From 90a45b8fc30a0b8b96c60926e638291fc0d0fa08 Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 25 Dec 2016 23:17:28 -0300 Subject: Fix some clang static analyzer warnings Nothing interesting. --- protocols/jabber/s5bytestream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'protocols/jabber') diff --git a/protocols/jabber/s5bytestream.c b/protocols/jabber/s5bytestream.c index 577840f1..9c79de8e 100644 --- a/protocols/jabber/s5bytestream.c +++ b/protocols/jabber/s5bytestream.c @@ -499,7 +499,7 @@ gboolean jabber_bs_recv_handshake(gpointer data, gint fd, b_input_condition cond } case BS_PHASE_REPLY: { - struct socks5_message socks5_reply; + struct socks5_message socks5_reply = {0}; int ret; if (!(ret = jabber_bs_peek(bt, &socks5_reply, sizeof(struct socks5_message)))) { @@ -1045,7 +1045,7 @@ gboolean jabber_bs_send_handshake(gpointer data, gint fd, b_input_condition cond unsigned char ver; unsigned char nmethods; unsigned char method; - } socks5_hello; + } socks5_hello = {0}; if (!(ret = jabber_bs_peek(bt, &socks5_hello, sizeof(socks5_hello)))) { return FALSE; @@ -1090,7 +1090,7 @@ gboolean jabber_bs_send_handshake(gpointer data, gint fd, b_input_condition cond } case BS_PHASE_REQUEST: { - struct socks5_message socks5_connect; + struct socks5_message socks5_connect = {0}; int msgsize = sizeof(struct socks5_message); int ret; -- cgit v1.2.3 From a04705bfde7c623605ee0e8449efd61ecc5c0b62 Mon Sep 17 00:00:00 2001 From: dequis Date: Mon, 26 Dec 2016 20:07:56 -0300 Subject: jabber: Workaround for servers (like slack) that send echoes without id Just comparing the body of the last sent message. This isn't foolproof and sending several messages quickly can make it fail, but it's less annoying than before. The correct solution is still to fix the server. In the case of slack I still recommend using the irc gateway instead. --- protocols/jabber/conference.c | 18 ++++++++++++++---- protocols/jabber/jabber.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'protocols/jabber') diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 593e4233..75f3100c 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -166,6 +166,7 @@ void jabber_chat_free(struct groupchat *c) jabber_buddy_remove_bare(c->ic, jc->name); + g_free(jc->last_sent_message); g_free(jc->my_full_jid); g_free(jc->name); g_free(jc->invite); @@ -187,6 +188,9 @@ int jabber_chat_msg(struct groupchat *c, char *message, int flags) jabber_cache_add(ic, node, jabber_chat_self_message); + g_free(jc->last_sent_message); + jc->last_sent_message = g_strdup(message); + return !jabber_write_packet(ic, node); } @@ -493,10 +497,16 @@ void jabber_chat_pkt_message(struct im_connection *ic, struct jabber_buddy *bud, } else if (chat != NULL && bud == NULL && nick == NULL) { imcb_chat_log(chat, "From conference server: %s", body->text); return; - } else if (jc && jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me && - (jabber_cache_handle_packet(ic, node) == XT_ABORT)) { - /* Self message marked by this bitlbee, don't show it */ - return; + } else if (jc && jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me) { + if (jabber_cache_handle_packet(ic, node) == XT_ABORT) { + /* Self message marked by this bitlbee, don't show it */ + return; + } else if (xt_find_attr(node, "id") == NULL && + g_strcmp0(body->text, jc->last_sent_message) == 0) { + /* Some misbehaving servers (like slack) eat the ids and echo anyway. + * Try to detect those cases by comparing against the last sent message. */ + return; + } } if (bud) { diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 7774c855..e1087315 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -160,6 +160,7 @@ struct jabber_chat { char *my_full_jid; /* Separate copy because of case sensitivity. */ struct jabber_buddy *me; char *invite; + char *last_sent_message; }; struct jabber_transfer { -- cgit v1.2.3