1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Don't override ProfMessage Id with origin-id

Profanity sends the same value for both. Other clients might not.
Safe both since we could need them later.

Once we implement Last Message Correction we will need the regular id.
If we override it with origin-id and another client chooses to not use
the same value for id and origin-id then we can't interpret the id sent
with the LMC request correctly.
This commit is contained in:
Michael Vetter 2019-10-31 13:45:44 +01:00
parent 4ecd4dea6a
commit f71de61b9d
5 changed files with 49 additions and 25 deletions

View File

@ -306,7 +306,7 @@ sv_ev_room_message(ProfMessage *message)
// only log message not coming from this client (but maybe same account, different client) // only log message not coming from this client (but maybe same account, different client)
// our messages are logged when outgoing // our messages are logged when outgoing
if (!(g_strcmp0(mynick, message->jid->resourcepart) == 0 && message_is_sent_by_us(message))) { if (!(g_strcmp0(mynick, message->jid->resourcepart) == 0 && message_is_sent_by_us(message, TRUE))) {
_log_muc(message); _log_muc(message);
} }

View File

@ -527,7 +527,7 @@ mucwin_incoming_msg(ProfMucWin *mucwin, ProfMessage *message, GSList *mentions,
assert(mucwin != NULL); assert(mucwin != NULL);
int flags = 0; int flags = 0;
if (message_is_sent_by_us(message)) { if (message_is_sent_by_us(message, TRUE)) {
/* Ignore reflection messages */ /* Ignore reflection messages */
return; return;
} }

View File

@ -186,6 +186,7 @@ message_init(void)
message->jid = NULL; message->jid = NULL;
message->id = NULL; message->id = NULL;
message->originid = NULL;
message->body = NULL; message->body = NULL;
message->encrypted = NULL; message->encrypted = NULL;
message->plain = NULL; message->plain = NULL;
@ -209,6 +210,10 @@ message_free(ProfMessage *message)
xmpp_free(ctx, message->id); xmpp_free(ctx, message->id);
} }
if (message->originid) {
xmpp_free(ctx, message->originid);
}
if (message->body) { if (message->body) {
xmpp_free(ctx, message->body); xmpp_free(ctx, message->body);
} }
@ -748,10 +753,11 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_ctx_t *ctx = connection_get_ctx();
const char *id = xmpp_stanza_get_id(stanza); const char *id = xmpp_stanza_get_id(stanza);
char *originid = NULL;
xmpp_stanza_t *origin = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_STABLE_ID); xmpp_stanza_t *origin = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_STABLE_ID);
if (origin && g_strcmp0(xmpp_stanza_get_name(origin), STANZA_NAME_ORIGIN_ID) == 0) { if (origin && g_strcmp0(xmpp_stanza_get_name(origin), STANZA_NAME_ORIGIN_ID) == 0) {
id = xmpp_stanza_get_attribute(origin, STANZA_ATTR_ID); originid = (char*)xmpp_stanza_get_attribute(origin, STANZA_ATTR_ID);
} }
const char *room_jid = xmpp_stanza_get_from(stanza); const char *room_jid = xmpp_stanza_get_from(stanza);
@ -803,6 +809,9 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
if (id) { if (id) {
message->id = strdup(id); message->id = strdup(id);
} }
if (originid) {
message->originid = strdup(originid);
}
message->body = xmpp_message_get_body(stanza); message->body = xmpp_message_get_body(stanza);
@ -1167,15 +1176,27 @@ _send_message_stanza(xmpp_stanza_t *const stanza)
xmpp_free(connection_get_ctx(), text); xmpp_free(connection_get_ctx(), text);
} }
/* ckeckOID = true: check origin-id
* checkOID = false: check regular id
*/
bool bool
message_is_sent_by_us(ProfMessage *message) { message_is_sent_by_us(ProfMessage *message, bool checkOID) {
bool ret = FALSE; bool ret = FALSE;
// we check the </origin-id> for this we calculate a hash into it so we can detect // 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() // whether this client sent it. See connection_create_stanza_id()
if (message && message->id != NULL) { if (message) {
char *tmp_id = NULL;
if (checkOID && message->originid != NULL) {
tmp_id = message->originid;
} else if (!checkOID && message->id != NULL) {
tmp_id = message->id;
}
if (tmp_id != NULL) {
gsize tmp_len; gsize tmp_len;
char *tmp = (char*)g_base64_decode(message->id, &tmp_len); char *tmp = (char*)g_base64_decode(tmp_id, &tmp_len);
// our client sents at least 36 (uuid) + identifier // our client sents at least 36 (uuid) + identifier
if (tmp_len > 36) { if (tmp_len > 36) {
@ -1195,6 +1216,7 @@ message_is_sent_by_us(ProfMessage *message) {
} }
free(tmp); free(tmp);
} }
}
return ret; return ret;
} }

View File

@ -126,6 +126,8 @@ typedef enum {
typedef struct prof_message_t { typedef struct prof_message_t {
Jid *jid; Jid *jid;
char *id; char *id;
/* </origin-id> XEP-0359 */
char *originid;
/* The raw body from xmpp message, either plaintext or OTR encrypted text */ /* The raw body from xmpp message, either plaintext or OTR encrypted text */
char *body; char *body;
/* The encrypted message as for PGP */ /* The encrypted message as for PGP */
@ -178,7 +180,7 @@ void message_send_paused(const char *const jid);
void message_send_gone(const char *const jid); void message_send_gone(const char *const jid);
void message_send_invite(const char *const room, const char *const contact, const char *const reason); void message_send_invite(const char *const room, const char *const contact, const char *const reason);
bool message_is_sent_by_us(ProfMessage *message); bool message_is_sent_by_us(ProfMessage *message, bool checkOID);
void presence_subscription(const char *const jid, const jabber_subscr_t action); void presence_subscription(const char *const jid, const jabber_subscr_t action);
GList* presence_get_subscription_requests(void); GList* presence_get_subscription_requests(void);

View File

@ -132,7 +132,7 @@ void message_send_gone(const char * const barejid) {}
void message_send_invite(const char * const room, const char * const contact, void message_send_invite(const char * const room, const char * const contact,
const char * const reason) {} const char * const reason) {}
bool message_is_sent_by_us(ProfMessage *message) { bool message_is_sent_by_us(ProfMessage *message, bool checkOID) {
return TRUE; return TRUE;
} }