1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-19 21:12:05 +01:00
Commit graph

76 commits

Author SHA1 Message Date
Florian Schmaus
4c218c96f6 Move Stream Management code into o.j.smack.sm
from o.jsmack.tcp.sm, as XEP-198 Stream Management is not an "XMPP over
TCP" exclusive feature. It could also be use together with the Websocket
binding of XMPP, so we may have a smack-streammangement in the
future. This change prepares for that by moving the SM code out of the
XMPP TCP package namespace.
2015-01-18 11:07:47 +01:00
Florian Schmaus
6d7f3904d9 Throw NotConnectedException on login()
if connect() was not previously called. Previously calling login() with
arguments would not check for the preconditions.

The check to throw needs to be performed in AbstractXMPPConnection
before every 'abstract login(Non)Anonymously()' call. That's the two
lines that check the preconditions are duplicated.

Also fix NPE in
XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate() when
packetWrite is null (i.e. if the connection was never connected before).
2015-01-17 17:53:36 +01:00
Florian Schmaus
75fd1683d1 Fix stanzaIdAcknowledgedListeners not being called
Replace isNotEmpty(id) with isNullOrEmpty(id)
2015-01-17 14:11:21 +01:00
Florian Schmaus
2ea469be10 Add javadoc to XMPPTCPConnectionConfiguration 2015-01-17 10:34:37 +01:00
Florian Schmaus
d099e7b16d Improve handling of InterruptedException
InterruptedExceptions should be treated as the users intention to
'cancel' the current thread's task. There is no such thing as a
spurious interrupt (not to be confused with "spurious wakeups").
2015-01-16 17:31:10 +01:00
Florian Schmaus
106512d8d4 Assure stanzaIdAcknowledgedListeners are removed
after at most 12 hours.

Also set a keep alive time for the removeCallbacksService to 30 seconds
and add AbstractXMPPConnection.schedule(Runnable, long, TimeUnit).
2015-01-15 21:36:23 +01:00
Florian Schmaus
6209d75536 Add XMPPTCPConnection.getMaxSmResumptionTime()
Note that the logic determining the max resumption time has changed,
Math.min() is now used instead of Math.max(). This should match the real
life situation, e.g. if the server announced a max resumption time of 10
minutes and the client one of 5, then it should be assumed that the
connection/stream state is dropped by the parties after 5 minutes.
2015-01-15 21:33:44 +01:00
Florian Schmaus
04d47b2dda Use Asyn.go() to create and start reader thread
in XMPPTCPConnection.
2015-01-15 18:36:35 +01:00
Florian Schmaus
ed84b4a8b3 Add javadoc to and fix typo in XMPPTCPConnection 2015-01-15 18:36:35 +01:00
Florian Schmaus
3582de0654 Fix initializing clientHandledStanzasCount
From XEP-198: Stream Management § 4. Acks:

"""
Note: There are two values of 'h' for any given stream: one maintained
by the client to keep track of stanzas it has handled from the server,
and one maintained by the server to keep track of stanzas it has handled
from the client. The client initializes its value to zero when it sends
<enable/> to the server, and the server initializes its value to zero
when it sends <enabled/> to the client (it is expected that the server
will respond immediately to <enable/> and set its counter to zero at
that time).
"""

Previously smack initialized both to 0 just before sending enabled. But
according to the note from XEP-198 the server's counter is initialized
by the server "when it sends <enabled/> to the client, so we need to set
clientHandledStanzasCount to 0 when we receive <enabled/>. Because the
server started counted right after he send <enabled/>.

Thanks to Kim "zash" Alvefur for pointing this out.
2015-01-15 18:36:08 +01:00
Florian Schmaus
3187436ba7 Throw exception if END_DOCUMENT is seen
instead of calling just instantShutdown(). Now we will catch this
exception, call notifyConnectionError which also calls
instantShutdown() but also notifies the connection listeners of the
event.

Smack should never all instantShutdown() without notifying the
connection listeners.
2015-01-14 17:07:35 +01:00
Florian Schmaus
2aaedcb2fd Improve stanza ack listener handling
- Don't abort if there is a NotConnectedExceptions, other listeners may
  want to be informed of the ack nevertheless.
- Simply return if the id is null or empty.
2015-01-13 13:31:45 +01:00
Florian Schmaus
24b940138f Improve XMPPTCPConnection.processHandledCount(long)
Add shortcut: If stanzaAcknowledgedListeners is not empty, then we don't
need to check the stanzaIdAcknowledgedListeners.

Also fixes a bug, instead of

if (id != null && stanzaAcknowledgedListeners.contains(id)) {

it must be

if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) {
2015-01-13 13:31:45 +01:00
Florian Schmaus
07539820c3 Make addStanzaAck…Listener() not throw
users may want to add listeners before the connection is connected. The
comment was also wrong, those listeners never got auto removed.
2015-01-13 13:31:45 +01:00
Florian Schmaus
b0cecee710 Rename IQ.ELEMENT to IQ.IQ_ELEMENT
to avoid confusion between the IQ element 'iq' and the IQs child
element. ELEMENT defined in an IQ sublcass should contain the *child*
element.

Add element to StreamInitation and fix FileTransferManager which still
used a packet listener instead of an IQ request handler to handle
incoming stream initiation requests.
2015-01-11 21:54:46 +01:00
Florian Schmaus
67c0a7089b Move notifyReconnection in AbstractXMPPConnection 2015-01-07 20:11:01 +01:00
Florian Schmaus
f6144c553c Try all Inet Addresses of the host when connecting
instead of the first resolved one.

Also some small refactorizations (e.g. getSocketFactory())
2015-01-07 14:35:23 +01:00
Florian Schmaus
717090d272 Rework incoming packet listeners and Roster
Differentiate between asynchronous and synchronous ones. Asynchronous
are the ones where the invocation order may not be the same as the order
in which the stanzas arrived.

Since it's no longer guaranteed that when a unit test calls

processPacket(stanza)

the stanza will be completely processed when the call returns, it was
necessary to extend the unit tests (mostly Roster and ChatManager) with
a packet listener that waits for his invocation. Since we now also use
LinkedHashMaps as Map for the packet listeners (SMACK-531, SMACK-424),
adding a packet listeners as last also means that it will be called as
last. We exploit this behavior change now in the unit tests.

Rename 'recvListeners' to 'syncRecvListeners' in AbstractXMPPConnection.

Rename 'rosterInitialized' to 'loaded' in Roster.

Add Roster.isLoaded().

Reset 'loaded' to false in
Roster.setOfflinePresencesAndResetLoaded() (was setOfflinePresences()).

Fixes SMACK-583, SMACK-532, SMACK-424
2015-01-07 14:35:23 +01:00
Florian Schmaus
c770b12348 Add log statements around socket.connect() of XMPPTCPConnection 2015-01-07 14:35:22 +01:00
Florian Schmaus
a24c813ed1 Add XMPPTCPConnectionConfiguration.getConnectTimeout() 2015-01-07 14:35:22 +01:00
Christoph Fiehe
665e7914f2 Enable OSGi compliance via 'DynamicImport-Package: *'
on package layer instead of Declarative Service (DS) approach.
Restructuring and cleanup of initialization process to ensure that all
internal config files are found by the corresponding bundle
classloaders.

SMACK-343
2015-01-03 13:14:02 +01:00
Florian Schmaus
08c1f2c850 Add AbstractXMPPConnection.parseAndProcessStanza()
and remove BOSHPacketReader.

Reduces the duplicate code in smack-tcp and smack-bosh. Also moves
ParsingExceptionCallback into AbstractXMPPConnection.
2014-12-28 17:43:39 +01:00
Florian Schmaus
54706e3918 Move lastStanzaReceived in processPacket
of AbstractXMPPConnection.

In worst case we loose a timestamp because handleUnparsablePacket threw
an Exception.
2014-12-28 00:47:31 +01:00
Florian Schmaus
4b77d00e91 Re-add the login(String, String, String) method 2014-12-18 14:07:54 +01:00
Florian Schmaus
d081055312 Use cached executor in AbstractXMPPConnection 2014-12-18 10:15:38 +01:00
Florian Schmaus
a87227c531 Rename ConnectionConfigurationBuilder to Builder 2014-12-18 10:15:35 +01:00
Florian Schmaus
d0341c1d94 Add XMPPTCPConnection.streamWasResumed() 2014-12-17 10:34:16 +01:00
Florian Schmaus
05870e6a22 s/Unkown/Unknown/g 2014-12-09 13:23:01 +01:00
Florian Schmaus
9286a1decb Rework XMPP Error class design
Introduce AbstractError, change 'Conditions' to enums. Because of
AbstractError, it was necessary that PlainStreamElement and
TopLevelStreamElement becomes an interface. Thus the implementation of
TopLevelStreamElement.toString() had to be removed.

This adds

- policy-violation
- unexpected-request

to XMPPError.Condition, and removes the

- payment-required
- remote-server-error
- unexpected-condition
- request-timeout

Conditions

The file transfer code does now no longer throw XMPPErrorExceptions, but
SmackExceptions.

Fixes SMACK-608. Makes it possible to resolves SMACK-386.
2014-11-25 13:19:32 +01:00
Florian Schmaus
59d3f55003 Set smWasEnableAtLeastOnce before sync point
to allow users to add stanza acknowledged listeners in
ConnectionListener.authenticated().
2014-11-17 23:59:00 +01:00
Florian Schmaus
504b550ef2 Report not connected/authenticated when resumeable
Since c81cd34561 we can report not
connected/authenticated when the client is disconnected but the stream
could be resumed. The previous behavior caused some confusion among
the users.
2014-11-16 18:53:31 +01:00
Florian Schmaus
301519a264 Fix END_DOCUMENT handling in XMPPTCPConnection
The 'break' statement in the END_DOCUMENT case should break the parsing
loop and not the switch/case within. Therefore we need to add a loop
label on break on that label.
2014-11-15 09:46:39 +01:00
Florian Schmaus
c81cd34561 Apply builder pattern to ConnectionConfiguration
Introducing a clean split between the constant connection configuration
parameters, which are now all in ConnectionConfiguration and the dynamic
connection state (e.g. hostAddresses) which are now in
AbstractXMPPConnection.

Also removed all arguments of login() since the username, password,
resource and callback handler need now to be configured via
ConnectionConfiguration.

Also remove documentation/extensions/messageevents.md, as it's already
in documentation/legacy
2014-11-15 09:46:31 +01:00
Florian Schmaus
5647cac39c Move is(Connected|Authenticated) and getUser()
into AbstractXMPPConnection.

Also remove wasAuthenticated field from XMPPBOSHConnection, it is
already in AbstractXMPPConnection.
2014-11-01 12:42:53 +01:00
Florian Schmaus
6b21455b32 Asynchronous invoke Stanza Acknowledged Listeners 2014-10-29 10:18:08 +01:00
Florian Schmaus
ac41fda1e5 Add Stream Management javadoc
- rename idStanzaAcknowledged to stanzaIdAcknowledged
- introduce smWasEnabledAtLeastOnce and throw
  StreamManagementNotEnabledExceptions
- enable SM is SM resumption is enabled
2014-10-29 10:06:33 +01:00
Florian Schmaus
92bc3452da Handle spurious interrupts in XMPPTCPConnection
Also remove unnecessary done() check in nextStreamElement() and remove
wrong comment in !instantShutdown branch. There is no mechanism to
forcible close the socket.
2014-10-28 15:11:48 +01:00
Florian Schmaus
765e83ca81 Send a final SM Ack on shutdown() 2014-10-28 15:11:48 +01:00
Florian Schmaus
65ccec995e Add XMPPTCPConnection.sendSMAcknowledgement 2014-10-28 15:11:48 +01:00
Florian Schmaus
9f56842ee4 Notify packet sending listeners in new thread
sendListeners are now invoked *after* the packet has been put on the
wire.

Also sending listener exceptions are not catched and not only
NotConnectedExceptions. And a exception does not cause a 'break' but a
'continue' now. Log level is WARNING now.
2014-10-25 16:35:58 +02:00
Florian Schmaus
25887e3427 s/SmackTcpSmackInitalizer/SmackTcpSmackInitializer/
This prevented Stream Management from working as the
StreamFeatureProvider was not loaded.

The typo existed from 46a4402a69 up to this
commit.
2014-10-23 17:42:54 +02:00
Florian Schmaus
177ab983d4 Merge branch '4.0'
Conflicts:
	build.gradle
	smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketReader.java
2014-10-22 22:25:20 +02:00
Florian Schmaus
674df78741 Fix parsing exception causing infinite loop
Fixes SMACK-613
2014-10-22 20:00:05 +02:00
Florian Schmaus
5f9c342f7e Don't check for END_DOCUMENT parsePackets()
instead use the event switch/case and log a warning if this ever
happens, as it's likely a programming error.
2014-10-21 23:44:39 +02:00
Florian Schmaus
e090067358 Use switch/case instead if/else-if in parsePackets() 2014-10-21 23:37:37 +02:00
Florian Schmaus
6980c8e63d Rework Smack Provider design
this is the first stop towards fixing "SMACK-65: parsing should look for
depth", by providing the initial parsing depth to the provider. Some
methods (.e.g parseMessage) now use the depth as abort condition,
instead of a unclean String equals check.

parseIQ() and parseExtension() where both renamed to parse.

This also restricts the Exceptions thrown by the parse method, to just
XmlPullParserException, IOException and SmackException (not really a big
victory, but nevertheless a slight improvement).

StreamFeatureProvider is now gone, we simply use PacketExtensionProvider
for stream features.
2014-10-08 16:01:14 +02:00
Florian Schmaus
d04517cd08 Add message String to all SmackExceptions
SMACK-599
2014-10-07 21:50:39 +02:00
Florian Schmaus
a942863ffe Move saslFeatureReceived check in connect()
so that APIs that need a fully connected but not yet authenticated
connection (e.g. AccountManager) can use the connection after connect()
returns.

Also move "connected = true" after saslFeatureReceived check, as if the
check would throw, the boolean would still be 'true' resulting in an
inconsistent state.

Otherwise this could result in

D/SMACK﹕ SENT (12): <stream:stream xmlns='jabber:client' to='*server*' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>
D/SMACK﹕ SENT (12): <iq id='miS03-37' to='*server*' type='get'><query xmlns='jabber:iq:register'></query></iq>
D/SMACK﹕ RCV (12): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='4280133582' from='*server*' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism >DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='a4WL1hRFRX38OouQz3okC+ayK2o='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
D/SMACK﹕ SENT (12): <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
D/SMACK﹕ RCV (12): <iq from='*server*' id='miS03-37' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username></username><password/></query></iq>
D/SMACK﹕ SENT (12): <iq id='miS03-39' to='*server*' type='set'><query xmlns='jabber:iq:register'><password>s0r73pgojeopmssjaairu6kcmk3v4l</password>< username>nqcjloj4v6uk52bug16hrrhspfanlr</username></query></iq>
D/SMACK﹕ RCV (12): <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
W/AbstractXMPPConnection﹕ Connection closed with error
    javax.net.ssl.SSLException: Connection closed by peer
            at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
            at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.ja va:405)
            at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocket Impl.java:661)
            at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.ja va:632)
            at org.jivesoftware.smack.tcp.XMPPTCPConnection.initReaderAndWriter(XMPPTCPConnect ion.java:661)
            at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnecti on.java:768)
2014-09-29 20:06:48 +02:00
Florian Schmaus
b81c00d340 Add message String to ConnectionException 2014-09-24 13:34:25 +02:00
Florian Schmaus
46a4402a69 Add StreamFeatureProvider
so that AccountManager and the CapsExtension can be moved to
smack-extensions, where they belong.
2014-09-11 23:58:07 +02:00