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 Connection
static final SystemProperty<Boolean>
protected PacketRouter
Router used to route incoming packets to the correct channels.protected SASLAuthentication.Status
SASL status based on the last SASL interactionprotected LocalSession
Session associated with the socket reader.protected boolean
protected boolean
protected boolean
protected boolean
-
Constructor Summary
ConstructorsConstructorDescriptionStanzaHandler
(PacketRouter router, Connection connection) Creates a dedicated reader for a socket. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Close the connection since TLS was mandatory and the entity never negotiated TLS.protected boolean
compressClient
(org.dom4j.Element doc) Start using compression but first check if the connection can and should use compression.protected void
After compression was successful we should open a new stream and offer new stream features such as resource binding and session establishment.protected void
createSession
(org.xmlpull.v1.XmlPullParser xpp) Uses the XPP to grab the opening stream tag and create an active session object.org.xmpp.packet.JID
Obtain the address of the XMPP entity for which this StanzaHandler handles stanzas.protected org.dom4j.Document
protected void
initiateSession
(String stanza, XMPPPacketReader reader) protected boolean
isEndOfStream
(String xml) Checks if the provided XML data represents the end / closing of an XMPP stream.protected boolean
isHostUnknown
(String host) protected boolean
isStartOfStream
(String xml) Checks if the provided XML data represents the beginning of a new XMPP stream.protected boolean
isStreamManagementStanza
(org.dom4j.Element stanza) Determines whether stanza's namespace matches XEP-0198 namespaceprotected boolean
Tries to encrypt the connection using TLS.void
process
(String stanza, XMPPPacketReader reader) protected void
processIQ
(org.xmpp.packet.IQ packet) Process the received IQ packet.protected void
processMessage
(org.xmpp.packet.Message packet) Process the received Message packet.protected void
processPresence
(org.xmpp.packet.Presence packet) Process the received Presence packet.protected void
processStanza
(String stanza, XMPPPacketReader reader) protected void
After SASL authentication was successful we should open a new stream and offer new stream features such as resource binding and session establishment.void
setSession
(LocalSession session) protected void
tlsNegotiated
(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. RegisteredPacketInterceptor
will 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. RegisteredPacketInterceptor
will 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. RegisteredPacketInterceptor
will 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.XmlPullParserException
IOException
-
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.
-