diff options
author | James Booth <boothj5@gmail.com> | 2016-08-20 21:37:20 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-08-20 21:37:20 +0100 |
commit | 948d63d855654a914d703f9e353f493b230dd56c (patch) | |
tree | 6f783ff4e73c15577497ed50a5951ec295605941 /src/xmpp | |
parent | 583fb2b8c66d1af9059763b2f8f56b7f78da246a (diff) | |
download | profani-tty-948d63d855654a914d703f9e353f493b230dd56c.tar.gz |
Tidy _handle_carbons
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/message.c | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c index bb7b6d18..5ccabdf4 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -681,52 +681,69 @@ _handle_carbons(xmpp_stanza_t *const stanza) } const char *name = xmpp_stanza_get_name(carbons); - if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) { - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); - xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + if (!name) { + log_error("Unable to retrieve stanza name for Carbon"); + return TRUE; + } - xmpp_ctx_t *ctx = connection_get_ctx(); + if ((g_strcmp0(name, "received") != 0) && (g_strcmp0(name, "sent") != 0)) { + log_warning("Carbon received with unrecognised stanza name: %s", name); + return TRUE; + } - const gchar *to = xmpp_stanza_get_to(message); - const gchar *from = xmpp_stanza_get_from(message); + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); + if (!forwarded) { + log_warning("Carbon received with no forwarded element"); + return TRUE; + } - // happens when receive a carbon of a self sent message - if (!to) to = from; + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + if (!message) { + log_warning("Carbon received with no message element"); + return TRUE; + } - Jid *jid_from = jid_create(from); - Jid *jid_to = jid_create(to); - Jid *my_jid = jid_create(connection_get_fulljid()); + char *message_txt = xmpp_message_get_body(message); + if (!message_txt) { + log_warning("Carbon received with no message."); + return TRUE; + } - // check for and deal with message - char *message_txt = xmpp_message_get_body(message); - if (message_txt) { - // check for pgp encrypted message - char *enc_message = NULL; - xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED); - if (x) { - enc_message = xmpp_stanza_get_text(x); - } + const gchar *to = xmpp_stanza_get_to(message); + const gchar *from = xmpp_stanza_get_from(message); - // if we are the recipient, treat as standard incoming message - if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message); + // happens when receive a carbon of a self sent message + if (!to) to = from; - // else treat as a sent message - } else { - sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message); - } - xmpp_free(ctx, message_txt); - xmpp_free(ctx, enc_message); - } + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(connection_get_fulljid()); + + // check for pgp encrypted message + char *enc_message = NULL; + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED); + if (x) { + enc_message = xmpp_stanza_get_text(x); + } - jid_destroy(jid_from); - jid_destroy(jid_to); - jid_destroy(my_jid); + // if we are the recipient, treat as standard incoming message + if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) { + sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message); - return TRUE; + // else treat as a sent message + } else { + sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message); } - return FALSE; + xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_free(ctx, message_txt); + xmpp_free(ctx, enc_message); + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + + return TRUE; } static void |