1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-14 16:22:07 +01:00
Commit graph

1057 commits

Author SHA1 Message Date
Florian Schmaus
d06e9499e8 [core] Add XmppElementUtil.castOrThrow(ExtensionElement, Class)
This method throws an IllegalStateException if the provided extension
element is not of the expected type and hints users towards potential
causes.
2020-08-29 16:29:22 +02:00
adiaholic
7ed29b9d5f Introduce websocket module into smack 2020-08-28 23:40:40 +05:30
Florian Schmaus
1aab0b8aac [core] Add cache to XmppElementUtil.getQNameFor(Class) 2020-08-28 09:47:09 +02:00
Florian Schmaus
cf4c9725b7 [core] Add ProviderManager.getExtensionProvider(QName) 2020-08-28 09:37:29 +02:00
Florian Schmaus
f892ba1369 [core] Get stream-open-like element from transport
When sending a stream-open-like element, it depends on the actual used
transport which element is send. For example, RFC6120-style TCP uses
<stream>, whereas the Websocket binding for XMPP uses <open/>.
2020-08-26 11:38:24 +02:00
Florian Schmaus
e6a60213b6 [core] Add convenience constructor to AbstractStreamOpen
Most of the times when we construct a stream-open-like element, we
want the jabber:client namespace. Hence add a constructor that does
select the namespace implicitly.
2020-08-26 11:36:55 +02:00
Florian Schmaus
2a9671ca93 [core] Change type of XmlStringBuilder cosntructor to FullyQualifiedElement
There is no reason we should do this only for ExtensionElements, this
behavior is sane for every FulllyQualifiedElement.
2020-08-26 11:35:22 +02:00
Florian Schmaus
53d66261af
Merge pull request #423 from adiaholic/streamFactory
Use AbstractStreamOpen instead of StreamOpen to open stream
2020-08-19 13:40:21 +02:00
Aditya Borikar
648a1cfab1 Use AbstractStreamOpen instead of StreamOpen to open stream
Before the existence of AbstractStreamOpen, StreamOpen sufficed our need
during sending an open stream element. Since the intention behind
introducing AbstractStreamOpen is to allow underlying transports provide
transport specific opening streams, these changes will further support
the cause.

This commit will allow us to send transport specific open element
which should be inherited from AbstractStreamOpen.
2020-08-19 11:48:00 +05:30
Aditya Borikar
db385e6595 Make ModularXmppClientToServerConnectionConfiguration.addModule() public
This commit will allow users to plug their module descriptors inside
modular architecture.
2020-08-19 11:32:50 +05:30
Florian Schmaus
9cec02b5e3
Merge pull request #420 from adiaholic/streamFactory
Introduce StreamOpenFactory for modular architecture
2020-08-18 16:22:27 +02:00
Aditya Borikar
0e49adff1d Introduce StreamOpenAndCloseFactory for modular architecture 2020-08-18 19:04:34 +05:30
Aditya Borikar
9fcc97836b Introduce AbstractStreamOpen and AbstractStreamClose
- Inherit StreamOpen and StreamClose from AbstractStream classes
2020-08-18 10:35:22 +05:30
Aditya Borikar
c9cf4f1541 XmlEnvironment: Use correct method to obatain effective namespace. 2020-08-08 20:14:39 +05:30
Florian Schmaus
cf92566e26
Merge pull request #416 from Flowdalic/connected-boolean
Set 'connected' to 'true' as early as possible
2020-08-07 12:43:53 +02:00
Aditya Borikar
7796b367cc Position parser at START_ELEMENT before parsing
This PR aims to provide parseXrdLinkReferencesFor() method the ability
to parse forward to the first START_ELEMENT tag.The HttpLookupMethodTest
tests the HttpLookupMethod class by parsing String. This makes use of
PacketParserUtils.getParserFor(String), which already does forward
winding to reach START_ELEMENT. However when fetching endpoints from a
remote host meta data, PacketParserUtils.getParserFor(InputStream) is
used which doesn't do winding in any form. And thus, even though
HttpLookupMethodTest tests pass, this implementation would crash while
parsing remote host-meta.
2020-08-07 15:01:53 +05:30
Florian Schmaus
ac788592a6 waitForCondition() → waitForConditionOrThrowConnectionException()
The method was already renamed, but not in
ModularXmppClientToServerConnectionInternal.
2020-08-06 18:17:04 +02:00
Florian Schmaus
1a2a613112 Set 'connected' to 'true' as early as possible
We previously only set 'connected' after connectInternal()
returned. This could lead to notifyConnectionError() ignoring stream
error exceptions, e.g. when establishing TLS which happens also in
connectInternal(), because 'connected' was still 'false'.

2020-08-06 13:08:06.265 19830-20423/org.atalk.android D/SMACK: SENT (0):
    <stream:stream xmlns='jabber:client' to='atalk.sytes.net' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
2020-08-06 13:08:06.333 19830-20424/org.atalk.android D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='16420577292739412012' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' from='atalk.sytes.net' xmlns='jabber:client'>
    <stream:error>
      <policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
      <text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
        Too many (20) failed authentications from this IP address (::ffff:42.60.7.13). The address will be unblocked at 05:15:34 06.08.2020 UTC
      </text>
    </stream:error>
    </stream:stream>
2020-08-06 13:08:06.346 19830-20424/org.atalk.android I/aTalk: [241896] org.jivesoftware.smack.AbstractXMPPConnection.notifyConnectionError() Connection was already disconnected when attempting to handle org.jivesoftware.smack.XMPPException$StreamErrorException: policy-violation You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
    <stream:error><policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en'>Too many (20) failed authentications from this IP address (::ffff:42.60.7.13). The address will be unblocked at 05:15:34 06.08.2020 UTC</text></stream:error>
    org.jivesoftware.smack.XMPPException$StreamErrorException: policy-violation You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
    <stream:error><policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en'>Too many (20) failed authentications from this IP address (::ffff:42.60.7.13). The address will be unblocked at 05:15:34 06.08.2020 UTC</text></stream:error>
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:966)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:898)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:921)
        at java.lang.Thread.run(Thread.java:919)

Which eventually leads to a NoResponseException

org.jivesoftware.smack.SmackException$NoResponseException: No response
received within reply timeout. Timeout was 30000ms (~30s). While
waiting for establishing TLS
[XMPPTCPConnection[not-authenticated] (4)]

We now set 'connected' to 'true' as soon as the transport (e.g. TCP,
BOSH, …) is connected. While this is in other ways also sensible, it
also allows notifyConnectionError() to handle exceptions in the early
connection stage.

Thanks to Eng Chong Meng for reporting this.
2020-08-06 16:32:26 +02:00
dd631048a3
NoEndpointDiscoveredException: s/Not/No 2020-07-28 19:00:04 +02:00
Florian Schmaus
ec80d5287b [core] Add String-based StateDescriptor precedence/inferiority declaration methods 2020-07-25 14:27:45 +02:00
Florian Schmaus
64fb47c98b Fix typo in StateDescriptor method: s/Inferiorty/Inferiority/ 2020-07-25 13:55:35 +02:00
Florian Schmaus
1bd097ed9b
Merge pull request #411 from Flowdalic/sasl
SASL / getFeature()
2020-07-23 16:09:57 +02:00
Florian Schmaus
329948b442 Add XMPP.(get|has)Feature(Class|QName) and deprecate (String, String) 2020-07-23 14:32:14 +02:00
Florian Schmaus
f1e10bc6bc
Merge pull request #409 from vanitasvitae/connectionListenerConnecting
ConnectionListener: Add connecting(XMPPConnection) method.
2020-07-23 14:19:14 +02:00
Florian Schmaus
2b423b911e Merge branch 'master' of github.com:igniterealtime/Smack 2020-07-18 21:47:06 +02:00
bc599a6dd6
Add callback method for when Smack is connecting 2020-07-18 12:50:08 +02:00
bb3c491e0c
StringUtils: Fix typo and expose unambiguous alphabet as string 2020-07-15 22:15:38 +02:00
Florian Schmaus
d3a99a133a [core] Fix log/exception message of XmppElementUtil
The Class.toString() already prefixes the resulting string with "class
", no need to state it explicitly in the log message that this is a
class.
2020-07-13 08:50:10 +02:00
Florian Schmaus
91337150e7 [sasl] Rename getChannelBindingName() to getGs2CbindFlag()
As this returns the value of the SCRAM gs2-cbind-flag.
2020-07-02 13:07:17 +02:00
Aditya Borikar
dcb66eef59 Add support for HTTP lookup method through xep-0156 2020-06-25 21:10:43 +05:30
Florian Schmaus
ddc39030d7 Rename waitForCondition() to waitForConditionOrConnectionException()
To make it clear that this will either return if the condition is
true *or* if a connection exception happened.

Also introduce waitFor(), which is deliberately not named
waitForCondition() because it carries a different semantic.
2020-06-17 21:56:45 +02:00
Florian Schmaus
3f9ca68134 Delete TypedCloneable 2020-06-14 17:38:51 +02:00
Florian Schmaus
18c2c37ad0 Rename XmlUnitUtils to XmlAssertUtil 2020-06-14 16:53:21 +02:00
Florian Schmaus
c689bef7ec Add static QNAME field to Compressed, Failure and Tls(Failure|Proceed) 2020-06-14 16:51:28 +02:00
Florian Schmaus
f1319d1c8b Move getters from Message to MessageView 2020-06-12 09:17:54 +02:00
Florian Schmaus
6a617af158 Merge branch 'master' of github.com:igniterealtime/Smack 2020-06-04 22:51:17 +02:00
Florian Schmaus
afbe833a97
Merge pull request #395 from adiaholic/docFix
Correct documentation
2020-06-02 22:07:35 +02:00
Florian Schmaus
ccbc0922ad [core] Fix comment 2020-06-02 10:05:56 +02:00
Florian Schmaus
81f10b0c5b [core] Synchronize notifyConnectionError()
Synchronize notifyConnectionError() so that only one exception is
handled and remove the ASYNC_BUT_ORDERED usage here. The
ASYNC_BUT_ORDERED was added with 7d2c3ac9f ("Do not call synchronized
methods in reader/writer thread"), but is no longer necessary, since
the Semaphores where replaced with conditions in the previous commit.
2020-05-31 19:49:40 +02:00
Florian Schmaus
57961a8cc1 Remove SynchronizationPoint
This continues the design started with e98d42790 ("SmackReactor/NIO,
Java8/Android19, Pretty print XML, FSM connections"), where the
exceptions that caused an operation to fail, are not recorded within
SynchronizationPoint but within the connection instance itself.
2020-05-31 19:48:47 +02:00
Aditya Borikar
d639e0bc4c Some more docFix es 2020-05-31 01:10:29 +05:30
Florian Schmaus
b1a4ccfae8 [core] Do not weakly reference "channel selected" callback
Since d65f2c932 ("Bump Error Prone version to 2.3.4 and fix new bug
patterns") the channel selected callback is no longer a final field of
the connection instance, hence it may be come null even if the
connection instance is still strongly referenced. Also the
ConnectionAttemptState class uses simply a lambda as callback, which
is also not strongly referenced otherwise.

The "channel selected" callback was wrapped in weak reference, so that
connection instances could get gc'ed if they are still connected but
the user lost all references to them. In this case, the weak reference
to the connection instance would become 'null' and
selectionKey.cancel() would be called.

This change means that a socket and its selection key of a "leaked"
connected connection instance continues to be part of the reactor. But
this may not be that bad: first, users are expected to manager their
connection instances, and disconnect them before they are
discarded. And secondly, at some point the connection likely will get
disconnected, and in this case, the socket and its selection key will
be removed from the reactor.
2020-05-30 19:45:59 +02:00
Florian Schmaus
f5448c5faa [core] Rework TLS logic
This moves the logic in AbstractXMPPConnection.getSmackTlsContext()
into the ConnectionConfiguration constructor.

Also introduce SslContextFactory and use it in
ConnectionConfiguration.
2020-05-25 15:41:57 +02:00
Florian Schmaus
7156849c77 [core] Set default SecurityMode to 'required' in ConnectionConfiguration 2020-05-25 14:44:35 +02:00
Florian Schmaus
d65f2c932e Bump Error Prone version to 2.3.4 and fix new bug patterns 2020-05-24 21:10:01 +02:00
Florian Schmaus
cac874bdc7 [core] Use UInt16 for ConnectionConfiguration 'port' 2020-05-24 13:08:03 +02:00
Florian Schmaus
9a8ee3c8e3 [core] Improve NumberUtil's exception message and fix javadoc 2020-05-24 13:08:03 +02:00
Florian Schmaus
ebe5c49e92 [checkstyle] Tighten JavadocMethod checkstyle rule 2020-05-23 22:43:29 +02:00
Florian Schmaus
a137944e50 [disco/caps] Fix DiscoverInfo.asBuilder()
The method would not copy the extensions elements, which would lead to
a false calculation of the caps hash by EntityCapsManager.
2020-05-22 15:38:16 +02:00
Florian Schmaus
68a453d3b3 [core] Fix deprecation javadoc in Presence
It should hint towards the StanzaFactory not SocketFactory.
2020-05-22 09:25:20 +02:00
Florian Schmaus
054fd9ae44 [core] Replace 'packet' with 'stanza' in Presence's javadoc 2020-05-22 09:25:15 +02:00
Florian Schmaus
962071762a [core] Optimize Presence.toXML() for empty element 2020-05-22 09:20:02 +02:00
Florian Schmaus
33720e8d97 [core] Fix potential NPE in Java7ZlibInputOutputStream
The field XMPPInputOutputStream.flushMethod was not initialized, which
could cause an NPE in the "switch (flushMethod)" found in
Java7ZlibInputOutputStream.getOutputStream().
2020-05-21 12:47:55 +02:00
Florian Schmaus
87591655ad [core] Add StanzaFilter.asPredicate(Class) 2020-05-18 09:15:14 +02:00
Florian Schmaus
72c5dc5886 [core] Introduce ScheduledAction.Kind for blocking and non-blocking actions 2020-05-18 09:15:14 +02:00
Florian Schmaus
4e5536e227 [core] Make ScheduledAction.cancel() return boolean and add javadoc 2020-05-18 09:15:14 +02:00
Florian Schmaus
6daf19dbd3 [core] Add javadoc to SmackReactor.cancel(ScheduledAction) 2020-05-18 09:15:14 +02:00
Florian Schmaus
dfdd0acf91 Introduce AbstractStats 2020-05-18 09:15:14 +02:00
dc64a43f12
Prevent NPE when closing trust store stream 2020-05-17 17:01:42 +02:00
Florian Schmaus
62ead2fbb3
Merge pull request #391 from vanitasvitae/typo
Quick typo fix: s/isntead/instead/g
2020-05-14 17:04:31 +02:00
d903184ee2
Quick typo fix: s/isntead/instead/g 2020-05-13 22:32:18 +02:00
Florian Schmaus
321c91c264 [build] Introduce bouncyCastleVersion variable and use it
Also bumps bouncy castle to 1.65.
2020-05-13 22:20:32 +02:00
Florian Schmaus
ab2d3a2b79 [core] Deprecate AbstractConnectionListener 2020-05-13 22:14:43 +02:00
Florian Schmaus
498dde2d86 Merge branch 'master' of github.com:igniterealtime/Smack 2020-05-13 20:20:01 +02:00
Florian Schmaus
77e26fc575 Re-work data form API
Apply builder pattern to form fields and replace getVariable() with
getFieldName(). Refer to the field name as "field name" instead of
"variable" everyone, just as XEP-0004 does.

Improve the high-level form API: introduce FilledForm and FillableForm
which perform stronger validation and consistency checks.

Also add FormFieldRegistry to enable processing of 'submit' forms
where the form field types are omitted.

Smack also now does omit the form field type declaration on 'submit'
type forms, as it is allowed by XEP-0004.
2020-05-13 20:14:41 +02:00
Guus der Kinderen
577c59484b pep: notification type can be normal or headline 2020-05-12 19:57:56 +02:00
Florian Schmaus
5e921e6393 core: add javadoc for StanzaView.getExtensions(Class) 2020-04-18 22:56:10 +02:00
Florian Schmaus
cdc5396f6c core: improve signature of Stanza.addExtensions() 2020-04-18 19:03:43 +02:00
Florian Schmaus
ad13effe41
Merge pull request #382 from vanitasvitae/typo
Fix typo in XmppElementUtil
2020-04-13 23:03:34 +02:00
Florian Schmaus
f3e93cef32 core: do not init() closingStreamReceived sync point in initState()
The initState() method is also called in disconnect(). And if we reset
the closingStreamReceived sync point at disconnect, it will break the
WaitForClosingStreamElementTest integration test.
2020-04-13 22:50:02 +02:00
Florian Schmaus
6c3cd53567 pep: improve pep event filter 2020-04-13 22:37:54 +02:00
Florian Schmaus
50da46ffda core: Add ExtensionElementFilter 2020-04-13 21:27:31 +02:00
Florian Schmaus
5114f6dfa4 core: remove deprecated methods in PacketUtil
Those where deprecated in 2015 with 8409dddff ("Add
PacketUtil.extensionElementFrom()"), and in 2017 with
2288825b1 ("Retain smack-core API").
2020-04-13 21:25:28 +02:00
Florian Schmaus
fb7054bbe7 core: delete deprecated ToFilter
This filter was marked deprecated in 2017 with 5d0dd49e6 ("Introduce
ToMatchesFilter"), time to delete it.
2020-04-13 20:54:04 +02:00
Florian Schmaus
988954a9db core: delete deprecated filters
Those where deprecated in 2015 with d4a6d8e65 ("Rename
PacketFilter (and implementing classes) and PacketExtension"), now it
is time to delete them.
2020-04-13 20:52:07 +02:00
Florian Schmaus
c49999b933 core: add shortcut via hash in EqualsUtil
Return false as soon as the hashed value does not match. This is
sound, since every class that implements equals(Object) should also
implement hashCode().
2020-04-13 20:40:10 +02:00
905d5dc102
Fix typo in XmppElementUtil 2020-04-13 18:18:31 +02:00
Florian Schmaus
5438fb7b33 core: add hint towards StanzaView.getExtension(Class) 2020-04-12 12:17:05 +02:00
Florian Schmaus
d498cd8499 core: re-add Stanza.getExtension(String, String) and mark deprecated
This method was removed with 07da9ffb4 ("Do not have
Stanza.getExtension(String, String) return a generic type"). In order
to aide migration to the newer API, this commit re-adds the method and
marks it as deprecated.
2020-04-12 12:17:05 +02:00
Florian Schmaus
7bc2ebb731 core: fix javadoc of Stanza.getExtensionElement(String, String)
The element name must not be null or empty.
2020-04-12 12:17:05 +02:00
Florian Schmaus
7a57bb7c09 Rename Stanza.getExtension(String, String) to getExtensionElement() 2020-04-12 12:09:04 +02:00
Florian Schmaus
4ccced906e core: add SuppressWarnings("static-method") to getReactor() 2020-04-11 22:07:16 +02:00
Florian Schmaus
b5f9d4d7a3 Introduce test fixtures
This also removes the powermock dependency. Although powermock is a
fine library, it currently prevents dropping Junit4. And since we only
use the Whitebox API of powermock, this simply replaced powermock's
Whitebox with our own.
2020-04-11 22:05:36 +02:00
Florian Schmaus
2c83c73005 core: Avoid ClassCastException in getExtension(Class)
Ensure that he returned extension element is actually of the correct
type. It should not be common, but in theory, Smack's provider
architecture would allow for different types to be returned than the
ones one may expect.
2020-04-11 18:04:15 +02:00
Florian Schmaus
85af4a022d compression: remove Android SDK level < 19 compatiblity
Since we now require Android SDK 19 or higher, we can use the method
directly.
2020-04-09 20:54:36 +02:00
Florian Schmaus
f1dd925844 Mark code from the old integration-test dir as migration candidates 2020-04-09 15:14:09 +02:00
Florian Schmaus
f329b447f2 Delete some outdated code from the old integration-test dir
The code in the integration-test/ directories should either be
migrated to sinttest (or unit tests), or get deleted. This is a first
small step towards this goal.
2020-04-09 15:14:09 +02:00
Florian Schmaus
5579567572 core: use addCompressionHandler() instead directly adding to the list 2020-04-09 15:14:09 +02:00
Florian Schmaus
8b0de5ff85 Introduce TLSUtils.setEnabledTlsProtocolsToRecommended(B builder)
And deprecate no longer recommended methods.

Thanks to Milan Kral <milan.kral@azet.sk> for the initial PR which
triggered this commit.
2020-04-05 22:28:01 +02:00
Florian Schmaus
07da9ffb48 Do not have Stanza.getExtension(String, String) return a generic type
Returning a generic would allow for

List<ExtensionElement> list = stanza.getExtension("foo", "bar");

to compile (Note the we are calling getExtension(), not
getExtension*s*()).

Users are encouraged to use the type safe getExtension(Class<? extends
ExtensionElement) variant instead.

Fixes SMACK-825.
2020-04-05 22:10:05 +02:00
Florian Schmaus
62916b8490 Improve exception message of XmppElementUtil.getQNameFor() 2020-04-05 22:08:10 +02:00
Florian Schmaus
8d432e2303 Add StanzaView.hasExtension(Class<? extends ExtensionElement>) 2020-04-05 19:59:24 +02:00
Florian Schmaus
5380e5705f Remove deprecated Packet(Extension) and DefaultExtensionElement types
Those where deperecated in 2015. Time to remove them.
2020-04-05 19:12:10 +02:00
Florian Schmaus
3382cbdf44 Delete superfluous newline in SmackInitialization 2020-04-05 18:59:28 +02:00
Florian Schmaus
439e29a1c7 Do not import Message.Body explicitly in SmackInitialization 2020-04-05 18:59:02 +02:00
Florian Schmaus
14c351397d Implement message stanza <thread/> and <subject/> as ExtensionElement
Fixes SMACK-852.
2020-04-05 18:58:13 +02:00
Florian Schmaus
f9fb4d7627 Remove deprecated XmlStringBuilder.rightAngelBracket()
This method was marked deprecated with bbf89c65b ("Fix typo in
XmlStringBuilder, it's not an Angel"). Now it is time to remove it.
2020-04-05 17:26:21 +02:00
Florian Schmaus
12e20c2d6c Remove deprecated methods/fields scheduled for removal in Smack 4.4 2020-04-04 13:03:48 +02:00
Florian Schmaus
cc636fff21 Introduce Smack's Modular Connection Architecture
This is a complete redesign of what was previously
XmppNioTcpConnection. The new architecture allows to extend an XMPP
client to server (c2s) connection with new transport bindings and
other extensions.
2020-04-04 13:03:31 +02:00
Florian Schmaus
4dd3800d82 Remove Bouncycastle as direct dependency
By not directly depending on Bouncycastle (BC), we avoid conflicts between
different bouncycastle versions. It is also part of the developers job
to take care that all required security primitives are available. If
they are provide by BC or some other security provider should not be
up to Smack to decide.

We now only add BC as test dependency to satisfy this requirement when
the unit tests are executed.
2020-03-13 16:58:45 +01:00