Skip to content

Commit

Permalink
[websocket] Do not swallow exceptions and use QName
Browse files Browse the repository at this point in the history
Follow up on c4d11ea ("[websocket] Reduce fragility")
  • Loading branch information
Flowdalic committed Nov 25, 2023
1 parent 2ebffa7 commit 097ab20
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package org.jivesoftware.smack.websocket.impl;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.SSLSession;
import javax.xml.namespace.QName;

import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
Expand All @@ -28,6 +30,8 @@
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.websocket.WebSocketException;
import org.jivesoftware.smack.websocket.elements.WebSocketCloseElement;
import org.jivesoftware.smack.websocket.elements.WebSocketOpenElement;
import org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
Expand Down Expand Up @@ -107,9 +111,10 @@ static boolean isOpenElement(String text) {
XmlPullParser parser;
try {
parser = PacketParserUtils.getParserFor(text);
parser.nextTag();
return "open".equals(parser.getName()) && "urn:ietf:params:xml:ns:xmpp-framing".equals(parser.getNamespace());
QName qname = parser.getQName();
return qname.equals(WebSocketOpenElement.QNAME);
} catch (XmlPullParserException | IOException e) {
LOGGER.log(Level.WARNING, "Could not inspect \"" + text + "\" for open element", e);
return false;
}
}
Expand All @@ -118,9 +123,10 @@ static boolean isCloseElement(String text) {
XmlPullParser parser;
try {
parser = PacketParserUtils.getParserFor(text);
parser.nextTag();
return "close".equals(parser.getName()) && "urn:ietf:params:xml:ns:xmpp-framing".equals(parser.getNamespace());
QName qname = parser.getQName();
return qname.equals(WebSocketCloseElement.QNAME);
} catch (XmlPullParserException | IOException e) {
LOGGER.log(Level.WARNING, "Could not inspect \"" + text + "\" for close element", e);
return false;
}
}
Expand Down

0 comments on commit 097ab20

Please sign in to comment.