From 65ccec995e8acb7a650280c236f8757442dd463a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 28 Oct 2014 12:22:05 +0100 Subject: [PATCH] Add XMPPTCPConnection.sendSMAcknowledgement --- .../jivesoftware/smack/tcp/XMPPTCPConnection.java | 15 +++++++++++++-- .../tcp/sm/provider/ParseStreamManagement.java | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 07c31b170..8e438070d 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -1193,9 +1193,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { processHandledCount(ackAnswer.getHandledCount()); break; case AckRequest.ELEMENT: - // AckRequest stanzas are trival, no need to parse them + ParseStreamManagement.ackRequest(parser); if (smEnabledSyncPoint.wasSuccessful()) { - packetWriter.sendStreamElement(new AckAnswer(clientHandledStanzasCount)); + sendSmAcknowledgementInternal(); } else { LOGGER.warning("SM Ack Request received while SM is not enabled"); } @@ -1499,6 +1499,17 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { packetWriter.sendStreamElement(AckRequest.INSTANCE); } + public void sendSmAcknowledgement() throws StreamManagementNotEnabledException, NotConnectedException { + if (!isSmEnabled()) { + throw new StreamManagementException.StreamManagementNotEnabledException(); + } + sendSmAcknowledgementInternal(); + } + + private void sendSmAcknowledgementInternal() throws NotConnectedException { + packetWriter.sendStreamElement(new AckAnswer(clientHandledStanzasCount)); + } + public void addStanzaAcknowledgedListener(PacketListener listener) { stanzaAcknowledgedListeners.add(listener); } diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/sm/provider/ParseStreamManagement.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/sm/provider/ParseStreamManagement.java index 6d3168885..e6290079c 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/sm/provider/ParseStreamManagement.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/sm/provider/ParseStreamManagement.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.tcp.sm.packet.StreamManagement.AckAnswer; +import org.jivesoftware.smack.tcp.sm.packet.StreamManagement.AckRequest; import org.jivesoftware.smack.tcp.sm.packet.StreamManagement.Enabled; import org.jivesoftware.smack.tcp.sm.packet.StreamManagement.Failed; import org.jivesoftware.smack.tcp.sm.packet.StreamManagement.Resumed; @@ -85,4 +86,10 @@ public class ParseStreamManagement { return new AckAnswer(h); } + public static AckRequest ackRequest(XmlPullParser parser) throws XmlPullParserException, IOException { + ParserUtils.assertAtStartTag(parser); + parser.next(); + ParserUtils.assertAtEndTag(parser); + return AckRequest.INSTANCE; + } }