diff options
author | Michael Vetter <jubalh@iodoru.org> | 2022-05-04 16:01:03 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2022-05-04 16:11:00 +0200 |
commit | 66eeccf4089de61d2cb029f057d1d58bdbb6ab73 (patch) | |
tree | 27ba46882974084237fdae5c39a3b37f04c6666f /src/xmpp | |
parent | 1eaa2c15291cde4eb8b7656db46aa096b50d9af9 (diff) | |
download | profani-tty-66eeccf4089de61d2cb029f057d1d58bdbb6ab73.tar.gz |
ox: only process proper messages
We only want to have the decrypted message or the alternative body in message->plain. Also let's print error messages if it makes sense and log other issues. Partly addresses the commit in the comit mesage of: 2dc0cc489c872941e18a622c091f74bf5b0b043f
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/message.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 70b40e25..115bf3da 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -1467,14 +1467,13 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m #ifdef HAVE_LIBGPGME xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0); if (ox) { - message->plain = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox)); - if (message->plain) { - xmpp_stanza_t* x = xmpp_stanza_new_from_string(connection_get_ctx(), message->plain); - if (x) { - xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(x, "payload"); + gchar* decrypted = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox)); + if (decrypted) { + xmpp_stanza_t* decrypted_stanza = xmpp_stanza_new_from_string(connection_get_ctx(), decrypted); + if (decrypted_stanza) { + xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(decrypted_stanza, "payload"); if (!p) { log_warning("OX Stanza - no Payload"); - message->plain = "OX error: No payload found"; return; } xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(p, "body"); @@ -1484,18 +1483,18 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m } message->plain = xmpp_stanza_get_text(b); message->encrypted = xmpp_stanza_get_text(ox); - if (message->plain == NULL) { - message->plain = xmpp_stanza_get_text(stanza); - } } else { - message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)"; + cons_show("Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)"); log_warning("OX Stanza text to stanza failed"); } } else { - message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)"; + // get alternative text from message body + xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(stanza, "body"); + if (b) { + message->plain = xmpp_stanza_get_text(b); + } } } else { - message->plain = "OX stanza without openpgp name"; log_warning("OX Stanza without openpgp stanza"); } #endif // HAVE_LIBGPGME |