Compare commits

...

126 Commits

Author SHA1 Message Date
Florian Schmaus 4f2d8e8d4c
Merge pull request #473 from Flowdalic/coveralls
[ci] Re-enable coveralls
2021-05-22 20:21:23 +02:00
Florian Schmaus b52e02740b [ci] Re-enable coveralls 2021-05-22 13:32:03 +02:00
Florian Schmaus e9ca16ed12 [websocket-java11] Add test 2021-05-22 13:32:03 +02:00
Florian Schmaus 8d74873925 Merge branch '4.4' 2021-05-20 14:39:32 +02:00
Florian Schmaus 4eb5869860 [build] Remove markdown-gradle-plugin 2021-05-20 14:38:16 +02:00
Florian Schmaus 39b211cde3 [muc] Use StanzaCollector.nextResultBlockForever() in MultiUserChat.nextMessage() 2021-05-12 10:18:17 +02:00
Florian Schmaus 602aafe119 [fix-a-javadoc] Modernize, tell xargs to run in parallel 2021-05-12 10:14:02 +02:00
Florian Schmaus b0729d83a8 [jingle] Do not call nextResult() in JingleUtil
StanzaCollector.nextResult() will not cancel the related stanza
collector potentially causing a resource leak.
2021-05-12 10:12:59 +02:00
Florian Schmaus aab48570c9 Call XMPPConnection.sendIqRequestAndWaitForResponse(IQ) where possible
Refactored using

find . -type f -name "*.java" |\
	 xargs sed -i -E |\
		's/\.createStanzaCollectorAndSend\((\w+)\)\.nextResultOrThrow\(\);/.sendIqRequestAndWaitForResponse(\1);/'

and some manual refactoring.
2021-05-12 10:12:40 +02:00
Florian Schmaus c9ea1c11b6 [search] Return and expect the high-level forms API types 2021-05-02 22:02:40 +02:00
Florian Schmaus 6ec654ad1e [muc] Fix javadoc of MultiUserChat.getConfigurationForm()
This method no longer returns null.
2021-05-02 22:02:00 +02:00
Florian Schmaus 1fee87b24d [openpgp] Do not catch Exception, catch the expected exception types 2021-05-02 18:45:25 +02:00
Florian Schmaus 5e43ef550f [openpgp] Improve control-flow logic in PainlessOpenPgpProvider
Also remove superfluous toString().
2021-05-02 18:45:25 +02:00
Florian Schmaus 64db6e3ebc [openpgp] Remove INFO log sites
INFO log sites should be used sparingly and carefully. Those are a
good examples for an unnecessary INFO log sites.
2021-05-02 18:45:25 +02:00
Florian Schmaus aa49743ef8 [openpgp] Downgrade log site from INFO to FINE 2021-05-02 18:41:28 +02:00
Florian Schmaus 8cd0a9f5ce [core] Mark IntrospectionProvider as deprecated 2021-05-02 17:16:58 +02:00
Florian Schmaus 6af38482de [iqversion] Use IQ builder pattern 2021-05-02 17:16:58 +02:00
Florian Schmaus 469d4fb0dc [time] Use IqBuilder pattern and improve API 2021-05-02 17:16:58 +02:00
Florian Schmaus cd33b885ae [xmlparser] Add SmackXmlParser.newXmlParser(InputStream) 2021-05-02 17:16:58 +02:00
Florian Schmaus a806595a77 [core] Move IqData construction API to the right place
AbstractIqBuilder is the wrong place for those methods, they belong in
IqData.
2021-05-02 17:16:58 +02:00
Florian Schmaus 6b14fcab75 [geoloc] Mark Builder constructor as deprecated 2021-05-02 17:16:58 +02:00
Florian Schmaus 6011d566cf [geoloc] Do not use Time IQ for timezone operations 2021-05-02 17:16:58 +02:00
Florian Schmaus 5cd77ec741 [geoloc] Mark Builder class final 2021-05-02 16:32:42 +02:00
Florian Schmaus 70cb9e8a94 [resources] Use realpath instead of readlink in fix-java-javadoc.sh 2021-04-27 17:01:50 +02:00
Florian Schmaus ba5c2e46d8 [smack-core] Fix javadoc of EmbeddedExtensionProvider 2021-04-27 17:01:50 +02:00
Florian Schmaus 65c363b19d
Merge pull request #470 from Fishbowler/fix_muc_javadoc
[sinttest] Tweaks to the muc test javadoc
2021-04-26 15:36:18 +02:00
Dan Caseley fc191e4e19 [sinttest] Add XEP reference for muc destroy test 2021-04-26 13:28:00 +01:00
Dan Caseley b541397119 [sinttest] Fix typo in muc XEP reference for test 2021-04-26 13:26:29 +01:00
Florian Schmaus 6a78e4ad09 [sinttest] Do not catch exceptions when destroying a MUC
If something goes wrong when destroying a MUC, we want to be notified
about it immediately, as further results of the integration test run
are unreliable anyway.
2021-04-26 09:42:20 +02:00
Florian Schmaus a36251ff7d Merge remote-tracking branch 'github/pr/469' into muc 2021-04-26 09:08:44 +02:00
Florian Schmaus 0c397294e1 Merge remote-tracking branch 'github/pr/468' into muc 2021-04-26 09:00:50 +02:00
Dan Caseley 920b686f29 Add kick presence tests
Inspired by OF-2240. Used to validate the problem, then test the fix.
2021-04-25 14:32:58 +01:00
Dan Caseley 642f5bde61 [sinttest] Fix ordering of parameters in muc assertEquals checks 2021-04-23 16:50:33 +01:00
Florian Schmaus 64c82ca0cf [muc] Add MultiUserChat.destroy() 2021-04-23 17:34:47 +02:00
Florian Schmaus c95c8264da [muc] Improve javadoc of MultiUserChat.destory(String, EntityBareJid) 2021-04-18 21:38:55 +02:00
Florian Schmaus 8a91021a0e [sinttest] Improve MultiUserChatIntegrationTest.tryDestroy(MultiUserChat) 2021-04-18 21:35:34 +02:00
Florian Schmaus 3d4e7938a7 Make ExtensionElement marker interface wrt. QNAME field
ExtensionElement is now a marker interface that requires all
implementation non-abstract classes to carry a static final QNAME
field (of type QName). This is verified by a new unit test.

Also FullyQualifiedElement is renamed to simply XmlElement. XmlElement
is used over ExtensionElement when implementing classes do not
statically know the qualified name of the XML elements they
represent. In general, XmlElement should be used sparingly, and every
XML element should be modeled by its own Java class (implementing
ExtensionElement).
2021-04-18 21:07:19 +02:00
Florian Schmaus 5493a22e44 Merge branch '4.4' 2021-04-18 17:25:14 +02:00
Florian Schmaus 961882ff7f Add more QNAME fields to extension element classes 2021-04-18 17:23:34 +02:00
Florian Schmaus 36c7521ca2 [offline] Add OfflineMessageInfo.QNAME field
Fixes SMACK-905.
2021-04-18 17:17:48 +02:00
Florian Schmaus b0abfe1bba [offline] Make OfflineMessageManager.NAMESPACE public 2021-04-18 17:16:38 +02:00
Florian Schmaus 2b1097a743 [README] Update README.md 2021-04-15 10:20:24 +02:00
Florian Schmaus fbddd074bc [gradle] Do not use deprecated 'compile' directive 2021-04-14 20:30:51 +02:00
Florian Schmaus 6b3e41d591 Merge branch 'master' of github.com:igniterealtime/Smack 2021-04-12 14:06:15 +02:00
Florian Schmaus 35c645e24b
Merge pull request #446 from Fishbowler/add_muc_tests
Add MUC tests
2021-04-08 10:23:37 +02:00
Dan Caseley aff6283798 Add MUC tests for presence & self-presence for role & affiliation changes 2021-04-07 10:33:38 +01:00
Dan Caseley b7709f583d Make muc.join() mirror muc.leave() and return the self-presence 2021-04-07 10:33:38 +01:00
Florian Schmaus 138725a22f [sinttest] Log testPackages to ISE's message
This means we the reason for the LOGGER.info() call is now gone.
2021-04-05 15:02:58 +02:00
Florian Schmaus aefbb28875 [websocket] Fix getStreamFromOpenElement() 2021-04-01 17:43:07 +02:00
Florian Schmaus c484b72fb7 [sinttest] Fix buildWebsocketDescriptor() 2021-04-01 17:22:23 +02:00
Florian Schmaus 0c4b5d3ff9 [sinttest] Log if sinttest packages are provided via command line 2021-04-01 17:22:06 +02:00
Florian Schmaus cd10d1b40c [sinttest] Downgrade org.refelections:reflections to 0.9.11 2021-04-01 17:21:49 +02:00
Florian Schmaus 533695c1b4 [core] Properly reply to IQ requests
Properly reply to IQ requests with feature-not-implemented or
service-unavailable. In case there is no IQ request handler but the IQ
namespace is known, we reply with feature-not-implemented, otherwise
with service-unavailable.
2021-04-01 13:57:36 +02:00
Guus der Kinderen 252cea1149 SINT: MAM test does not require XEP-0441
The MAM integration test setup attepts to set MAM preferences (XEP-0441).
When a server does not support this XEP, the setup phase errors out, preventing
the tests from being executed.

There is no functional reason why tests shouldn't be run when XEP-0441 is not
supported: the tests can run against the default configuration of the MAM
service.

This commit ignores feature-not-implemented errors when MAM
preferences are set.

[Ignore only feature-not-implemented errors, log ignored errors)
Modified-by: Florian Schmaus <flo@geekplace.eu>
2021-04-01 13:13:42 +02:00
Florian Schmaus e6433a6870 Merge branch '4.4' 2021-03-31 12:26:25 +02:00
Florian Schmaus 8c57d34b97
Merge pull request #466 from Vshnv/master
Added proxy support for XEP-0363
2021-03-29 18:15:40 +02:00
Vshnv 4736d080a1 Added proxy support for XEP-0363 2021-03-29 19:01:58 +05:30
Vshnv 525db827a9 Added support for Java's Proxy class in ProxyInfo 2021-03-29 19:01:42 +05:30
Florian Schmaus e04a3877fb Merge branch '4.4' 2021-03-25 19:28:58 +01:00
Florian Schmaus 92f4aadfdc [sasl] Avoid mechanisms that need a password when none is available 2021-03-25 15:01:15 +01:00
Florian Schmaus 72e11ebf71 [README] Fix typo; s/NOICE/NOTICE/ 2021-03-25 15:00:07 +01:00
Florian Schmaus 33d735a42e [core] Make Smack.getNoticeStream() more robust
Appearently simply calling ClassLoader.getSystemResourceAsStream()
works on Java SE but not on Android. But our FileUtils are able to
load the resource stream on Android.
2021-03-25 14:58:44 +01:00
Florian Schmaus b58511d624 [core] Also provide incoming Nonzas to SmackDebugger 2021-03-25 14:51:25 +01:00
Florian Schmaus 5844bee1c3 [javadoc-overview] Disconnect the connection in example code 2021-03-25 12:23:39 +01:00
Florian Schmaus a39d44ed1f [javadoc-overview] Improve 'License' section 2021-03-25 12:23:19 +01:00
Florian Schmaus 406daa78f7 [javadoc-overview] Use stanza factory in example code 2021-03-25 12:16:34 +01:00
Florian Schmaus 61713c500c Smack 4.4.2
-----BEGIN PGP SIGNATURE-----
 
 iQGTBAABCgB9FiEEl3UFnzoh3OFr5PuuIjmn6PWFIFIFAmBcSRtfFIAAAAAALgAo
 aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDk3
 NzUwNTlGM0EyMURDRTE2QkU0RkJBRTIyMzlBN0U4RjU4NTIwNTIACgkQIjmn6PWF
 IFJs0wf/TYm4e4LlBiekmar8YnfaAObT9loDiqMJjO5s4g+trYx2U3gCKkRvKI0P
 U/jzqoJohcPY+5s/fkGKaBWjzFD5WucHyvNaP01D4EWSvHXpCMElbSxY1Uz3X4k1
 t0pmdb27DoHhtdqMfw1Cg7Nba4M+ZzdrEIkDRgCNA8H0mJoKpnsDAg8Y6kEUnvt6
 WQxmIZ49ZT9UOQnVbsXUk4t5DZDz1GdQggrDS5Sh+rZaRFy1KyDgLC+X4NQO99RV
 v3Tf4VRIy+6Nen7L/av3qwSBRqpvc1TEJauNwOnYvyuDwpwjE0tEfRuFZ8wjtkAz
 CKF+LLor+WA5Y2GCXEegLJxVd9Je6Q==
 =hZJ2
 -----END PGP SIGNATURE-----

Merge tag '4.4.2'

Smack 4.4.2
2021-03-25 11:45:03 +01:00
Florian Schmaus 2dab49f048 Smack 4.4.3-SNAPSHOT 2021-03-25 09:46:57 +01:00
Florian Schmaus 9d64af26b7 Smack 4.4.2 2021-03-25 09:26:02 +01:00
Florian Schmaus d07d46bbdc [chat2] Fix resource unlock condition
If the resource of the updated presence is equal to the currently
locked resource, then no further action is required.

Thanks to Pedro Oliveira for reporting this.

Reported-by: Pedro Oliveira <kanytu@gmail.com>
2021-03-25 08:22:12 +01:00
Florian Schmaus eb31479913 [muc] Make sendMessage() return a MessageView of the sent message 2021-03-25 08:19:53 +01:00
Florian Schmaus ed807d5954 Merge branch '4.4' 2021-03-23 21:41:25 +01:00
Florian Schmaus 64a2db3f19 [sid] Add <origin-id/> to MUC messages if not muc#stable_id 2021-03-23 21:27:10 +01:00
Florian Schmaus 4381d04831 [muc] Introduce MucMessageInterceptor 2021-03-23 21:27:10 +01:00
Florian Schmaus b8f23eb371 [sid] Do not enable StableUniqueStanzaIdManager per default 2021-03-23 21:27:10 +01:00
Florian Schmaus 800c771700 [sid] Check if there is already a <origin-id/> in addOriginId() 2021-03-23 21:27:09 +01:00
Florian Schmaus 4fefa92e40 Merge branch '4.4' 2021-03-19 09:47:07 +01:00
Florian Schmaus b276b89916 [sinttest] Add code comment and empty line 2021-03-18 21:32:37 +01:00
Florian Schmaus ddf96828e4 [sinttest] Add fromMarkers array to exception message 2021-03-18 21:32:21 +01:00
Florian Schmaus 35cd1a8f88 [sinttest] Do not lazily create fromMarkers
If we do not create the fromMarkers initialized with 'false' at the
start, then it may appear like all messages are received, because we
only check for false markers. But if there is not even the fromMarkers
array, then we do not see those 'false' markers.
2021-03-18 21:32:10 +01:00
Florian Schmaus 47178fd27d Bump JUnit to 5.7.1 2021-03-18 09:01:03 +01:00
Florian Schmaus 9520aa7d90 [sinttest] Do not create myReceiveMarkers on demand 2021-03-15 19:24:19 +01:00
Florian Schmaus 11a486d84d [sinttest] Add header to NotAllMessagesReceivedException
This header maps the internal connection ID to the connection.
2021-03-15 19:22:57 +01:00
Florian Schmaus f91598e10c [sinttest] Improve NotAllMessageReceivedException 2021-03-15 19:22:26 +01:00
Florian Schmaus ad8eeebc0d [sinttest] Allow maxPayloadChunks == 0 2021-03-15 19:21:55 +01:00
Florian Schmaus d75cd2acb8 [filetransfer] Pre-register 'stream-method' form field
Fixes SMACK-904.
2021-03-14 19:34:28 +01:00
Florian Schmaus adc159186c [formtypes] Introduce LOOKASIDE_FIELD_REGISTRY
Some field's like stream-method of XEP-0096, which is of type
list-single, need to be pre-registered.
2021-03-14 17:58:13 +01:00
Florian Schmaus 73941629f3 [sinttest] Call OutgoingFiletransfer.getException() in case of error 2021-03-14 17:57:13 +01:00
Florian Schmaus 2779187d8c [filetransfer] Set the status to error in setException()
FileTransfer would previously not change the status, even though an
exception has been set, leading users to believe that the transfer is
still ongoing, when it is not.
2021-03-14 17:54:03 +01:00
Florian Schmaus c564c89c40 [extensions] Add OutgoingFileTransfer.setCallback()
Some methods of OutgoingFileTransfer take already the
NegotiationProgress callback as argument, some do not. The API is not
ideal, and adding a setter for the callback at least makes it possible
to always have the callback.
2021-03-14 17:52:12 +01:00
Florian Schmaus f2b44f65d9 [tcp] Add code comment why we need to set "running = false" here 2021-03-14 17:51:33 +01:00
Florian Schmaus 9d1b88a877 [muc] Do not filter for presence ID if #stable_id is not announced
On leave(), do not filter for presence ID if the MUC service does not
announce #stable_id.
2021-03-14 12:48:01 +01:00
Florian Schmaus 61cb73ee37 [core] Add AndFilter(List<StanzaFilter>) constructor 2021-03-14 12:48:01 +01:00
Florian Schmaus 14142a0ef2 [omemo] Introduce OmemoAesCipher as central AES API
OmemoAesCipher is the sole point where OMEMO related AES operations
are performed. This allows OmemoAesCipher to check in a static block
if AES is available. If AES is not available it throws a (hopefully)
helpfull exception message.

Typically AES is not available on Android if no security provider
providing AES, like Bouncy Castle, has been explicitly configured.
2021-03-14 12:48:01 +01:00
Florian Schmaus b7905d585d [omemo] Use RandomUtil.fillWithSecureRandom() to generate IV 2021-03-14 12:48:01 +01:00
Florian Schmaus 17ac41c8cb [core] Add RandomUtil.fillWithSecureRandom(byte[]) 2021-03-14 12:48:01 +01:00
Florian Schmaus 7cf0112487 [omemo] Cleanup CryptoFailedException
Remove the unused list of exceptions and add a (String, Exception)
constructor.
2021-03-14 12:48:00 +01:00
Florian Schmaus c7b429535b [doc] Fix extensions/index.md table 2021-03-10 10:24:39 +01:00
Florian Schmaus f9114f780d [tcp] Ignore exceptions in reader thread if writer was terminated
If we do not ignore the exception, then users may receive an exception
via connectionClosedOnError() on connection termination. Those
exceptions are typically unwanted if they are caused e.g. because the
server does not send a closing stream tag.

We previously ignored exceptions in this case already, but that
behavior was changed with [1: 57961a8cc1]. This commit re-adds the
behavior.

1: 57961a8cc1
   Remove SynchronizationPoint
2021-03-09 19:27:53 +01:00
Florian Schmaus 4adbd21a0f [smack-xmlparser] Allow override of used XmlPullParserFactory 2021-03-03 22:25:32 +01:00
Florian Schmaus 3bef905ef5 [xmlparser-stax] Move getNamespace() to its friends within the file 2021-03-03 21:43:43 +01:00
Florian Schmaus ba6968fc79 [xmlparser-stax] Fix potential IAE in StaxXmlPullParser.getNamespace()
StAX's NamespaceContext.getNamespaceURI(String) is allowed to throw an
IllegalArgumentException in case the argument is null. We simply
re-use getNamespace(String) which will substitute the default
namespace if the argument is null to avoid this.

Connection closed due to an exception
java.lang.IllegalArgumentException: Illegal to pass null as argument
at com.ctc.wstx.sr.NsInputElementStack.getNamespaceURI(NsInputElementStack.java:486)
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.getNamespace(StaxXmlPullParser.java:113)
at org.jivesoftware.smack.AbstractXMPPConnection.parseFeatures(AbstractXMPPConnection.java:1852)
at org.jivesoftware.smack.AbstractXMPPConnection.parseFeaturesAndNotify(AbstractXMPPConnection.java:1887)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1300(XMPPTCPConnection.java:130)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:983)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:913)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:936)
at java.lang.Thread.run(Thread.java:748)

Fixes SMACK-903
2021-03-03 21:41:07 +01:00
Florian Schmaus 48f5e349b9 Smack 4.4.1
-----BEGIN PGP SIGNATURE-----
 
 iQGTBAABCgB9FiEEl3UFnzoh3OFr5PuuIjmn6PWFIFIFAmA/eF1fFIAAAAAALgAo
 aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDk3
 NzUwNTlGM0EyMURDRTE2QkU0RkJBRTIyMzlBN0U4RjU4NTIwNTIACgkQIjmn6PWF
 IFLlCQf6A9u5hd2v36Cve/Iopx/GAjuHBNu/7DYop7gP7vLtKxUBGCS/DLn8kaov
 ujpTvdcpm6pg7F4uivMnADFqkkL9cUwsBPDyNY8c0ygfGzVPU8P47g00/SBhB7kP
 0/0In4eunXt8+tfs/afHrr1kQG66lq5J/9q8M6bbC9pUYO2g5Flxes0WW9azluVh
 zs39CCtXPeXwr6Lh+HNEyIe/WiHKnOj7zkwpV7htmOnPaedlRJj/e8KbcBDxmZhg
 zbMoI3Puq3grlA6spke6Z7HK6IeFZjbZABI4EeCEUVhUq1VvL0JurV92S672dty+
 SXX64GbA5TLbVq04I+NP28x9kgnRiw==
 =skkJ
 -----END PGP SIGNATURE-----

Merge tag '4.4.1'

Smack 4.4.1
2021-03-03 13:39:57 +01:00
Florian Schmaus 7d6891c077 Smack 4.4.2-SNAPSHOT 2021-03-03 13:38:25 +01:00
Florian Schmaus ae44af5d63 Smack 4.4.1 2021-03-03 12:51:56 +01:00
Frank Matheron d4d2a7a6d8 [xdata] Do not require FORM_TYPE field in FilledForm
The FillableForm API is the most convenient way of filling out a
form. Currently only forms with a FORM_TYPE can be filled, due to a
restriction in FillableForm. This makes filling out untyped forms very
cumbersome.

This commit removes the required FORM_TYPE when using FilledForm (and
therefor FillableForm). Some subclasses of FilledForm already check
that the correct FORM_TYPE is set using FilledForm#ensureFormType().
2021-03-03 12:42:17 +01:00
Florian Schmaus bca3821343
Merge pull request #465 from Flowdalic/xdata-order-fields
[xdata] Order fields
2021-03-03 10:11:40 +01:00
Florian Schmaus 33f59fd7ed [xdata] Ensure that hidden FROM_TYPE field is first 2021-03-02 21:40:52 +01:00
Florian Schmaus 687c4f35aa
Merge pull request #464 from Flowdalic/relax-forms-v2
Relax forms (v2)
2021-03-02 15:50:09 +01:00
Florian Schmaus 1c262471e5 [xdata] Use extra registry for fields in clark notation
If a field name is in clark notation, then lookup the field's type via
an extra registry.
2021-03-02 11:43:23 +01:00
Florian Schmaus 3c4610d500 Merge branch 'master' of github.com:igniterealtime/Smack 2021-02-28 11:59:36 +01:00
Florian Schmaus 19521174f4
Merge pull request #463 from vanitasvitae/intellij_import
Add Smack import schema file for Intellij
2021-02-27 16:06:34 +01:00
Paul Schaub af77543544
Add Smack import schema file for Intellij 2021-02-27 15:11:11 +01:00
Florian Schmaus 1a1a67a2c5 [core] Add assert message in AbstractXMPPConnection.onStreamOpen() 2021-02-25 22:09:59 +01:00
Florian Schmaus d881395d05
Merge pull request #460 from Flowdalic/ci-java-15
Run CI also with Java 15
2021-02-15 13:43:48 +01:00
Florian Schmaus 4e90db3191 [gitlab-ci] Also check with Java 15 2021-02-15 13:12:24 +01:00
Florian Schmaus 8b0248c346 Bump Mockito to 3.7.7 2021-02-15 13:12:24 +01:00
Florian Schmaus 4aacdc5154 Add smack-websocket-java11
This also lifts a bunch of logic from smack-websocket-okhttp into
smack-websocket. Furthermore, the following subprojects require now
Java 11:
- smack-integration-test
- smack-omemo-signal-integration-test
- smack-repl
- smack-websocket-java11

Related tracking issue: SMACK-835
2021-02-14 20:34:40 +01:00
Florian Schmaus cd40455b62 [smack-integration-test] Bump reflections to 0.9.12
This also means that smack-integration-test needs to declare a
dependency on Guava, which was previously available as transitive
dependency of 'reflections' 0.9.11.
2021-02-14 18:37:44 +01:00
Florian Schmaus fe3214291d Bump Bouncy Castle to 1.68 2021-02-14 18:35:50 +01:00
Florian Schmaus 9261d6485e [openpgp] Do not put the BouncyCastleProvider at first position
This causes

java.security.InvalidKeyException: cannot identify XDH private key

on Java 11 or higher.

See also
- https://github.com/bcgit/bc-java/issues/620
- https://github.com/bcgit/bc-java/issues/589
- https://github.com/corretto/corretto-11/issues/168
- https://bugs.openjdk.java.net/browse/JDK-8171279
2021-02-14 18:35:49 +01:00
Florian Schmaus ce4f85acf8
Merge pull request #459 from Flowdalic/reported-data
[DataFormProvider] Retrieve field types from <reported/> if possible
2021-02-01 16:04:48 +01:00
Florian Schmaus bda3901910 Deprecate DataForm.Builder.setType() 2021-01-29 20:40:05 +01:00
Florian Schmaus 070aa8e28e [DataFormProvider] Retrieve field types from <reported/> if possible
Fixes SMACK-902.
2021-01-29 20:40:05 +01:00
Florian Schmaus 86b48fbf00
Merge pull request #458 from Flowdalic/errorprone
Bump ErrorProne to 2.5.1 and refactor Providers a bit
2021-01-29 09:45:24 +01:00
Florian Schmaus a7b3303f3e Bump ErrorProne to 2.5.1 and refactor Providers a bit
This also resulted in a refactoring of the Providers and parsing
Exceptions. NumberFormatException and ParseException can now be thrown
directly, the wrapping in a SmackParsingException is down at a higher
layer, i.e. in AbstractProvider.
2021-01-29 09:26:15 +01:00
414 changed files with 4330 additions and 1940 deletions

View File

@ -12,7 +12,11 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
java: [ 1.8, 11 ]
java:
- 11
- 15
env:
PRIMARY_JAVA_VERSION: 11
steps:
- name: Checkout
@ -76,12 +80,12 @@ jobs:
# Javadoc
- name: Javadoc
if: ${{ matrix.java == 11 }}
if: ${{ matrix.java == env.PRIMARY_JAVA_VERSION }}
run: ${PATH_TO_GRADLE} javadocAll --stacktrace
# Test Coverage Report
- name: Jacoco Test Coverage
if: ${{ matrix.java == 1.8 }}
if: ${{ matrix.java == env.PRIMARY_JAVA_VERSION }}
run: ${PATH_TO_GRADLE} jacocoRootReport coveralls
env:
COVERALLS_REPO_TOKEN: S2ecSJja2cKJa9yv45C8ZFPohXuRrTXKd

View File

@ -6,12 +6,12 @@ Smack
About
-----
[Smack] is an open source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android.
[Smack] is an open-source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android.
A pure Java library, it can be embedded into your applications to create anything from a full XMPP instant messaging client to simple XMPP integrations such as sending notification messages and presence-enabling devices.
Smack and XMPP allows you to easily exchange data, in various ways e.g. fire-and-forget, publish-subscribe, between human and non-human endpoints (M2M, IoT, …).
Being a pure Java library, it can be embedded into your applications to create anything from a full XMPP instant messaging client to simple XMPP integrations such as sending notification messages and presence-enabling devices.
Smack and XMPP allow you to easily exchange data in various ways e.g., fire-and-forget, publish-subscribe, between human and non-human endpoints (M2M, IoT, …).
More information are provided by the [Overview](documentation/overview.md).
More information is provided by the [Overview](documentation/overview.md).
Getting started
---------------
@ -23,7 +23,7 @@ Instructions on how to use Smack in your Java or Android project are provided in
License
-------
Most of Smack is governed by the Apache License 2.0 (SPDX License Identifier: Apache 2.0). This license requires that the contents of a NOICE text file are shown "…within a display generated by the Derivative Works, if and wherever such third-party notices normally appear.".
Most of Smack is governed by the Apache License 2.0 (SPDX License Identifier: Apache 2.0). This license requires that the contents of a NOTICE text file are shown "…within a display generated by the Derivative Works, if and wherever such third-party notices normally appear.".
Smack comes which such a NOTICE file. Moreover, since `smack-core` is licensed under the Apache License 2.0, the conditions apply to every project using Smack. The content of Smack's NOTICE file can conveniently be retrieved using `Smack.getNoticeStream()`.
@ -32,10 +32,12 @@ Some subprojects of Smack are governed by other licenses. Please refer to the in
Professional Services
---------------------
Smack is a collaborative effort of many open source, professionally and spare-time, paid and unpaid, contributors.
While we try to provide the best possible XMPP library for Android and Java SE compatible execution environments by following state of the art software engineering practices, the API may not always perfectly fit your requirements.
We welcome contributions and encourage discussion about how Smack can be further improved.
We also provide **paid services** ranging from **XMPP/Smack related consulting** to **designing and developing features** in order to accommodate your needs.
Smack is a collaborative effort of many people.
Some are paid, e.g., by their employer or a third party, for their contributions.
But many contribute in their spare time for free.
While we try to provide the best possible XMPP library for Android and Java SE-compatible execution environments by following state-of-the-art software engineering practices, the API may not always perfectly fit your requirements.
Hence welcome contributions and encourage discussion about how Smack can be further improved.
We also provide **paid services** ranging from **XMPP/Smack related consulting** to **designing and developing features** to accommodate your needs.
Please contact [Florian Schmaus](mailto:flo@geekplace.eu) for further information.
Bug Reporting

View File

@ -5,20 +5,40 @@ buildscript {
maven { url 'https://dl.bintray.com/content/aalmiray/kordamp' }
}
dependencies {
classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2'
}
}
plugins {
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'net.ltgt.errorprone' version '1.1.1'
id 'net.ltgt.errorprone' version '1.3.0'
// Use e.g. "gradle <task> taskTree" to show its dependency tree.
id 'com.dorongold.task-tree' version '1.5'
id 'com.github.kt3k.coveralls' version '2.10.2'
}
apply plugin: 'org.kordamp.gradle.markdown'
ext {
java11Projects = [
':smack-integration-test',
':smack-omemo-signal-integration-test',
':smack-repl',
':smack-websocket-java11',
].collect { project(it) }
java11Projects += getRootProject()
java8Projects = allprojects - java11Projects
}
configure (java8Projects) {
ext {
javaCompatilibity = JavaVersion.VERSION_1_8
}
}
configure (java11Projects) {
ext {
javaCompatilibity = JavaVersion.VERSION_11
}
}
allprojects {
apply plugin: 'java-library'
@ -34,7 +54,7 @@ allprojects {
isSnapshot = version.endsWith('-SNAPSHOT')
gitCommit = getGitCommit()
javadocAllDir = new File(buildDir, 'javadoc')
documentationDir = new File(buildDir, 'documentation')
documentationDir = new File(projectDir, 'documentation')
releasedocsDir = new File(buildDir, 'releasedocs')
rootConfigDir = new File(rootDir, 'config')
sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
@ -125,9 +145,12 @@ allprojects {
jxmppVersion = '[1.0.0, 1.0.999]'
miniDnsVersion = '[1.0.0, 1.0.999]'
smackMinAndroidSdk = 19
junitVersion = '5.6.2'
junitVersion = '5.7.1'
commonsIoVersion = '2.6'
bouncyCastleVersion = '1.65'
bouncyCastleVersion = '1.68'
guavaVersion = '30.1-jre'
mockitoVersion = '3.7.7'
orgReflectionsVersion = '0.9.11'
if (project.hasProperty("useSonatype")) {
useSonatype = project.getProperty("useSonatype").toBoolean()
@ -135,7 +158,6 @@ allprojects {
// Default to true
useSonatype = true
}
javaCompatilibity = JavaVersion.VERSION_1_8
javaMajor = javaCompatilibity.getMajorVersion()
}
group = 'org.igniterealtime.smack'
@ -218,6 +240,8 @@ allprojects {
// Disabled but should be re-enabled at some point
//'-Xep:InconsistentCapitalization:OFF',
'-Xep:MixedMutabilityReturnType:OFF',
// TODO: Re-enable once Smack's minimum Android SDK level is 26 or higher.
'-Xep:JavaUtilDate:OFF',
]
}
}
@ -230,7 +254,7 @@ allprojects {
}
jacoco {
toolVersion = "0.8.3"
toolVersion = "0.8.6"
}
jacocoTestReport {
@ -248,7 +272,10 @@ allprojects {
// since the one paramater addStringOption doesn't seem to
// work, we extra add '-quiet', which is added anyway by
// gradle.
options.addStringOption('Xdoclint:all', '-quiet')
// TODO: This enables all doclint check but
// 'missing'. Re-enable 'missing' once every public API in
// Smack has a javadoc comment.
options.addStringOption('Xdoclint:accessibility,html,reference,syntax', '-quiet')
// Treat warnings as errors.
// See also https://bugs.openjdk.java.net/browse/JDK-8200363
@ -260,12 +287,16 @@ allprojects {
tasks.withType(Javadoc) {
options.addStringOption('-release', javaMajor)
// Fix for javadoc search. If not set, the search result would direct to
// javadoc/undefined/org/jivesoftware/smack/altconnections/HttpLookupMethod.html
// instead of
// javadoc/org/jivesoftware/smack/altconnections/HttpLookupMethod.html
// https://stackoverflow.com/a/53732633/194894
options.addBooleanOption("-no-module-directories", true)
// The -no-modules-directories javadoc option was removed in Java 13
// See https://bugs.openjdk.java.net/browse/JDK-8215582
if (JavaVersion.current() < JavaVersion.VERSION_13) {
// Fix for javadoc search. If not set, the search result would direct to
// javadoc/undefined/org/jivesoftware/smack/altconnections/HttpLookupMethod.html
// instead of
// javadoc/org/jivesoftware/smack/altconnections/HttpLookupMethod.html
// https://stackoverflow.com/a/53732633/194894
options.addBooleanOption("-no-module-directories", true)
}
}
tasks.withType(JavaCompile) {
options.compilerArgs.addAll([
@ -287,13 +318,13 @@ tasks.withType(Javadoc) {
// The smack-extensions subproject uses mockito in its fest
// fixtures, and we want to have mockito also available in
// test, so we use API here.
testFixturesApi "org.mockito:mockito-core:3.3.3"
testFixturesApi "org.mockito:mockito-core:${mockitoVersion}"
// To mock final classes
testImplementation 'org.mockito:mockito-inline:3.3.3'
testImplementation "org.mockito:mockito-inline:${mockitoVersion}"
testImplementation 'com.jamesmurty.utils:java-xmlbuilder:1.2'
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
errorprone 'com.google.errorprone:error_prone_core:2.5.1'
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
}
@ -335,7 +366,7 @@ task javadocAll(type: Javadoc) {
linkSource = true
use = true
links = [
"https://docs.oracle.com/javase/${javaMajor}/docs/api/",
"https://docs.oracle.com/en/java/javase/${javaMajor}/docs/api/",
"https://jxmpp.org/releases/${staticJxmppVersion}/javadoc/",
"https://minidns.org/releases/${staticMiniDnsVersion}/javadoc/",
] as String[]
@ -369,13 +400,7 @@ task prepareReleasedocs(type: Copy) {
filter(ReplaceTokens, tokens: [version: version, releasedate: builtDate, targetCompatibility: targetCompatibility.toString()])
}
markdownToHtml {
sourceDir = new File(projectDir, "/documentation")
outputDir documentationDir
configuration = [tables: true, fencedCodeBlocks: true]
}
task distributionZip(type: Zip, dependsOn: [javadocAll, prepareReleasedocs, markdownToHtml]) {
task distributionZip(type: Zip, dependsOn: [javadocAll, prepareReleasedocs]) {
classifier builtDate
into ('javadoc') {
from(javadocAllDir)

View File

@ -28,7 +28,7 @@ Currently supported XEPs of smack-im
------------------------------------
| Name | XEP | Version | Description |
|---------------------------------------------|--------------------------------------------------------|-----------|-----------------------------------|--
|---------------------------------------------|--------------------------------------------------------|-----------|-----------------------------------|
| Roster Versioning | [XEP-0237](https://xmpp.org/extensions/xep-0237.html) | n/a | Efficient roster synchronization. |
Smack Extensions and currently supported XEPs of smack-extensions

View File

@ -15,12 +15,7 @@ cd "`dirname "${SCRIPTDIR}"`" > /dev/null
SCRIPTDIR="`pwd`";
popd > /dev/null
SMACK_DIR=$(readlink "${SCRIPTDIR}"/..)
FIND_ALL_JAVA_SRC="find ${SMACK_DIR} \
-type f \
-name *.java \
-print"
SMACK_DIR=$(realpath "${SCRIPTDIR}"/..)
declare -A SMACK_EXCEPTIONS
SMACK_EXCEPTIONS[NotConnectedException]="if the XMPP connection is not connected."
@ -71,7 +66,8 @@ SMACK_EXCEPTIONS[FailedNonzaException]="if an XMPP protocol failure was received
MODE=""
while getopts dm: OPTION "$@"; do
SMACK_DIR=$(realpath "${SCRIPTDIR}"/..)
while getopts dm:p: OPTION "$@"; do
case $OPTION in
d)
set -x
@ -79,6 +75,9 @@ while getopts dm: OPTION "$@"; do
m)
MODE=${OPTARG}
;;
p)
SMACK_DIR=${OPTARG}
;;
*)
echo "Unknown option ${OPTION}"
exit 1
@ -86,26 +85,43 @@ while getopts dm: OPTION "$@"; do
esac
done
JAVA_SOURCES_LIST=$(mktemp)
onExit() {
rm "${JAVA_SOURCES_LIST}"
}
trap onExit EXIT
find ${SMACK_DIR} \
-type f \
-name "*.java" \
-print > "${JAVA_SOURCES_LIST}"
NPROC=$(nproc)
sed_sources() {
sedScript=${1}
${FIND_ALL_JAVA_SRC} |\
xargs sed \
--in-place \
--follow-symlinks \
--regexp-extended \
"${sedScript}"
xargs \
--max-procs="${NPROC}" \
--max-args=8 \
-- \
sed \
--in-place \
--follow-symlinks \
--regexp-extended \
"${sedScript}" < "${JAVA_SOURCES_LIST}"
}
show_affected() {
echo ${!SMACK_EXCEPTIONS{@}}
for exception in ${!SMACK_EXCEPTIONS[@]}; do
${FIND_ALL_JAVA_SRC} |\
xargs grep " \* @throws $exception$" || true
xargs grep " \* @throws $exception$" < "${JAVA_SOURCES_LIST}"
done
for exception in ${!SMACK_EXCEPTIONS[@]}; do
count=$(${FIND_ALL_JAVA_SRC} |\
xargs grep " \* @throws $exception$" | wc -l)
echo "$exception $count"
local count
count=$(<"${JAVA_SOURCES_LIST}" xargs grep " \* @throws $exception$" |\
wc -l)
echo "$exception $count"q
done
}
@ -113,7 +129,7 @@ show_affected() {
fix_affected() {
for exception in "${!SMACK_EXCEPTIONS[@]}"; do
exceptionJavadoc=${SMACK_EXCEPTIONS[${exception}]}
sed_sources "s;@throws ((\w*\.)?${exception})\$;@throws \1 ${exceptionJavadoc};"
sed_sources "s;@throws ((\w*\.)?${exception}) ?\$;@throws \1 ${exceptionJavadoc};"
done
}

View File

@ -0,0 +1,18 @@
<code_scheme name="Smack" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10000" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="org.jivesoftware" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</code_scheme>

View File

@ -14,15 +14,35 @@
AbstractXMPPConnection connection = new XMPPTCPConnection("mtucker", "password", "jabber.org");
connection.connect().login();
Message message = new Message("jsmith@igniterealtime.org", "Howdy! How are you?");
Message message = connection.getStanzaFactory()
.buildMessageStanza()
.to("jsmith@igniterealtime.org")
.setBody("Howdy! How are you?")
.build();
connection.sendStanza(message);
connection.disconnect();
</pre>
<p>Smack doesn't force you to code at the protcol level of XMPP. The library provides intelligent higher level constructs, often called {@link org.jivesoftware.smack.Manager}, which let you program more efficiently. Other examples of those constructs are the Chat and Roster classes.</p>
<p>Smack comes with APIs for easy machine-to-machine communication. You can set any number of properties on each message, including properties that are Java objects.</p>
<p>Smack is open-source under the Apache License 2.0, which means you can incorporate Smack into your commercial or non-commercial applications.</p>
<h2>License</h2>
<p>Smack is open-source and most parts are under the Apache License
2.0, which means you can incorporate Smack into your commercial or
non-commercial applications. Some parts of Smack may be under a
different open-source license. Please refer to the individual
subprojects for their license statement.</p>
<p>Note that the Apache License 2.0 requires that the contents of a
NOICE text file are shown "…within a display generated by the
Derivative Works, if and wherever such third-party notices normally
appear.". Smack comes with such a NOTICE file. The content of
Smack's NOTICE file can conveniently be retrieved using
{@link org.jivesoftware.smack.Smack#getNoticeStream}.</p>
<h2>About XMPP</h2>

View File

@ -141,7 +141,44 @@ hr {
<div id="pageBody">
<h2>4.4.2 -- <span style="font-weight: normal;">2021-03-25</span></h2>
<h2> Bug
</h2>
<ul>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-903'>SMACK-903</a>] - StaxXmlPullParser.getNamespace() may throws IllegalArgumentException
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-904'>SMACK-904</a>] - XEP-0096 file transfer fails because of a hidden ClastCastException
</li>
</ul>
<h2>4.4.1 -- <span style="font-weight: normal;">2021-03-03</span></h2>
<h2> Bug
</h2>
<ul>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-895'>SMACK-895</a>] - BoBIQ#getIQChildElementBuilder throws NPE when the BoB data does not contain max-age.
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-896'>SMACK-896</a>] - BoBDataExtension is missing getter for BoBData and ContentId
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-897'>SMACK-897</a>] - DirectoryRosterStore.readEntry() should also catch IllegalArgumentException
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-898'>SMACK-898</a>] - AbstractProvider should also consider TypeVariable
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-899'>SMACK-899</a>] - NullPointerException in EntityCapsManager.addCapsExtension
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-900'>SMACK-900</a>] - NPE in DataForm.Builder.addItem()
</li>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-902'>SMACK-902</a>] - DataFormProvider should retrieve the type of fields from &lt;reported/&gt; elements if possible
</li>
</ul>
<h2> Improvement
</h2>
<ul>
<li>[<a href='https://igniterealtime.atlassian.net/browse/SMACK-901'>SMACK-901</a>] - BoBDataExtension.from() should also allow IQs
</li>
</ul>
<h2>4.4.0 -- <span style="font-weight: normal;">2020-12-06</span></h2>

View File

@ -32,6 +32,7 @@ include 'smack-core',
'smack-openpgp',
'smack-websocket',
'smack-websocket-okhttp',
'smack-websocket-java11',
'smack-xmlparser',
'smack-xmlparser-stax',
'smack-xmlparser-xpp3'

View File

@ -4,8 +4,8 @@ Extra Smack extensions for Android."""
// Note that the test dependencies (junit, ) are inferred from the
// sourceSet.test of the core subproject
dependencies {
compile project(':smack-android')
compile project(':smack-extensions')
api project(':smack-android')
api project(':smack-extensions')
// Add the Android jar to the Eclipse .classpath.
compileClasspath files(androidBootClasspath)

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2017 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.jivesoftware.smackx.ping.android;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Logger;
@ -80,6 +79,12 @@ public final class ServerPingWithAlarmManager extends Manager {
});
}
/**
* Get the instance of this manager for the given connection.
*
* @param connection the connection.
* @return the instance of this manager for the given connection.
*/
public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
if (serverPingWithAlarmManager == null) {
@ -105,6 +110,11 @@ public final class ServerPingWithAlarmManager extends Manager {
mEnabled = enabled;
}
/**
* Check if this manager is enabled.
*
* @return <code>true</code> if this manager is enabled, <code>false</code> otherwise.
*/
public boolean isEnabled() {
return mEnabled;
}
@ -113,14 +123,14 @@ public final class ServerPingWithAlarmManager extends Manager {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
Set<Map.Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
for (Map.Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "

View File

@ -14,13 +14,13 @@ dependencies {
// Android version is smaller then 21. Note that we deliberatly do
// not add this to smack-minidns, as this dependency may also be
// used in non-Android projects.
compile "org.minidns:minidns-android21:$miniDnsVersion"
implementation "org.minidns:minidns-android21:$miniDnsVersion"
// androidProjects lists all projects that are checked to compile against android.jar
// Filter out the optional Smack dependencies from androidProjects
(androidProjects - androidOptionalProjects)
.each { project ->
compile project
api project
}
// Add the Android jar to the Eclipse .classpath.

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2018 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -39,8 +39,8 @@ public class AndroidSmackInitializer implements SmackInitializer {
@Override
public List<Exception> initialize() {
SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
Base64.setEncoder(AndroidBase64Encoder.getInstance());
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
Base64.setEncoder(AndroidBase64Encoder.INSTANCE);
Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.INSTANCE);
return null;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,7 +24,10 @@ import android.util.Base64;
*/
public final class AndroidBase64Encoder implements org.jivesoftware.smack.util.stringencoder.Base64.Encoder {
private static AndroidBase64Encoder instance = new AndroidBase64Encoder();
/**
* An instance of this encoder.
*/
public static AndroidBase64Encoder INSTANCE = new AndroidBase64Encoder();
private static final int BASE64_ENCODER_FLAGS = Base64.NO_WRAP;
@ -32,10 +35,6 @@ public final class AndroidBase64Encoder implements org.jivesoftware.smack.util.s
// Use getInstance()
}
public static AndroidBase64Encoder getInstance() {
return instance;
}
@Override
public byte[] decode(String string) {
return Base64.decode(string, Base64.DEFAULT);

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,9 +22,16 @@ import org.jivesoftware.smack.util.stringencoder.StringEncoder;
import android.util.Base64;
/**
* An URL-safe Base64 encoder.
* @author Florian Schmaus
*/
public final class AndroidBase64UrlSafeEncoder implements StringEncoder<String> {
private static AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();
/**
* An instance of this encoder.
*/
public static AndroidBase64UrlSafeEncoder INSTANCE = new AndroidBase64UrlSafeEncoder();
private static final int BASE64_ENCODER_FLAGS = Base64.URL_SAFE | Base64.NO_WRAP;
@ -32,10 +39,6 @@ public final class AndroidBase64UrlSafeEncoder implements StringEncoder<String>
// Use getInstance()
}
public static AndroidBase64UrlSafeEncoder getInstance() {
return instance;
}
@Override
public String encode(String string) {
return Base64.encodeToString(string.getBytes(StandardCharsets.UTF_8), BASE64_ENCODER_FLAGS);

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2017 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,11 @@ import android.util.Log;
*/
public class AndroidDebugger extends AbstractDebugger {
/**
* Constructs a new Smack debugger for Android.
*
* @param connection the connection to debug.
*/
public AndroidDebugger(XMPPConnection connection) {
super(connection);
}

View File

@ -3,8 +3,8 @@ Smack BOSH API.
This API is considered beta quality."""
dependencies {
compile project(':smack-core')
api project(':smack-core')
// See https://issues.igniterealtime.org/browse/SMACK-858 and
// comment in version.gradle why the specify the version this way.
compile 'org.igniterealtime.jbosh:jbosh:[0.9.1,0.9.999]'
implementation 'org.igniterealtime.jbosh:jbosh:[0.9.1,0.9.999]'
}

View File

@ -6,10 +6,10 @@ ext {
}
dependencies {
compile project(':smack-xmlparser')
compile "org.jxmpp:jxmpp-core:$jxmppVersion"
compile "org.jxmpp:jxmpp-jid:$jxmppVersion"
compile "org.minidns:minidns-core:$miniDnsVersion"
api project(':smack-xmlparser')
api "org.jxmpp:jxmpp-core:$jxmppVersion"
api "org.jxmpp:jxmpp-jid:$jxmppVersion"
api "org.minidns:minidns-core:$miniDnsVersion"
testFixturesImplementation project(':smack-xmlparser-stax')
testFixturesImplementation project(':smack-xmlparser-xpp3')
@ -33,7 +33,7 @@ dependencies {
testFixturesApi "org.assertj:assertj-core:3.11.1"
testFixturesApi "org.xmlunit:xmlunit-assertj:$xmlUnitVersion"
testFixturesApi 'org.hamcrest:hamcrest-library:2.2'
testFixturesApi 'com.google.guava:guava:28.2-jre'
testFixturesApi "com.google.guava:guava:${guavaVersion}"
}
class CreateFileTask extends DefaultTask {

View File

@ -74,7 +74,6 @@ import org.jivesoftware.smack.packet.AbstractStreamOpen;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Message;
@ -92,6 +91,7 @@ import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.packet.id.StanzaIdSource;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
@ -239,7 +239,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected final Lock connectionLock = new ReentrantLock();
protected final Map<QName, FullyQualifiedElement> streamFeatures = new HashMap<>();
protected final Map<QName, XmlElement> streamFeatures = new HashMap<>();
/**
* The full JID of the authenticated user, as returned by the resource binding response of the server.
@ -377,6 +377,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
private final Map<QName, IQRequestHandler> setIqRequestHandler = new HashMap<>();
private final Map<QName, IQRequestHandler> getIqRequestHandler = new HashMap<>();
private final Set<String> iqRequestHandlerNamespaces = new CopyOnWriteArraySet<>();
private final Map<String, Integer> iqRequestHandlerNamespacesReferenceCounters = new HashMap<>();
private final StanzaFactory stanzaFactory;
@ -1407,6 +1409,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return successNonza;
}
private void maybeNotifyDebuggerAboutIncoming(TopLevelStreamElement incomingTopLevelStreamElement) {
final SmackDebugger debugger = this.debugger;
if (debugger != null) {
debugger.onIncomingStreamElement(incomingTopLevelStreamElement);
}
}
protected final void parseAndProcessNonza(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
ParserUtils.assertAtStartTag(parser);
@ -1435,6 +1444,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
Nonza nonza = nonzaProvider.parse(parser, incomingStreamXmlEnvironment);
maybeNotifyDebuggerAboutIncoming(nonza);
for (NonzaCallback nonzaCallback : nonzaCallbacks) {
nonzaCallback.onNonzaReceived(nonza);
}
@ -1474,10 +1485,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected void processStanza(final Stanza stanza) throws InterruptedException {
assert stanza != null;
final SmackDebugger debugger = this.debugger;
if (debugger != null) {
debugger.onIncomingStreamElement(stanza);
}
maybeNotifyDebuggerAboutIncoming(stanza);
lastStanzaReceived = System.currentTimeMillis();
// Deliver the incoming packet to listeners.
@ -1518,15 +1526,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
}
if (iqRequestHandler == null) {
final String iqNamespace = key.getNamespaceURI();
StanzaError.Condition replyCondition;
switch (unknownIqRequestReplyMode) {
case doNotReply:
return;
case replyFeatureNotImplemented:
replyCondition = StanzaError.Condition.feature_not_implemented;
break;
case replyServiceUnavailable:
replyCondition = StanzaError.Condition.service_unavailable;
case reply:
boolean isKnownNamespace = iqRequestHandlerNamespaces.contains(iqNamespace);
if (isKnownNamespace) {
replyCondition = StanzaError.Condition.feature_not_implemented;
} else {
replyCondition = StanzaError.Condition.service_unavailable;
}
break;
default:
throw new AssertionError();
@ -1848,7 +1859,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getDepth() == initialDepth + 1) {
FullyQualifiedElement streamFeature = null;
XmlElement streamFeature = null;
String name = parser.getName();
String namespace = parser.getNamespace();
switch (name) {
@ -1917,7 +1928,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@SuppressWarnings("unchecked")
@Override
public <F extends FullyQualifiedElement> F getFeature(QName qname) {
public <F extends XmlElement> F getFeature(QName qname) {
return (F) streamFeatures.get(qname);
}
@ -1926,7 +1937,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return streamFeatures.containsKey(qname);
}
protected void addStreamFeature(FullyQualifiedElement feature) {
protected void addStreamFeature(XmlElement feature) {
QName key = feature.getQName();
streamFeatures.put(key, feature);
}
@ -2037,18 +2048,35 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public IQRequestHandler registerIQRequestHandler(final IQRequestHandler iqRequestHandler) {
final QName key = iqRequestHandler.getQName();
IQRequestHandler previous;
switch (iqRequestHandler.getType()) {
case set:
synchronized (setIqRequestHandler) {
return setIqRequestHandler.put(key, iqRequestHandler);
previous = setIqRequestHandler.put(key, iqRequestHandler);
}
break;
case get:
synchronized (getIqRequestHandler) {
return getIqRequestHandler.put(key, iqRequestHandler);
previous = getIqRequestHandler.put(key, iqRequestHandler);
}
break;
default:
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
final String iqNamespace = key.getNamespaceURI();
synchronized (iqRequestHandlerNamespacesReferenceCounters) {
Integer newValue;
Integer counter = iqRequestHandlerNamespacesReferenceCounters.get(iqNamespace);
if (counter == null) {
iqRequestHandlerNamespaces.add(iqNamespace);
newValue = 0;
} else {
newValue = counter.intValue() + 1;
}
iqRequestHandlerNamespacesReferenceCounters.put(iqNamespace, newValue);
}
return previous;
}
@Override
@ -2059,19 +2087,38 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public IQRequestHandler unregisterIQRequestHandler(String element, String namespace, IQ.Type type) {
IQRequestHandler unregisteredHandler;
final QName key = new QName(namespace, element);
switch (type) {
case set:
synchronized (setIqRequestHandler) {
return setIqRequestHandler.remove(key);
unregisteredHandler = setIqRequestHandler.remove(key);
}
break;
case get:
synchronized (getIqRequestHandler) {
return getIqRequestHandler.remove(key);
unregisteredHandler = getIqRequestHandler.remove(key);
}
break;
default:
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
}
if (unregisteredHandler == null) {
return null;
}
synchronized (iqRequestHandlerNamespacesReferenceCounters) {
int newValue = iqRequestHandlerNamespacesReferenceCounters.get(namespace).intValue() - 1;
if (newValue == 0) {
iqRequestHandlerNamespacesReferenceCounters.remove(namespace);
iqRequestHandlerNamespaces.remove(namespace);
} else {
iqRequestHandlerNamespacesReferenceCounters.put(namespace, newValue);
}
}
return unregisteredHandler;
}
private long lastStanzaReceived;
@ -2214,7 +2261,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @return a String representing the corresponding stream end tag.
*/
protected String onStreamOpen(XmlPullParser parser) {
assert StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE.equals(parser.getNamespace());
assert StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE.equals(parser.getNamespace()) : parser.getNamespace()
+ " is not " + StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE;
assert StreamOpen.UNPREFIXED_ELEMENT.equals(parser.getName());
streamId = parser.getAttributeValue("id");

View File

@ -42,6 +42,7 @@ import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism;
import org.jivesoftware.smack.sasl.packet.SaslNonza;
import org.jivesoftware.smack.sasl.packet.SaslNonza.SASLFailure;
import org.jivesoftware.smack.sasl.packet.SaslNonza.Success;
import org.jivesoftware.smack.util.StringUtils;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
@ -184,7 +185,7 @@ public final class SASLAuthentication {
SASLMechanism authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession)
throws XMPPErrorException, SASLErrorException, IOException,
InterruptedException, SmackSaslException, NotConnectedException, NoResponseException {
final SASLMechanism mechanism = selectMechanism(authzid);
final SASLMechanism mechanism = selectMechanism(authzid, password);
final CallbackHandler callbackHandler = configuration.getCallbackHandler();
final String host = connection.getHost();
final DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();
@ -249,7 +250,6 @@ public final class SASLAuthentication {
* Notification message saying that SASL authentication was successful. The next step
* would be to bind the resource.
* @param success result of the authentication.
* @throws SmackException if Smack detected an exceptional situation.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws SmackSaslException if a SASL specific error occurred.
@ -312,34 +312,48 @@ public final class SASLAuthentication {
return lastUsedMech.getName();
}
private SASLMechanism selectMechanism(EntityBareJid authzid) throws SmackException.SmackSaslException {
private SASLMechanism selectMechanism(EntityBareJid authzid, String password) throws SmackException.SmackSaslException {
final boolean passwordAvailable = StringUtils.isNotEmpty(password);
Iterator<SASLMechanism> it = REGISTERED_MECHANISMS.iterator();
final List<String> serverMechanisms = getServerMechanisms();
if (serverMechanisms.isEmpty()) {
LOGGER.warning("Server did not report any SASL mechanisms");
}
List<String> skipReasons = new ArrayList<>();
// Iterate in SASL Priority order over registered mechanisms
while (it.hasNext()) {
SASLMechanism mechanism = it.next();
String mechanismName = mechanism.getName();
if (!serverMechanisms.contains(mechanismName)) {
continue;
}
synchronized (BLACKLISTED_MECHANISMS) {
if (BLACKLISTED_MECHANISMS.contains(mechanismName)) {
continue;
}
}
if (!configuration.isEnabledSaslMechanism(mechanismName)) {
continue;
}
if (authzid != null) {
if (!mechanism.authzidSupported()) {
LOGGER.fine("Skipping " + mechanism + " because authzid is required by not supported by this SASL mechanism");
continue;
}
if (authzid != null && !mechanism.authzidSupported()) {
skipReasons.add("Skipping " + mechanism + " because authzid is required by not supported by this SASL mechanism");
continue;
}
if (serverMechanisms.contains(mechanismName)) {
// Create a new instance of the SASLMechanism for every authentication attempt.
return mechanism.instanceForAuthentication(connection, configuration);
if (mechanism.requiresPassword() && !passwordAvailable) {
skipReasons.add("Skipping " + mechanism + " because a password is required for it, but none was provided to the connection configuration");
continue;
}
// Create a new instance of the SASLMechanism for every authentication attempt.
return mechanism.instanceForAuthentication(connection, configuration);
}
synchronized (BLACKLISTED_MECHANISMS) {
@ -349,7 +363,8 @@ public final class SASLAuthentication {
"Server announced mechanisms: " + serverMechanisms + ". " +
"Registered SASL mechanisms with Smack: " + REGISTERED_MECHANISMS + ". " +
"Enabled SASL mechanisms for this connection: " + configuration.getEnabledSaslMechanisms() + ". " +
"Blacklisted SASL mechanisms: " + BLACKLISTED_MECHANISMS + '.'
"Blacklisted SASL mechanisms: " + BLACKLISTED_MECHANISMS + ". " +
"Skip reasons: " + skipReasons
);
// @formatter;on
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,8 @@ package org.jivesoftware.smack;
import java.io.InputStream;
import java.util.logging.Logger;
import org.jivesoftware.smack.util.FileUtils;
public class Smack {
private static final Logger LOGGER = Logger.getLogger(Smack.class.getName());
@ -38,8 +40,20 @@ public class Smack {
private static final String NOTICE_RESOURCE = SMACK_PACKAGE + "/NOTICE";
/**
* Get the stream of the NOTICE file of Smack.
* <p>
* This license of Smack requires that the contents of this NOTICE text file are shown "…within a display generated by
* the Derivative Works, if and wherever such third-party notices normally appear.".
* </p>
*
* @return the stream of the NOTICE file of Smack.
* @since 4.4.0
*/
public static InputStream getNoticeStream() {
return ClassLoader.getSystemResourceAsStream(NOTICE_RESOURCE);
InputStream res = FileUtils.getInputStreamForClasspathFile(NOTICE_RESOURCE);
assert res != null;
return res;
}
public static void ensureInitialized() {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2018-2020 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2018-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -343,11 +343,10 @@ public final class SmackConfiguration {
public enum UnknownIqRequestReplyMode {
doNotReply,
replyFeatureNotImplemented,
replyServiceUnavailable,
reply,
}
private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyFeatureNotImplemented;
private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.reply;
public static UnknownIqRequestReplyMode getUnknownIqRequestReplyMode() {
return unknownIqRequestReplyMode;

View File

@ -343,7 +343,7 @@ public final class StanzaCollector implements AutoCloseable {
*
* @param packet the stanza to process.
*/
protected void processStanza(Stanza packet) {
void processStanza(Stanza packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
synchronized (this) {
if (resultQueue.size() == maxQueueSize) {

View File

@ -27,7 +27,6 @@ import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
@ -36,6 +35,7 @@ import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.PresenceBuilder;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaFactory;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.Consumer;
import org.jivesoftware.smack.util.Predicate;
import org.jivesoftware.smack.util.XmppElementUtil;
@ -583,7 +583,7 @@ public interface XMPPConnection {
*/
// TODO: Remove in Smack 4.5.
@Deprecated
default <F extends FullyQualifiedElement> F getFeature(String element, String namespace) {
default <F extends XmlElement> F getFeature(String element, String namespace) {
QName qname = new QName(namespace, element);
return getFeature(qname);
}
@ -597,7 +597,7 @@ public interface XMPPConnection {
* @return a stanza extensions of the feature or <code>null</code>
* @since 4.4
*/
<F extends FullyQualifiedElement> F getFeature(QName qname);
<F extends XmlElement> F getFeature(QName qname);
/**
* Get the feature stanza extensions for a given stream feature of the
@ -608,7 +608,7 @@ public interface XMPPConnection {
* @return a stanza extensions of the feature or <code>null</code>
* @since 4.4
*/
default <F extends FullyQualifiedElement> F getFeature(Class<F> featureClass) {
default <F extends XmlElement> F getFeature(Class<F> featureClass) {
QName qname = XmppElementUtil.getQNameFor(featureClass);
return getFeature(qname);
}

View File

@ -99,7 +99,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
private boolean featuresReceived;
protected boolean streamResumed;
private boolean streamResumed;
private GraphVertex<State> currentStateVertex;
@ -264,7 +264,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
walkStateGraph(walkStateGraphContext);
}
protected WalkStateGraphContext.Builder buildNewWalkTo(Class<? extends StateDescriptor> finalStateClass) {
private WalkStateGraphContext.Builder buildNewWalkTo(Class<? extends StateDescriptor> finalStateClass) {
return WalkStateGraphContext.builder(currentStateVertex.getElement().getStateDescriptor().getClass(), finalStateClass);
}
@ -279,7 +279,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
revertedState.resetState();
}
protected void walkStateGraph(WalkStateGraphContext walkStateGraphContext)
private void walkStateGraph(WalkStateGraphContext walkStateGraphContext)
throws XMPPException, IOException, SmackException, InterruptedException {
// Save a copy of the current state
GraphVertex<State> previousStateVertex = currentStateVertex;
@ -491,7 +491,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
}
}
protected SSLSession getSSLSession() {
private SSLSession getSSLSession() {
final XmppClientToServerTransport transport = activeTransport;
if (transport == null) {
return null;
@ -505,7 +505,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
notifyWaitingThreads();
}
protected void parseAndProcessElement(String element) {
private void parseAndProcessElement(String element) {
try {
XmlPullParser parser = PacketParserUtils.getParserFor(element);
@ -556,11 +556,11 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
}
}
protected synchronized void prepareToWaitForFeaturesReceived() {
private synchronized void prepareToWaitForFeaturesReceived() {
featuresReceived = false;
}
protected void waitForFeaturesReceived(String waitFor)
private void waitForFeaturesReceived(String waitFor)
throws InterruptedException, SmackException, XMPPException {
waitForConditionOrThrowConnectionException(() -> featuresReceived, waitFor);
}
@ -571,7 +571,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
return streamOpenAndCloseFactory.createStreamOpen(to, from, id, lang);
}
protected void newStreamOpenWaitForFeaturesSequence(String waitFor) throws InterruptedException,
private void newStreamOpenWaitForFeaturesSequence(String waitFor) throws InterruptedException,
SmackException, XMPPException {
prepareToWaitForFeaturesReceived();
@ -1028,7 +1028,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
return connectionStateMachineListeners.remove(connectionStateMachineListener);
}
protected void invokeConnectionStateMachineListener(ConnectionStateEvent connectionStateEvent) {
private void invokeConnectionStateMachineListener(ConnectionStateEvent connectionStateEvent) {
if (connectionStateMachineListeners.isEmpty()) {
return;
}
@ -1056,7 +1056,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne
walkStateGraph(walkStateGraphContext);
}
protected Map<String, Object> getFilterStats() {
private Map<String, Object> getFilterStats() {
Collection<XmppInputOutputFilter> filters;
synchronized (this) {
if (inputOutputFilters.isEmpty() && previousInputOutputFilters != null) {

View File

@ -54,8 +54,6 @@ public abstract class XmppClientToServerTransport {
public abstract SSLSession getSslSession();
public abstract boolean isConnected();
public boolean isTransportSecured() {
return getSslSession() != null;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,11 +44,20 @@ public abstract class AbstractListFilter implements StanzaFilter {
* @param filters the filters to add.
*/
protected AbstractListFilter(StanzaFilter... filters) {
this(new ArrayList<StanzaFilter>(Arrays.asList(filters)));
}
/**
* Creates an filter using the specified filters.
*
* @param filters the filters to add.
*/
protected AbstractListFilter(List<StanzaFilter> filters) {
Objects.requireNonNull(filters, "Parameter must not be null.");
for (StanzaFilter filter : filters) {
Objects.requireNonNull(filter, "Parameter must not be null.");
}
this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters));
this.filters = filters;
}
/**

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software.
* Copyright 2003-2007 Jive Software, 2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.jivesoftware.smack.filter;
import java.util.List;
import org.jivesoftware.smack.packet.Stanza;
/**
@ -44,6 +46,15 @@ public class AndFilter extends AbstractListFilter implements StanzaFilter {
super(filters);
}
/**
* Creates an AND filter using the specified filters.
*
* @param filters the filters to add.
*/
public AndFilter(List<StanzaFilter> filters) {
super(filters);
}
@Override
public boolean accept(Stanza packet) {
for (StanzaFilter filter : filters) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmppElementUtil;
public class ExtensionElementFilter<E extends ExtensionElement> implements StanzaFilter {
@ -34,7 +35,7 @@ public class ExtensionElementFilter<E extends ExtensionElement> implements Stanz
@Override
public final boolean accept(Stanza stanza) {
ExtensionElement extensionElement = stanza.getExtension(extensionElementQName);
XmlElement extensionElement = stanza.getExtension(extensionElementQName);
if (extensionElement == null) {
return false;
}

View File

@ -27,6 +27,7 @@ import org.jivesoftware.smack.util.Objects;
* @author Alexander Wenckus
*
*/
@SuppressWarnings("BadImport")
public final class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
public static final StanzaFilter GET = new IQTypeFilter(Type.get);

View File

@ -27,6 +27,7 @@ import org.jivesoftware.smack.packet.Message.Type;
* @see org.jivesoftware.smack.packet.Message.Type
* @author Ward Harold
*/
@SuppressWarnings("BadImport")
public final class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {
public static final StanzaFilter NORMAL = new MessageTypeFilter(Type.normal);

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Florian Schmaus
* Copyright 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import org.jivesoftware.smack.util.Objects;
* A filter for Presence types. Returns true only if the stanza is an Presence stanza and it matches the type provided in the
* constructor.
*/
@SuppressWarnings("BadImport")
public final class PresenceTypeFilter extends FlexibleStanzaTypeFilter<Presence> {
public static final PresenceTypeFilter AVAILABLE = new PresenceTypeFilter(Type.available);

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.jivesoftware.smack.iqrequest;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
/**
* Convenience class to create IQ requests handlers.
@ -26,10 +25,10 @@ public abstract class AbstractIqRequestHandler implements IQRequestHandler {
private final String element;
private final String namespace;
private final Type type;
private final IQ.Type type;
private final Mode mode;
protected AbstractIqRequestHandler(String element, String namespace, Type type, Mode mode) {
protected AbstractIqRequestHandler(String element, String namespace, IQ.Type type, Mode mode) {
switch (type) {
case set:
case get:
@ -52,7 +51,7 @@ public abstract class AbstractIqRequestHandler implements IQRequestHandler {
}
@Override
public Type getType() {
public IQ.Type getType() {
return type;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2014-2015 Florian Schmaus
* Copyright 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,18 +32,18 @@ public class AbstractError {
protected final String textNamespace;
protected final Map<String, String> descriptiveTexts;
protected final List<ExtensionElement> extensions;
protected final List<XmlElement> extensions;
protected AbstractError(Map<String, String> descriptiveTexts) {
this(descriptiveTexts, null);
}
protected AbstractError(Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, List<XmlElement> extensions) {
this(descriptiveTexts, null, extensions);
}
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<ExtensionElement> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<XmlElement> extensions) {
if (descriptiveTexts != null) {
this.descriptiveTexts = descriptiveTexts;
} else {
@ -108,7 +108,7 @@ public class AbstractError {
* @param <PE> type of the ExtensionElement.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
public <PE extends XmlElement> PE getExtension(String elementName, String namespace) {
return PacketUtil.extensionElementFrom(extensions, elementName, namespace);
}
@ -128,7 +128,7 @@ public class AbstractError {
public abstract static class Builder<B extends Builder<B>> {
protected String textNamespace;
protected Map<String, String> descriptiveTexts;
protected List<ExtensionElement> extensions;
protected List<XmlElement> extensions;
public B setDescriptiveTexts(Map<String, String> descriptiveTexts) {
if (descriptiveTexts == null) {
@ -173,7 +173,7 @@ public class AbstractError {
return getThis();
}
public B setExtensions(List<ExtensionElement> extensions) {
public B setExtensions(List<XmlElement> extensions) {
if (this.extensions == null) {
this.extensions = extensions;
}
@ -183,7 +183,7 @@ public class AbstractError {
return getThis();
}
public B addExtension(ExtensionElement extension) {
public B addExtension(XmlElement extension) {
if (extensions == null) {
extensions = new ArrayList<>();
}

View File

@ -40,10 +40,12 @@ public abstract class AbstractIqBuilder<IB extends AbstractIqBuilder<IB>> extend
super(stanzaId);
}
// TODO: Deprecate and use corresponding method in IqData instead.
public static IqData createResponse(IqView request) {
return createResponse(request, IQ.ResponseType.result);
}
// TODO: Deprecate and use corresponding method in IqData instead.
public static IqData createErrorResponse(IqView request) {
return createResponse(request, IQ.ResponseType.error);
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2015-2016 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2015-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.jivesoftware.smack.packet;
import javax.xml.namespace.QName;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.parts.Resourcepart;
@ -73,6 +75,7 @@ public final class Bind extends IQ {
public static final class Feature implements ExtensionElement {
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
public static final Feature INSTANCE = new Feature();
private Feature() {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2018 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2018-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,21 +17,16 @@
package org.jivesoftware.smack.packet;
/**
* Interface to represent extension elements.
* Interface to represent XMPP extension elements. Unlike {@link XmlElement}, every non-abstract class that implements
* {@link ExtensionElement} must have a static final QNAME member of the type {@link javax.xml.namespace.QName}. This
* allows type-safe functions like {@link StanzaView#getExtension(Class)}. Hence this is a marker interface.
* <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of
* extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements.
* <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* Use this class when implementing new extension elements when possible. This means that every instance of your
* implemented class must represent an XML element of the same qualified name.
* </p>
*
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker
* @see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>
*/
public interface ExtensionElement extends FullyQualifiedElement {
public interface ExtensionElement extends XmlElement {
}

View File

@ -211,7 +211,7 @@ public abstract class IQ extends Stanza implements IqView {
xml.append(iqChildElement);
List<ExtensionElement> extensionsXml = getExtensions();
List<XmlElement> extensionsXml = getExtensions();
if (iqChildElement.isEmptyElement) {
if (extensionsXml.isEmpty()) {
xml.closeEmptyElement();

View File

@ -46,4 +46,12 @@ public final class IqData extends AbstractIqBuilder<IqData> {
public Stanza build() {
throw new UnsupportedOperationException();
}
public static IqData createResponseData(IqView request) {
return createResponse(request, IQ.ResponseType.result);
}
public static IqData createErrorResponseDAta(IqView request) {
return createResponse(request, IQ.ResponseType.error);
}
}

View File

@ -344,7 +344,7 @@ public final class Message extends MessageOrPresence<MessageBuilder>
@Deprecated
// TODO: Remove when stanza builder is ready.
public boolean removeBody(Body body) {
ExtensionElement removedElement = removeExtension(body);
XmlElement removedElement = removeExtension(body);
return removedElement != null;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2019-2020 Florian Schmaus
* Copyright 2003-2007 Jive Software, 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -150,9 +150,9 @@ public interface MessageView extends StanzaView {
* @since 3.0.2
*/
default Set<Message.Body> getBodies() {
List<ExtensionElement> bodiesList = getExtensions(Message.Body.QNAME);
List<XmlElement> bodiesList = getExtensions(Message.Body.QNAME);
Set<Message.Body> resultSet = new HashSet<>(bodiesList.size());
for (ExtensionElement extensionElement : bodiesList) {
for (XmlElement extensionElement : bodiesList) {
Message.Body body = (Message.Body) extensionElement;
resultSet.add(body);
}

View File

@ -23,7 +23,7 @@ package org.jivesoftware.smack.packet;
* <p>
* Please note that usage of this interface is <b>discouraged</b>. The reason is that every XML element is fully
* qualified, i.e., it is qualified by a namespace. The namespace may not be explicitly given, but instead, is inherited
* from an outer element. Use {@link FullyQualifiedElement} instead when possible.
* from an outer element. Use {@link XmlElement} instead when possible.
* </p>
*/
public interface NamedElement extends Element {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2020 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2020-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -319,7 +319,7 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
buf.attribute("type", type);
}
List<ExtensionElement> extensions = getExtensions();
List<XmlElement> extensions = getExtensions();
if (status == null
&& priority == null
&& (mode == null || mode == Mode.available)

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2020 Florian Schmaus.
* Copyright 2015-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* @since 4.2
* @author Florian Schmaus
*/
public final class StandardExtensionElement implements ExtensionElement {
public final class StandardExtensionElement implements XmlElement {
private final String name;
private final String namespace;

View File

@ -64,7 +64,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
protected static final String DEFAULT_LANGUAGE =
java.util.Locale.getDefault().getLanguage().toLowerCase(Locale.US);
private final MultiMap<QName, ExtensionElement> extensionElements;
private final MultiMap<QName, XmlElement> extensionElements;
// Assume that all stanzas Smack handles are in the client namespace, since Smack is an XMPP client library. We can
// change this behavior later if it is required.
@ -284,18 +284,18 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final List<ExtensionElement> getExtensions() {
public final List<XmlElement> getExtensions() {
synchronized (extensionElements) {
// No need to create a new list, values() will already create a new one for us
return extensionElements.values();
}
}
public final MultiMap<QName, ExtensionElement> getExtensionsMap() {
public final MultiMap<QName, XmlElement> getExtensionsMap() {
return cloneExtensionsMap();
}
final MultiMap<QName, ExtensionElement> cloneExtensionsMap() {
final MultiMap<QName, XmlElement> cloneExtensionsMap() {
synchronized (extensionElements) {
return extensionElements.clone();
}
@ -312,7 +312,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @return a set of all matching extensions.
* @since 4.1
*/
public final List<ExtensionElement> getExtensions(String elementName, String namespace) {
public final List<XmlElement> getExtensions(String elementName, String namespace) {
requireNotNullNorEmpty(elementName, "elementName must not be null nor empty");
requireNotNullNorEmpty(namespace, "namespace must not be null nor empty");
QName key = new QName(namespace, elementName);
@ -320,8 +320,8 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final List<ExtensionElement> getExtensions(QName qname) {
List<ExtensionElement> res;
public final List<XmlElement> getExtensions(QName qname) {
List<XmlElement> res;
synchronized (extensionElements) {
res = extensionElements.getAll(qname);
}
@ -344,7 +344,8 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param namespace the namespace of the extension that is desired.
* @return the stanza extension with the given namespace.
*/
public final ExtensionElement getExtension(String namespace) {
// TODO: Mark this method as deprecated in favor of getExtension(QName).
public final XmlElement getExtension(String namespace) {
return PacketUtil.extensionElementFrom(getExtensions(), null, namespace);
}
@ -361,12 +362,12 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param namespace the XML element namespace of the extension.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
public final ExtensionElement getExtensionElement(String elementName, String namespace) {
public final XmlElement getExtensionElement(String elementName, String namespace) {
if (namespace == null) {
return null;
}
QName key = new QName(namespace, elementName);
ExtensionElement packetExtension = getExtension(key);
XmlElement packetExtension = getExtension(key);
if (packetExtension == null) {
return null;
}
@ -390,7 +391,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final ExtensionElement getExtension(QName qname) {
public final XmlElement getExtension(QName qname) {
synchronized (extensionElements) {
return extensionElements.getFirst(qname);
}
@ -400,13 +401,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* Adds a stanza extension to the packet. Does nothing if extension is null.
* <p>
* Please note that although this method is not yet marked as deprecated, it is recommended to use
* {@link StanzaBuilder#addExtension(ExtensionElement)} instead.
* {@link StanzaBuilder#addExtension(XmlElement)} instead.
* </p>
*
* @param extension a stanza extension.
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final void addExtension(ExtensionElement extension) {
public final void addExtension(XmlElement extension) {
if (extension == null) return;
QName key = extension.getQName();
synchronized (extensionElements) {
@ -419,7 +420,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* namespace.
* <p>
* Please note that although this method is not yet marked as deprecated, it is recommended to use
* {@link StanzaBuilder#overrideExtension(ExtensionElement)} instead.
* {@link StanzaBuilder#overrideExtension(XmlElement)} instead.
* </p>
*
* @param extension the extension element to add.
@ -427,13 +428,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @since 4.1.2
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final ExtensionElement overrideExtension(ExtensionElement extension) {
public final XmlElement overrideExtension(XmlElement extension) {
if (extension == null) return null;
synchronized (extensionElements) {
// Note that we need to use removeExtension(String, String) here. If would use
// removeExtension(ExtensionElement) then we would remove based on the equality of ExtensionElement, which
// is not what we want in this case.
ExtensionElement removedExtension = removeExtension(extension.getElementName(), extension.getNamespace());
XmlElement removedExtension = removeExtension(extension.getElementName(), extension.getNamespace());
addExtension(extension);
return removedExtension;
}
@ -445,9 +446,9 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param extensions a collection of stanza extensions
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final void addExtensions(Collection<? extends ExtensionElement> extensions) {
public final void addExtensions(Collection<? extends XmlElement> extensions) {
if (extensions == null) return;
for (ExtensionElement packetExtension : extensions) {
for (XmlElement packetExtension : extensions) {
addExtension(packetExtension);
}
}
@ -476,7 +477,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
@Override
public final boolean hasExtension(String namespace) {
synchronized (extensionElements) {
for (ExtensionElement packetExtension : extensionElements.values()) {
for (XmlElement packetExtension : extensionElements.values()) {
if (packetExtension.getNamespace().equals(namespace)) {
return true;
}
@ -493,7 +494,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @return the removed stanza extension or null.
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final ExtensionElement removeExtension(String elementName, String namespace) {
public final XmlElement removeExtension(String elementName, String namespace) {
QName key = new QName(namespace, elementName);
synchronized (extensionElements) {
return extensionElements.remove(key);
@ -509,10 +510,10 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
*/
@Deprecated
// TODO: Remove in Smack 4.5.
public final ExtensionElement removeExtension(ExtensionElement extension) {
public final XmlElement removeExtension(XmlElement extension) {
QName key = extension.getQName();
synchronized (extensionElements) {
List<ExtensionElement> list = extensionElements.getAll(key);
List<XmlElement> list = extensionElements.getAll(key);
boolean removed = list.remove(extension);
if (removed) {
return extension;

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
String language;
MultiMap<QName, ExtensionElement> extensionElements = new MultiMap<>();
MultiMap<QName, XmlElement> extensionElements = new MultiMap<>();
protected StanzaBuilder(StanzaBuilder<?> other) {
stanzaIdSource = other.stanzaIdSource;
@ -156,13 +156,13 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
return getThis();
}
public final B addExtension(ExtensionElement extensionElement) {
public final B addExtension(XmlElement extensionElement) {
QName key = extensionElement.getQName();
extensionElements.put(key, extensionElement);
return getThis();
}
public final B addOptExtensions(Collection<? extends ExtensionElement> extensionElements) {
public final B addOptExtensions(Collection<? extends XmlElement> extensionElements) {
if (extensionElements == null) {
return getThis();
}
@ -170,14 +170,14 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
return addExtensions(extensionElements);
}
public final B addExtensions(Collection<? extends ExtensionElement> extensionElements) {
for (ExtensionElement extensionElement : extensionElements) {
public final B addExtensions(Collection<? extends XmlElement> extensionElements) {
for (XmlElement extensionElement : extensionElements) {
addExtension(extensionElement);
}
return getThis();
}
public final B overrideExtension(ExtensionElement extensionElement) {
public final B overrideExtension(XmlElement extensionElement) {
QName key = extensionElement.getQName();
extensionElements.remove(key);
extensionElements.put(key, extensionElement);
@ -214,17 +214,17 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
}
@Override
public final ExtensionElement getExtension(QName qname) {
public final XmlElement getExtension(QName qname) {
return extensionElements.getFirst(qname);
}
@Override
public final List<ExtensionElement> getExtensions() {
public final List<XmlElement> getExtensions() {
return extensionElements.values();
}
@Override
public final List<ExtensionElement> getExtensions(QName qname) {
public final List<XmlElement> getExtensions(QName qname) {
return extensionElements.getAll(qname);
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2015-2019 Florian Schmaus
* Copyright 2003-2007 Jive Software, 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,6 +22,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -74,6 +76,8 @@ public class StanzaError extends AbstractError implements ExtensionElement {
public static final String ERROR = "error";
public static final QName QNAME = new QName(StreamOpen.CLIENT_NAMESPACE, ERROR);
private static final Logger LOGGER = Logger.getLogger(StanzaError.class.getName());
static final Map<Condition, Type> CONDITION_TO_TYPE = new HashMap<Condition, Type>();
@ -121,7 +125,7 @@ public class StanzaError extends AbstractError implements ExtensionElement {
* @param extensions list of stanza extensions
*/
public StanzaError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<ExtensionElement> extensions) {
List<XmlElement> extensions) {
super(descriptiveTexts, ERROR_CONDITION_AND_TEXT_NAMESPACE, extensions);
this.condition = Objects.requireNonNull(condition, "condition must not be null");
// Some implementations may send the condition as non-empty element containing the empty string, that is
@ -199,12 +203,12 @@ public class StanzaError extends AbstractError implements ExtensionElement {
@Override
public String getElementName() {
return ERROR;
return QNAME.getLocalPart();
}
@Override
public String getNamespace() {
return StreamOpen.CLIENT_NAMESPACE;
return QNAME.getNamespaceURI();
}
@Override

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public interface StanzaView extends XmlLangElement {
*/
StanzaError getError();
ExtensionElement getExtension(QName qname);
XmlElement getExtension(QName qname);
default boolean hasExtension(QName qname) {
return getExtension(qname) != null;
@ -78,7 +78,7 @@ public interface StanzaView extends XmlLangElement {
* @return true if a stanza extension exists, false otherwise.
*/
default boolean hasExtension(String namespace) {
for (ExtensionElement packetExtension : getExtensions()) {
for (XmlElement packetExtension : getExtensions()) {
if (packetExtension.getNamespace().equals(namespace)) {
return true;
}
@ -89,7 +89,7 @@ public interface StanzaView extends XmlLangElement {
default <E extends ExtensionElement> E getExtension(Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
ExtensionElement extensionElement = getExtension(qname);
XmlElement extensionElement = getExtension(qname);
if (extensionElement == null) {
return null;
@ -103,9 +103,9 @@ public interface StanzaView extends XmlLangElement {
*
* @return a list of all extension elements of this stanza.
*/
List<ExtensionElement> getExtensions();
List<XmlElement> getExtensions();
List<ExtensionElement> getExtensions(QName qname);
List<XmlElement> getExtensions(QName qname);
/**
* Return all extension elements of the given type. Returns the empty list if there a none.

View File

@ -105,7 +105,7 @@ public class StreamError extends AbstractError implements Nonza {
private final Condition condition;
private final String conditionText;
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<XmlElement> extensions) {
super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string

View File

@ -20,6 +20,6 @@ package org.jivesoftware.smack.packet;
* A XMPP top level stream element. This is either a stanza ({@link Stanza}) or
* just a plain stream element ({@link Nonza}).
*/
public interface TopLevelStreamElement extends FullyQualifiedElement {
public interface TopLevelStreamElement extends XmlElement {
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2019 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,23 @@ package org.jivesoftware.smack.packet;
import javax.xml.namespace.QName;
public interface FullyQualifiedElement extends NamedElement, XmlLangElement {
/**
* Interface to represent XML elements. Every XML element in XMPP has a qualified XML name ({@link QName}). This name
* can be obtained via {@link #getQName()}.
* <p>
* XMPP uses "extension elements", i.e. XML elements, to provide extended functionality beyond what is in the base XMPP
* specification. Examples of extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements. See {@link ExtensionElement} for more information about XMPP
* extension elements.
* </p>
* <p>
* It is recommend to use {@link ExtensionElement} over this class when creating new extension elements.
* </p>
*
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @since 4.5
*/
public interface XmlElement extends NamedElement, XmlLangElement {
/**
* Returns the root element XML namespace.

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,12 +34,24 @@ public class SmackParsingException extends Exception {
super(message);
}
/**
* Deprecated, do not import.
* @deprecated do not import.
*/
@Deprecated
// TODO: Remove in Smack 4.6.
public static class SmackTextParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Deprecated, do not use.
* @param parsingException the exception.
* @deprecated do not use, simply throw ParseException.
*/
@Deprecated
public SmackTextParseException(ParseException parsingException) {
super(parsingException);
}

View File

@ -16,11 +16,15 @@
*/
package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.text.ParseException;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException;
public class AbstractProvider<E extends Element> {
@ -55,4 +59,51 @@ public class AbstractProvider<E extends Element> {
public final Class<E> getElementClass() {
return elementClass;
}
public static final class TextParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;
private final ParseException parseException;
private TextParseException(ParseException parseException) {
super(parseException);
this.parseException = parseException;
}
public ParseException getParseException() {
return parseException;
}
}
public static final class NumberFormatParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;
private NumberFormatParseException(NumberFormatException numberFormatException) {
super(numberFormatException);
}
}
protected interface WrappableParser<E> {
E parse() throws XmlPullParserException, IOException, SmackParsingException, ParseException;
}
protected static <E> E wrapExceptions(WrappableParser<E> parser)
throws XmlPullParserException, IOException, SmackParsingException {
E e;
try {
e = parser.parse();
} catch (ParseException parseException) {
throw new TextParseException(parseException);
} catch (NumberFormatException numberFormatException) {
throw new NumberFormatParseException(numberFormatException);
}
return e;
}
}

View File

@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.util.PacketParserUtils;
@ -41,9 +41,9 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
* <b>smack.properties</b> file. Then they will be automatically picked up and used to parse
* any child elements.
*
* <pre>
* For example, given the following message
*
* <pre>
* &lt;message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo&gt;
* &lt;event xmlns='http://jabber.org/protocol/pubsub#event&gt;
* &lt;items node='princely_musings'&gt;
@ -57,6 +57,7 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
* &lt;/items&gt;
* &lt;/event&gt;
* &lt;/message&gt;
* </pre>
*
* I would have a classes
* <code>ItemsProvider</code> extends {@link EmbeddedExtensionProvider}
@ -67,6 +68,7 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
* These classes are then registered in the meta-inf/smack.providers file
* as follows.
*
* <pre>
* &lt;extensionProvider&gt;
* &lt;elementName&gt;items&lt;/elementName&gt;
* &lt;namespace&gt;http://jabber.org/protocol/pubsub#event&lt;/namespace&gt;
@ -77,12 +79,11 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
* &lt;namespace&gt;http://jabber.org/protocol/pubsub#event&lt;/namespace&gt;
* &lt;className&gt;org.jivesoftware.smackx.provider.ItemProvider&lt;/className&gt;
* &lt;/extensionProvider&gt;
*
* </pre>
*
* @author Robin Collier
*/
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
public abstract class EmbeddedExtensionProvider<PE extends XmlElement> extends ExtensionElementProvider<PE> {
@Override
public final PE parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
@ -95,7 +96,7 @@ public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> ext
attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
}
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
XmlPullParser.Event event;
do {
event = parser.next();
@ -109,5 +110,5 @@ public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> ext
}
protected abstract PE createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends ExtensionElement> content);
Map<String, String> attributeMap, List<? extends XmlElement> content);
}

View File

@ -17,7 +17,7 @@
package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
/**
* An abstract class for parsing custom extensions elements. Each ExtensionElementProvider must
@ -26,6 +26,6 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Matt Tucker
*/
public abstract class ExtensionElementProvider<EE extends ExtensionElement> extends Provider<EE> {
public abstract class ExtensionElementProvider<E extends XmlElement> extends Provider<E> {
}

View File

@ -18,6 +18,7 @@
package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
@ -50,7 +51,7 @@ public abstract class IQProvider<I extends IQ> extends IqProvider<I> {
final int initialDepth = parser.getDepth();
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
I e = parse(parser, initialDepth, xmlEnvironment);
I e = wrapExceptions(() -> parse(parser, initialDepth, xmlEnvironment));
// XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
@ -59,11 +60,12 @@ public abstract class IQProvider<I extends IQ> extends IqProvider<I> {
@Override
public final I parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
// Old-style IQ parsers do not need IqData.
return parse(parser, initialDepth, xmlEnvironment);
}
public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException;
public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,10 +26,22 @@ import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
/**
* Parsing with introspection poses a security threat and results in mutable classes and is therefore discouraged.
* @deprecated use a proper parser.
*/
// TODO: Remove in Smack 4.6.
@Deprecated
public class IntrospectionProvider{
// Unfortunately, we have to create two introspection providers, with the exactly the same code here
/**
* Parsing with introspection poses a security threat and results in mutable classes and is therefore discouraged.
* @deprecated use a proper parser.
*/
// TODO: Remove in Smack 4.6.
@Deprecated
public abstract static class IQIntrospectionProvider<I extends IQ> extends IQProvider<I> {
private final Class<I> elementClass;
@ -51,6 +63,12 @@ public class IntrospectionProvider{
}
}
/**
* Parsing with introspection poses a security threat and results in mutable classes and is therefore discouraged.
* @deprecated use a proper parser.
*/
// TODO: Remove in Smack 4.6.
@Deprecated
public abstract static class PacketExtensionIntrospectionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
private final Class<PE> elementClass;
@ -117,7 +135,7 @@ public class IntrospectionProvider{
* @param type the type of the property.
* @param value the encode String value to decode.
* @return the String value decoded into the specified type.
* @throws ClassNotFoundException
* @throws ClassNotFoundException if the provided class was not found.
*/
private static Object decode(Class<?> type, String value) throws ClassNotFoundException {
String name = type.getName();

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
@ -37,10 +38,12 @@ public abstract class IqProvider<I extends IQ> extends AbstractProvider<I> {
final int initialDepth = parser.getDepth();
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
return parse(parser, initialDepth, iqData, xmlEnvironment);
I i = wrapExceptions(() -> parse(parser, initialDepth, iqData, xmlEnvironment));
return i;
}
public abstract I parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException;
throws XmlPullParserException, IOException, SmackParsingException, ParseException;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@
package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.XmlEnvironment;
@ -50,12 +51,13 @@ public abstract class Provider<E extends Element> extends AbstractProvider<E> {
final int initialDepth = parser.getDepth();
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
E e = parse(parser, initialDepth, xmlEnvironment);
E e = wrapExceptions(() -> parse(parser, initialDepth, xmlEnvironment));
// XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
return e;
}
public abstract E parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException;
public abstract E parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException;
}

View File

@ -16,6 +16,10 @@
*/
package org.jivesoftware.smack.proxy;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
/**
* Class which stores proxy information such as proxy type, host, port,
* authentication etc.
@ -44,19 +48,10 @@ public class ProxyInfo {
this.proxyPort = pPort;
this.proxyUsername = pUser;
this.proxyPassword = pPass;
switch (proxyType) {
case HTTP:
proxySocketConnection = new HTTPProxySocketConnection(this);
break;
case SOCKS4:
proxySocketConnection = new Socks4ProxySocketConnection(this);
break;
case SOCKS5:
proxySocketConnection = new Socks5ProxySocketConnection(this);
break;
default:
throw new IllegalStateException();
}
this.proxySocketConnection =
ProxySocketConnection
.forProxyType(proxyType)
.apply(this);
}
public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser,
@ -74,6 +69,18 @@ public class ProxyInfo {
return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
}
public Proxy.Type getJavaProxyType() {
switch (proxyType) {
case HTTP:
return Proxy.Type.HTTP;
case SOCKS4:
case SOCKS5:
return Proxy.Type.SOCKS;
default:
throw new AssertionError("Invalid proxy type: " + proxyType);
}
}
public ProxyType getProxyType() {
return proxyType;
}
@ -97,4 +104,11 @@ public class ProxyInfo {
public ProxySocketConnection getProxySocketConnection() {
return proxySocketConnection;
}
public Proxy toJavaProxy() {
final SocketAddress proxySocketAddress = new InetSocketAddress(proxyAddress, proxyPort);
final Proxy.Type type = getJavaProxyType();
return new Proxy(type, proxySocketAddress);
}
}

View File

@ -19,6 +19,8 @@ package org.jivesoftware.smack.proxy;
import java.io.IOException;
import java.net.Socket;
import org.jivesoftware.smack.util.Function;
public interface ProxySocketConnection {
/**
@ -34,4 +36,16 @@ public interface ProxySocketConnection {
void connect(Socket socket, String host, int port, int timeout)
throws IOException;
static Function<ProxySocketConnection, ProxyInfo> forProxyType(ProxyInfo.ProxyType proxyType) {
switch (proxyType) {
case HTTP:
return HTTPProxySocketConnection::new;
case SOCKS4:
return Socks4ProxySocketConnection::new;
case SOCKS5:
return Socks5ProxySocketConnection::new;
default:
throw new AssertionError("Unknown proxy type: " + proxyType);
}
}
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2014-2019 Florian Schmaus
* Copyright 2003-2007 Jive Software, 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -311,6 +311,10 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
return false;
}
public boolean requiresPassword() {
return true;
}
public boolean isAuthenticationSuccessful() {
return authenticationSuccessful;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2014-2020 Florian Schmaus
* Copyright 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,7 +26,6 @@ import java.util.Random;
import javax.security.auth.callback.CallbackHandler;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.SmackSaslException;
import org.jivesoftware.smack.sasl.SASLMechanism;
import org.jivesoftware.smack.util.ByteUtils;
@ -263,6 +262,7 @@ public abstract class ScramMechanism extends SASLMechanism {
}
/**
* Get the channel binding data.
*
* @return the Channel Binding data.
* @throws SmackSaslException if a SASL specific error occurred.
@ -361,7 +361,7 @@ public abstract class ScramMechanism extends SASLMechanism {
* @param key TODO javadoc me please
* @param str TODO javadoc me please
* @return the HMAC-SHA1 value of the input.
* @throws SmackException if Smack detected an exceptional situation.
* @throws SmackSaslException if Smack detected an exceptional situation.
*/
private byte[] hmac(byte[] key, byte[] str) throws SmackSaslException {
try {

View File

@ -41,6 +41,19 @@ public final class FileUtils {
private static final Logger LOGGER = Logger.getLogger(FileUtils.class.getName());
public static InputStream getInputStreamForClasspathFile(String path) {
return getInputStreamForClasspathFile(path, null);
}
public static InputStream getInputStreamForClasspathFile(String path, ClassLoader loader) {
try {
return getStreamForClasspathFile(path, loader);
} catch (IOException e) {
LOGGER.log(Level.FINE, "Suppressed IOException in getInputStreamForClasspathFile", e);
return null;
}
}
public static InputStream getStreamForClasspathFile(String path, ClassLoader loader) throws IOException {
// Get an array of class loaders to try loading the providers files from.
List<ClassLoader> classLoaders = getClassLoaders();

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2015-2020 Florian Schmaus
* Copyright © 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
@ -251,7 +250,7 @@ public class MultiMap<K, V> {
public MultiMap<K, V> asUnmodifiableMultiMap() {
LinkedHashMap<K, List<V>> mapCopy = new LinkedHashMap<>(map.size());
for (Entry<K, List<V>> entry : map.entrySet()) {
for (Map.Entry<K, List<V>> entry : map.entrySet()) {
K key = entry.getKey();
List<V> values = entry.getValue();
@ -266,7 +265,7 @@ public class MultiMap<K, V> {
Map<K, List<V>> clonedMap = new LinkedHashMap<>(map.size());
// TODO: Use Map.forEach() once Smack's minimum Android API is 24 or higher.
for (Entry<K, List<V>> entry : map.entrySet()) {
for (Map.Entry<K, List<V>> entry : map.entrySet()) {
List<V> clonedList = CollectionUtil.newListWith(entry.getValue());
clonedMap.put(entry.getKey(), clonedList);
}

View File

@ -48,6 +48,7 @@ import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.UnparsedIQ;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
@ -183,7 +184,7 @@ public class PacketParserUtils {
message.setError(parseError(parser, messageXmlEnvironment));
break;
default:
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, messageXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, messageXmlEnvironment);
message.addExtension(extensionElement);
break;
}
@ -474,7 +475,7 @@ public class PacketParserUtils {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information.
try {
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, presenceXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, presenceXmlEnvironment);
presence.addExtension(extensionElement);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to parse extension element in Presence stanza: " + presence, e);
@ -701,7 +702,7 @@ public class PacketParserUtils {
*/
public static StreamError parseStreamError(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
final int initialDepth = parser.getDepth();
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
Map<String, String> descriptiveTexts = null;
StreamError.Condition condition = null;
String conditionText = null;
@ -765,7 +766,7 @@ public class PacketParserUtils {
final int initialDepth = parser.getDepth();
Map<String, String> descriptiveTexts = null;
XmlEnvironment stanzaErrorXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
StanzaError.Builder builder = StanzaError.getBuilder();
// Parse the error header
@ -825,7 +826,7 @@ public class PacketParserUtils {
* @throws IOException if an I/O error occurred.
* @throws SmackParsingException if the Smack parser (provider) encountered invalid input.
*/
public static ExtensionElement parseExtensionElement(String elementName, String namespace,
public static XmlElement parseExtensionElement(String elementName, String namespace,
XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ParserUtils.assertAtStartTag(parser);
// See if a provider is registered to handle the extension.
@ -907,7 +908,7 @@ public class PacketParserUtils {
public static void addExtensionElement(StanzaBuilder<?> stanzaBuilder, XmlPullParser parser, String elementName,
String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
stanzaBuilder.addExtension(extensionElement);
}
@ -919,18 +920,18 @@ public class PacketParserUtils {
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
packet.addExtension(packetExtension);
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
public static void addExtensionElement(Collection<XmlElement> collection, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace(), outerXmlEnvironment);
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser,
public static void addExtensionElement(Collection<XmlElement> collection, XmlPullParser parser,
String elementName, String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
collection.add(packetExtension);
}
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2020 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,7 @@ package org.jivesoftware.smack.util;
import java.util.Collection;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
public class PacketUtil {
@ -33,9 +33,9 @@ public class PacketUtil {
* @return the extension element
*/
@SuppressWarnings("unchecked")
public static <PE extends ExtensionElement> PE extensionElementFrom(Collection<ExtensionElement> collection,
public static <PE extends XmlElement> PE extensionElementFrom(Collection<XmlElement> collection,
String element, String namespace) {
for (ExtensionElement packetExtension : collection) {
for (XmlElement packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals(
element))
&& packetExtension.getNamespace().equals(namespace)) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,7 +30,6 @@ import org.jivesoftware.smack.datatypes.UInt32;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.RequiredAttributeMissingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -308,30 +307,23 @@ public class ParserUtils {
return s;
}
public static Date getDateFromOptionalXep82String(String dateString) throws SmackTextParseException {
public static Date getDateFromOptionalXep82String(String dateString) throws ParseException {
if (dateString == null) {
return null;
}
return getDateFromXep82String(dateString);
}
public static Date getDateFromXep82String(String dateString) throws SmackTextParseException {
try {
return XmppDateTime.parseXEP0082Date(dateString);
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
public static Date getDateFromXep82String(String dateString) throws ParseException {
return XmppDateTime.parseXEP0082Date(dateString);
}
public static Date getDateFromString(String dateString) throws SmackTextParseException {
try {
return XmppDateTime.parseDate(dateString);
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
public static Date getDateFromString(String dateString) throws ParseException {
return XmppDateTime.parseDate(dateString);
}
public static Date getDateFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException, SmackTextParseException {
public static Date getDateFromNextText(XmlPullParser parser)
throws XmlPullParserException, IOException, ParseException {
String dateString = parser.nextText();
return getDateFromString(dateString);
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2016-2019 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2016-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -47,4 +47,8 @@ public class RandomUtil {
public static int nextSecureRandomInt() {
return SECURE_RANDOM.get().nextInt();
}
public static void fillWithSecureRandom(byte[] bytes) {
SECURE_RANDOM.get().nextBytes(bytes);
}
}

View File

@ -24,8 +24,8 @@ import java.util.Date;
import java.util.List;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jxmpp.util.XmppDateTime;
@ -42,7 +42,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
effectiveXmlEnvironment = null;
}
public XmlStringBuilder(FullyQualifiedElement pe) {
public XmlStringBuilder(XmlElement pe) {
this(pe, null);
}
@ -51,7 +51,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
halfOpenElement(e.getElementName());
}
public XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment) {
public XmlStringBuilder(XmlElement element, XmlEnvironment enclosingXmlEnvironment) {
sb = new LazyStringBuilder();
halfOpenElement(element);
@ -516,7 +516,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
return escape(text.toString());
}
protected XmlStringBuilder prelude(FullyQualifiedElement pe) {
protected XmlStringBuilder prelude(XmlElement pe) {
return prelude(pe.getElementName(), pe.getNamespace());
}

View File

@ -64,4 +64,13 @@ public class XmlUtil {
return stringWriter.toString();
}
public static boolean isClarkNotation(String text) {
if (text.isEmpty()) {
return false;
}
// TODO: This is currently a mediocre heuristic to check for clark notation.
return text.charAt(0) == '{';
}
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2020 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,19 +24,19 @@ import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.StandardExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jxmpp.util.cache.LruCache;
public class XmppElementUtil {
private static final LruCache<Class<? extends FullyQualifiedElement>, QName> CLASS_TO_QNAME_CACHE = new LruCache<>(512);
private static final LruCache<Class<? extends XmlElement>, QName> CLASS_TO_QNAME_CACHE = new LruCache<>(512);
public static final Logger LOGGER = Logger.getLogger(XmppElementUtil.class.getName());
public static QName getQNameFor(Class<? extends FullyQualifiedElement> fullyQualifiedElement) {
public static QName getQNameFor(Class<? extends XmlElement> fullyQualifiedElement) {
QName qname = CLASS_TO_QNAME_CACHE.get(fullyQualifiedElement);
if (qname != null) {
return qname;
@ -72,24 +72,24 @@ public class XmppElementUtil {
}
public static <E extends ExtensionElement> List<E> getElementsFrom(
MultiMap<QName, ExtensionElement> elementMap, Class<E> extensionElementClass) {
MultiMap<QName, XmlElement> elementMap, Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
List<ExtensionElement> extensionElements = elementMap.getAll(qname);
List<XmlElement> extensionElements = elementMap.getAll(qname);
if (extensionElements.isEmpty()) {
return Collections.emptyList();
}
List<E> res = new ArrayList<>(extensionElements.size());
for (ExtensionElement extensionElement : extensionElements) {
for (XmlElement extensionElement : extensionElements) {
E e = castOrThrow(extensionElement, extensionElementClass);
res.add(e);
}
return res;
}
public static <E extends ExtensionElement> E castOrThrow(ExtensionElement extensionElement, Class<E> extensionElementClass) {
public static <E extends ExtensionElement> E castOrThrow(XmlElement extensionElement, Class<E> extensionElementClass) {
if (!extensionElementClass.isInstance(extensionElement)) {
final QName qname = getQNameFor(extensionElementClass);

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,6 +32,10 @@ public interface RemoteConnectionEndpoint {
String getDescription();
default String getRawString() {
return toString();
}
class InetSocketAddressCoupling<RCE extends RemoteConnectionEndpoint> {
private final RCE connectionEndpoint;
private final InetSocketAddress inetSocketAddress;

View File

@ -104,6 +104,8 @@ public class Base32 {
for (int j = 0; j < blocklen; j++)
ds.writeByte((byte) (t[j] & 0xFF));
} catch (IOException e) {
// This should not happen.
throw new AssertionError(e);
}
}

View File

@ -53,7 +53,7 @@ public class ConnectionConfigurationTest {
private static final class DummyConnectionConfiguration extends ConnectionConfiguration {
protected DummyConnectionConfiguration(Builder builder) {
DummyConnectionConfiguration(Builder builder) {
super(builder);
}

View File

@ -101,7 +101,7 @@ public class StreamErrorTest {
assertNotNull(error);
assertEquals(Condition.conflict, error.getCondition());
assertEquals("Replaced by new connection", error.getDescriptiveText());
ExtensionElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
XmlElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
assertNotNull(appSpecificElement);
}

View File

@ -20,17 +20,14 @@ import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.jivesoftware.smack.packet.StanzaError.Condition;
import org.jivesoftware.smack.packet.StanzaError.Type;
import org.junit.Test;
public class XMPPErrorTest {
@Test
public void testConditionHasDefaultTypeMapping() throws NoSuchFieldException, IllegalAccessException {
Map<Condition, Type> conditionToTypeMap = StanzaError.CONDITION_TO_TYPE;
Map<StanzaError.Condition, StanzaError.Type> conditionToTypeMap = StanzaError.CONDITION_TO_TYPE;
assertEquals("CONDITION_TO_TYPE map is likely out of sync with Condition enum",
Condition.values().length,
StanzaError.Condition.values().length,
conditionToTypeMap.size());
}
}

View File

@ -0,0 +1,70 @@
/**
*
* Copyright 2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.SmackTestUtil;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.junit.jupiter.api.Test;
public class AbstractProviderTest {
private static final ExtensionElementProvider<ExtensionElement> NUMBER_FORMAT_THROWING_PROVIDER = new ExtensionElementProvider<ExtensionElement>() {
@Override
public ExtensionElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
throw new NumberFormatException();
}
};
private static final String MESSAGE = "dummy message";
private static final int VALUE = 14768234;
private static final ExtensionElementProvider<ExtensionElement> PARSE_EXCEPTION_THROWING_PROVIDER = new ExtensionElementProvider<ExtensionElement>() {
@Override
public ExtensionElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
throw new ParseException(MESSAGE, VALUE);
}
};
@Test
public void testWrapsNumberFormatException() throws XmlPullParserException, IOException {
XmlPullParser parser = SmackTestUtil.createDummyParser();
assertThrows(AbstractProvider.NumberFormatParseException.class,
() -> NUMBER_FORMAT_THROWING_PROVIDER.parse(parser));
}
@Test
public void testWrapsParseException() throws XmlPullParserException, IOException {
XmlPullParser parser = SmackTestUtil.createDummyParser();
AbstractProvider.TextParseException testParseException = assertThrows(AbstractProvider.TextParseException.class,
() -> PARSE_EXCEPTION_THROWING_PROVIDER.parse(parser));
ParseException parseException = testParseException.getParseException();
assertEquals(MESSAGE, parseException.getMessage());
assertEquals(VALUE, parseException.getErrorOffset());
}
}

View File

@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
@ -58,7 +57,7 @@ public class ThreadedDummyConnection extends DummyConnection {
replyPacket.setStanzaId(packet.getStanzaId());
replyPacket.setTo(packet.getFrom());
if (replyPacket.getType() == null) {
replyPacket.setType(Type.result);
replyPacket.setType(IQ.Type.result);
}
new ProcessQueue(replyQ).start();

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.Provider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smack.xml.XmlPullParserFactory;
@ -125,6 +126,11 @@ public class SmackTestUtil {
return parser;
}
public static XmlPullParser createDummyParser() throws XmlPullParserException, IOException {
String dummyElement = "<empty-element/>";
return PacketParserUtils.getParserFor(dummyElement);
}
@SuppressWarnings("unchecked")
private static <E extends Element, P extends Provider<E>> P providerClassToProvider(Class<P> providerClass) {
P provider;

View File

@ -4,6 +4,6 @@ Inspect the exchanged XMPP stanzas.
Connect your favourite slf4j backend of choice to get output inside of it"""
dependencies {
compile project(':smack-core')
compile 'org.slf4j:slf4j-api:[1.7,1.8)'
api project(':smack-core')
implementation 'org.slf4j:slf4j-api:[1.7,1.8)'
}

View File

@ -3,5 +3,5 @@ Smack GUI debugger.
Inspect the exchanged XMPP stanzas."""
dependencies {
compile project(':smack-core')
api project(':smack-core')
}

View File

@ -5,10 +5,10 @@ otherwise carefully considered for deployment. The API may change even
between patch versions."""
dependencies {
compile project(':smack-core')
compile project(':smack-extensions')
api project(':smack-core')
api project(':smack-extensions')
compile "org.hsluv:hsluv:0.2"
implementation "org.hsluv:hsluv:0.2"
testFixturesApi(testFixtures(project(":smack-extensions")))
}

View File

@ -339,7 +339,7 @@ public final class CarbonManager extends Manager {
IQ setIQ = carbonsEnabledIQ(new_state);
connection().createStanzaCollectorAndSend(setIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(setIQ);
enabled_state = new_state;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Georg Lukas, 2020 Florian Schmaus
* Copyright 2013-2014 Georg Lukas, 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,9 +16,12 @@
*/
package org.jivesoftware.smackx.carbons.packet;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.forward.packet.Forwarded;
@ -34,7 +37,7 @@ import org.jivesoftware.smackx.forward.packet.Forwarded;
*
* @author Georg Lukas
*/
public class CarbonExtension implements ExtensionElement {
public class CarbonExtension implements XmlElement {
public static final String NAMESPACE = Carbon.NAMESPACE;
private final Direction dir;
@ -136,6 +139,7 @@ public class CarbonExtension implements ExtensionElement {
public static final class Private implements ExtensionElement {
public static final Private INSTANCE = new Private();
public static final String ELEMENT = "private";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private Private() {
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Georg Lukas, 2020 Florian Schmaus.
* Copyright 2013-2014 Georg Lukas, 2020-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.jivesoftware.smackx.carbons.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.XmlEnvironment;
@ -40,7 +41,8 @@ import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
public class CarbonManagerProvider extends ExtensionElementProvider<CarbonExtension> {
@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
public CarbonExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
Direction dir = Direction.valueOf(parser.getName());
Forwarded<Message> fwd = null;

View File

@ -17,8 +17,8 @@
package org.jivesoftware.smackx.chat_markers.filter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.ChatStateManager;
@ -56,7 +56,7 @@ public final class EligibleForChatMarkerFilter extends StanzaExtensionFilter {
}
if (super.accept(message)) {
ExtensionElement extension = message.getExtension(ChatStateManager.NAMESPACE);
XmlElement extension = message.getExtension(ChatStateManager.NAMESPACE);
String chatStateElementName = extension.getElementName();
ChatState state;

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2015 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.csi.packet;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Nonza;
@ -77,12 +79,19 @@ public class ClientStateIndication {
public static final Feature INSTANCE = new Feature();
public static final String ELEMENT = "csi";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private Feature() {
}
@Override
public String getElementName() {
return ELEMENT;
return QNAME.getLocalPart();
}
@Override
public String getNamespace() {
return QNAME.getNamespaceURI();
}
@Override
@ -90,9 +99,5 @@ public class ClientStateIndication {
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
}
@Override
public String getNamespace() {
return NAMESPACE;
}
}
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,7 +31,6 @@ import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StanzaError.Condition;
import org.jivesoftware.smack.packet.StanzaError.Type;
import org.jivesoftware.smack.util.RandomUtil;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
@ -89,7 +88,7 @@ public final class DnsOverXmppManager extends Manager {
response = resolver.resolve(query);
} catch (IOException exception) {
StanzaError errorBuilder = StanzaError.getBuilder()
.setType(Type.CANCEL)
.setType(StanzaError.Type.CANCEL)
.setCondition(Condition.internal_server_error)
.setDescriptiveEnText("Exception while resolving your DNS query", exception)
.build()

View File

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.fallback_indication;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.fallback_indication.element.FallbackIndicationElement;
public interface FallbackIndicationListener {

View File

@ -35,6 +35,7 @@ import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.fallback_indication.element.FallbackIndicationElement;

View File

@ -23,6 +23,7 @@ import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.fallback_indication.element.FallbackIndicationElement;
public class FallbackIndicationElementProvider extends ExtensionElementProvider<FallbackIndicationElement> {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2017 Paul Schaub
* Copyright © 2017 Paul Schaub, 2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.hashes.element;
import static org.jivesoftware.smack.util.Objects.requireNonNull;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.stringencoder.Base64;
@ -34,6 +36,8 @@ public class HashElement implements ExtensionElement {
public static final String ELEMENT = "hash";
public static final String ATTR_ALGO = "algo";
public static final QName QNAME = new QName(HashManager.NAMESPACE.V2.toString(), ELEMENT);
private final HashManager.ALGORITHM algorithm;
private final byte[] hash;
private final String hashB64;
@ -89,7 +93,12 @@ public class HashElement implements ExtensionElement {
@Override
public String getElementName() {
return ELEMENT;
return QNAME.getLocalPart();
}
@Override
public String getNamespace() {
return QNAME.getNamespaceURI();
}
@Override
@ -102,11 +111,6 @@ public class HashElement implements ExtensionElement {
return sb;
}
@Override
public String getNamespace() {
return HashManager.NAMESPACE.V2.toString();
}
@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof HashElement)) {

View File

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.hoxt.packet;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.NamedElement;
@ -161,6 +163,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class Data extends HoxExtensionElement {
public static final String ELEMENT = "data";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final NamedElement child;
@ -210,6 +213,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class Text extends HoxExtensionElement {
public static final String ELEMENT = "text";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String text;
@ -252,6 +256,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class Base64 extends HoxExtensionElement {
public static final String ELEMENT = "base64";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String text;
@ -294,6 +299,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class Xml extends HoxExtensionElement {
public static final String ELEMENT = "xml";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String text;
@ -336,6 +342,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class ChunkedBase64 extends HoxExtensionElement {
public static final String ELEMENT = "chunkedBase64";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String streamId;
@ -379,6 +386,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
public static class Ibb extends HoxExtensionElement {
public static final String ELEMENT = "ibb";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String sid;

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Andriy Tsykholyas, 2015 Florian Schmaus
* Copyright 2014 Andriy Tsykholyas, 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.hoxt.packet;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -36,6 +38,8 @@ public class Base64BinaryChunk implements ExtensionElement {
public static final String ATTRIBUTE_LAST = "last";
public static final String ATTRIBUTE_NR = "nr";
public static final QName QNAME = new QName(HOXTManager.NAMESPACE, ELEMENT_CHUNK);
private final String streamId;
private final boolean last;
private final String text;
@ -108,12 +112,12 @@ public class Base64BinaryChunk implements ExtensionElement {
@Override
public String getElementName() {
return ELEMENT_CHUNK;
return QNAME.getLocalPart();
}
@Override
public String getNamespace() {
return HOXTManager.NAMESPACE;
return QNAME.getNamespaceURI();
}
@Override

View File

@ -27,7 +27,6 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.logging.Level;
@ -37,6 +36,7 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.Manager;
@ -45,6 +45,7 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
@ -417,7 +418,7 @@ public final class HttpFileUploadManager extends Manager {
throw new AssertionError();
}
return connection.createStanzaCollectorAndSend(slotRequest).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(slotRequest);
}
public void setTlsContext(SSLContext tlsContext) {
@ -429,15 +430,15 @@ public final class HttpFileUploadManager extends Manager {
private void upload(InputStream iStream, long fileSize, Slot slot, UploadProgressListener listener) throws IOException {
final URL putUrl = slot.getPutUrl();
final HttpURLConnection urlConnection = (HttpURLConnection) putUrl.openConnection();
final XMPPConnection connection = connection();
final HttpURLConnection urlConnection = createURLConnection(connection, putUrl);
urlConnection.setRequestMethod("PUT");
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true);
urlConnection.setFixedLengthStreamingMode(fileSize);
urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
for (Entry<String, String> header : slot.getHeaders().entrySet()) {
for (Map.Entry<String, String> header : slot.getHeaders().entrySet()) {
urlConnection.setRequestProperty(header.getKey(), header.getValue());
}
@ -503,6 +504,30 @@ public final class HttpFileUploadManager extends Manager {
}
}
private static HttpURLConnection createURLConnection(XMPPConnection connection, URL putUrl) throws IOException {
Objects.requireNonNull(connection);
Objects.requireNonNull(putUrl);
ProxyInfo proxyInfo = fetchProxyInfo(connection);
if (proxyInfo != null) {
return createProxiedURLConnection(proxyInfo, putUrl);
}
return (HttpURLConnection) putUrl.openConnection();
}
private static HttpURLConnection createProxiedURLConnection(ProxyInfo proxyInfo, URL putUrl) throws IOException {
Objects.requireNonNull(proxyInfo);
Objects.requireNonNull(putUrl);
return (HttpURLConnection) putUrl.openConnection(proxyInfo.toJavaProxy());
}
private static ProxyInfo fetchProxyInfo(XMPPConnection connection) {
if (!(connection instanceof AbstractXMPPConnection)) {
return null;
}
AbstractXMPPConnection xmppConnection = (AbstractXMPPConnection) connection;
return xmppConnection.getConfiguration().getProxyInfo();
}
public static UploadService.Version namespaceToVersion(String namespace) {
UploadService.Version version;
switch (namespace) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2016 Florian Schmaus
* Copyright 2016-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.iot.provisioning.IoTProvisioningManager;
@ -70,7 +69,7 @@ public abstract class IoTManager extends Manager {
protected abstract class IoTIqRequestHandler extends AbstractIqRequestHandler {
protected IoTIqRequestHandler(String element, String namespace, Type type, Mode mode) {
protected IoTIqRequestHandler(String element, String namespace, IQ.Type type, Mode mode) {
super(element, namespace, type, mode);
}

View File

@ -23,7 +23,6 @@ import java.util.Iterator;
import org.jivesoftware.smackx.iot.control.ThingControlRequest;
import org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutRequest;
import org.jivesoftware.smackx.iot.discovery.element.Tag;
import org.jivesoftware.smackx.iot.discovery.element.Tag.Type;
import org.jivesoftware.smackx.iot.element.NodeInfo;
public final class Thing {
@ -112,35 +111,35 @@ public final class Thing {
public Builder setSerialNumber(String sn) {
final String name = "SN";
Tag tag = new Tag(name, Type.str, sn);
Tag tag = new Tag(name, Tag.Type.str, sn);
metaTags.put(name, tag);
return this;
}
public Builder setKey(String key) {
final String name = "KEY";
Tag tag = new Tag(name, Type.str, key);
Tag tag = new Tag(name, Tag.Type.str, key);
metaTags.put(name, tag);
return this;
}
public Builder setManufacturer(String manufacturer) {
final String name = "MAN";
Tag tag = new Tag(name, Type.str, manufacturer);
Tag tag = new Tag(name, Tag.Type.str, manufacturer);
metaTags.put(name, tag);
return this;
}
public Builder setModel(String model) {
final String name = "MODEL";
Tag tag = new Tag(name, Type.str, model);
Tag tag = new Tag(name, Tag.Type.str, model);
metaTags.put(name, tag);
return this;
}
public Builder setVersion(String version) {
final String name = "V";
Tag tag = new Tag(name, Type.num, version);
Tag tag = new Tag(name, Tag.Type.num, version);
metaTags.put(name, tag);
return this;
}

View File

@ -128,7 +128,7 @@ public final class IoTControlManager extends IoTManager {
public IoTSetResponse setUsingIq(FullJid jid, Collection<? extends SetData> data) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
IoTSetRequest request = new IoTSetRequest(data);
request.setTo(jid);
IoTSetResponse response = connection().createStanzaCollectorAndSend(request).nextResultOrThrow();
IoTSetResponse response = connection().sendIqRequestAndWaitForResponse(request);
return response;
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2016-2019 Florian Schmaus
* Copyright © 2016-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,10 +18,10 @@ package org.jivesoftware.smackx.iot.control.element;
import java.util.Locale;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
public abstract class SetData implements ExtensionElement {
public abstract class SetData implements XmlElement {
public enum Type {
BOOL,

Some files were not shown because too many files have changed in this diff Show More