From 3a57f6df897202010e1de242445b0f65763946d2 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 26 Jun 2014 16:42:24 +0200 Subject: faulty otr messages now generate an error --- .../conversations/generator/MessageGenerator.java | 18 ++++++++++++++++++ src/eu/siacs/conversations/parser/MessageParser.java | 4 ++-- .../conversations/services/XmppConnectionService.java | 8 +++++--- 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/eu/siacs') diff --git a/src/eu/siacs/conversations/generator/MessageGenerator.java b/src/eu/siacs/conversations/generator/MessageGenerator.java index b97289522..28504b211 100644 --- a/src/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/eu/siacs/conversations/generator/MessageGenerator.java @@ -88,4 +88,22 @@ public class MessageGenerator { } return packet; } + + public MessagePacket generateNotAcceptable(MessagePacket origin) { + MessagePacket packet = generateError(origin); + Element error = packet.addChild("error"); + error.setAttribute("type", "modify"); + error.setAttribute("code", "406"); + error.addChild("not-acceptable"); + return packet; + } + + private MessagePacket generateError(MessagePacket origin) { + MessagePacket packet = new MessagePacket(); + packet.setId(origin.getId()); + packet.setTo(origin.getFrom()); + packet.setBody(origin.getBody()); + packet.setType(MessagePacket.TYPE_ERROR); + return packet; + } } diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index cd10d6c8a..598cf8307 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -92,9 +92,9 @@ public class MessageParser extends AbstractParser { } catch (Exception e) { String receivedId = packet.getId(); if (receivedId!=null) { - mXmppConnectionService.replyWithError(account,packet); + mXmppConnectionService.replyWithNotAcceptable(account,packet); } - conversation.resetOtrSession(); + conversation.endOtrIfNeeded(); return null; } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index f4691fab9..b7c32db24 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1475,8 +1475,10 @@ public class XmppConnectionService extends Service { return this.pm; } - public void replyWithError(Account account, MessagePacket packet) { - // TODO Auto-generated method stub - + public void replyWithNotAcceptable(Account account, MessagePacket packet) { + if (account.getStatus() == Account.STATUS_ONLINE) { + MessagePacket error = this.mMessageGenerator.generateNotAcceptable(packet); + account.getXmppConnection().sendMessagePacket(error); + } } } -- cgit v1.2.3