1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Add AbstractXMPPConnection.parseAndProcessStanza()

and remove BOSHPacketReader.

Reduces the duplicate code in smack-tcp and smack-bosh. Also moves
ParsingExceptionCallback into AbstractXMPPConnection.
This commit is contained in:
Florian Schmaus 2014-12-28 17:43:39 +01:00
parent 54706e3918
commit 08c1f2c850
4 changed files with 136 additions and 182 deletions

View file

@ -48,8 +48,6 @@ import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.UnparsablePacket;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
@ -152,8 +150,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
private boolean usingTLS = false;
private ParsingExceptionCallback parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
/**
* Protected access level because of unit test purposes
*/
@ -293,25 +289,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
return connectionID;
}
/**
* Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a
* stanza
*
* @param callback the callback to install
*/
public void setParsingExceptionCallback(ParsingExceptionCallback callback) {
parsingExceptionCallback = callback;
}
/**
* Get the current active parsing exception callback.
*
* @return the active exception callback or null if there is none
*/
public ParsingExceptionCallback getParsingExceptionCallback() {
return parsingExceptionCallback;
}
@Override
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
packetWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
@ -975,29 +952,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
case Message.ELEMENT:
case IQ.ELEMENT:
case Presence.ELEMENT:
int parserDepth = parser.getDepth();
Packet packet;
try {
packet = PacketParserUtils.parseStanza(parser,
XMPPTCPConnection.this);
}
catch (Exception e) {
ParsingExceptionCallback callback = getParsingExceptionCallback();
CharSequence content = PacketParserUtils.parseContentDepth(parser,
parserDepth);
UnparsablePacket message = new UnparsablePacket(content, e);
if (callback != null) {
callback.handleUnparsablePacket(message);
}
// The parser is now at the end tag of the unparsable stanza. We need to advance to the next
// start tag in order to avoid an exception which would again lead to the execution of the
// catch block becoming effectively an endless loop.
eventType = parser.next();
continue;
parseAndProcessStanza(parser);
} finally {
clientHandledStanzasCount = SMUtils.incrementHeight(clientHandledStanzasCount);
}
processPacket(packet);
break;
case "stream":
// We found an opening stream.