Package org.jivesoftware.openfire.net
Class StanzaHandler
java.lang.Object
org.jivesoftware.openfire.net.StanzaHandler
- Direct Known Subclasses:
ClientStanzaHandler,ComponentStanzaHandler,MultiplexerStanzaHandler,RespondingServerStanzaHandler,ServerStanzaHandler
A StanzaHandler is the main responsible for handling incoming stanzas. Some stanzas like startTLS
are totally managed by this class. The rest of the stanzas are just forwarded to the router.
- Author:
- Gaston Dombiak
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Connectionstatic final SystemProperty<Boolean>protected PacketRouterRouter used to route incoming packets to the correct channels.protected SASLAuthentication.StatusSASL status based on the last SASL interactionprotected LocalSessionSession associated with the socket reader.protected booleanprotected booleanprotected booleanprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionStanzaHandler(PacketRouter router, Connection connection) Creates a dedicated reader for a socket. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClose the connection since TLS was mandatory and the entity never negotiated TLS.protected booleancompressClient(org.dom4j.Element doc) Start using compression but first check if the connection can and should use compression.protected voidAfter compression was successful we should open a new stream and offer new stream features such as resource binding and session establishment.protected voidcreateSession(org.xmlpull.v1.XmlPullParser xpp) Uses the XPP to grab the opening stream tag and create an active session object.org.xmpp.packet.JIDObtain the address of the XMPP entity for which this StanzaHandler handles stanzas.protected org.dom4j.Documentprotected voidinitiateSession(String stanza, XMPPPacketReader reader) protected booleanisEndOfStream(String xml) Checks if the provided XML data represents the end / closing of an XMPP stream.protected booleanisHostUnknown(String host) protected booleanisStartOfStream(String xml) Checks if the provided XML data represents the beginning of a new XMPP stream.protected booleanisStreamManagementStanza(org.dom4j.Element stanza) Determines whether stanza's namespace matches XEP-0198 namespaceprotected booleanTries to encrypt the connection using TLS.voidprocess(String stanza, XMPPPacketReader reader) protected voidprocessIQ(org.xmpp.packet.IQ packet) Process the received IQ packet.protected voidprocessMessage(org.xmpp.packet.Message packet) Process the received Message packet.protected voidprocessPresence(org.xmpp.packet.Presence packet) Process the received Presence packet.protected voidprocessStanza(String stanza, XMPPPacketReader reader) protected voidAfter SASL authentication was successful we should open a new stream and offer new stream features such as resource binding and session establishment.voidsetSession(LocalSession session) protected voidtlsNegotiated(org.xmlpull.v1.XmlPullParser xpp) TLS negotiation was successful so open a new stream and offer the new stream features.
-
Field Details
-
PROPERTY_OVERWRITE_EMPTY_TO
-
connection
-
sessionCreated
protected boolean sessionCreated -
startedTLS
protected boolean startedTLS -
startedSASL
protected boolean startedSASL -
saslStatus
SASL status based on the last SASL interaction -
waitingCompressionACK
protected boolean waitingCompressionACK -
session
Session associated with the socket reader. -
router
Router used to route incoming packets to the correct channels.
-
-
Constructor Details
-
StanzaHandler
Creates a dedicated reader for a socket.- Parameters:
router- the router for sending packets that were read.connection- the connection being read.
-
-
Method Details
-
setSession
-
process
- Throws:
Exception
-
initiateSession
- Throws:
Exception
-
processStanza
- Throws:
Exception
-
processIQ
Process the received IQ packet. RegisteredPacketInterceptorwill be invoked before and after the packet was routed.Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.
- Parameters:
packet- the received packet.- Throws:
UnauthorizedException- if service is not available to sender.
-
processPresence
Process the received Presence packet. RegisteredPacketInterceptorwill be invoked before and after the packet was routed.Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.
- Parameters:
packet- the received packet.- Throws:
UnauthorizedException- if service is not available to sender.
-
processMessage
Process the received Message packet. RegisteredPacketInterceptorwill be invoked before and after the packet was routed.Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.
- Parameters:
packet- the received packet.- Throws:
UnauthorizedException- if service is not available to sender.
-
negotiateTLS
protected boolean negotiateTLS()Tries to encrypt the connection using TLS. If the connection is encrypted then reset the parser to use the new encrypted reader. But if the connection failed to be encrypted then send astanza and close the connection. - Returns:
- true if the connection was encrypted.
-
tlsNegotiated
protected void tlsNegotiated(org.xmlpull.v1.XmlPullParser xpp) throws org.xmlpull.v1.XmlPullParserException, IOException TLS negotiation was successful so open a new stream and offer the new stream features. The new stream features will include available SASL mechanisms and specific features depending on the session type such as auth for Non-SASL authentication and register for in-band registration.- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
saslSuccessful
protected void saslSuccessful()After SASL authentication was successful we should open a new stream and offer new stream features such as resource binding and session establishment. Notice that resource binding and session establishment should only be offered to clients (i.e. not to servers or external components) -
compressClient
protected boolean compressClient(org.dom4j.Element doc) Start using compression but first check if the connection can and should use compression. The connection will be closed if the requested method is not supported, if the connection is already using compression or if client requested to use compression but this feature is disabled.- Parameters:
doc- the element sent by the client requesting compression. Compression method is included.- Returns:
- true if it was possible to use compression.
-
compressionSuccessful
protected void compressionSuccessful()After compression was successful we should open a new stream and offer new stream features such as resource binding and session establishment. Notice that resource binding and session establishment should only be offered to clients (i.e. not to servers or external components) -
isStreamManagementStanza
protected boolean isStreamManagementStanza(org.dom4j.Element stanza) Determines whether stanza's namespace matches XEP-0198 namespace- Parameters:
stanza- Stanza to be checked- Returns:
- whether stanza's namespace matches XEP-0198 namespace
-
getStreamHeader
protected org.dom4j.Document getStreamHeader() -
closeNeverEncryptedConnection
protected void closeNeverEncryptedConnection()Close the connection since TLS was mandatory and the entity never negotiated TLS. Before closing the connection a stream error will be sent to the entity. -
createSession
protected void createSession(org.xmlpull.v1.XmlPullParser xpp) throws org.xmlpull.v1.XmlPullParserException, IOException Uses the XPP to grab the opening stream tag and create an active session object. The session to create will depend on the sent namespace. In all cases, the method obtains the opening stream tag, checks for errors, and either creates a session or returns an error and kills the connection. If the connection remains open, the XPP will be set to be ready for the first packet. A call to next() should result in an START_TAG state with the first packet in the stream.- Parameters:
xpp- the pull parser- Throws:
org.xmlpull.v1.XmlPullParserException- if an exception occurs reading from the pull parserIOException- if an IO exception occurs reading from the pull parser
-
isHostUnknown
-
getAddress
public org.xmpp.packet.JID getAddress()Obtain the address of the XMPP entity for which this StanzaHandler handles stanzas. Note that the value that is returned for this method can change over time. For example, if no session has been established yet, this method will returnnull, or, if resource binding occurs, the returned value might change. Values obtained from this method are therefore best not cached.- Returns:
- The address of the XMPP entity for.
-
isStartOfStream
Checks if the provided XML data represents the beginning of a new XMPP stream.- Parameters:
xml- The XML to verify- Returns:
- 'true' if the provided data represents the beginning of an XMPP stream.
-
isEndOfStream
Checks if the provided XML data represents the end / closing of an XMPP stream.- Parameters:
xml- The XML to verify- Returns:
- 'true' if the provided data represents the end of an XMPP stream.
-