Commit Graph

110 Commits

Author SHA1 Message Date
Florian Schmaus b1e4884fbb Remove erroneous next() from AbstractJsonExtensionProvider
Fixes SMACK-695.
2015-08-24 11:09:59 +02:00
Florian Schmaus e6a403fb1c Re-escape XML text in parseContentDepth()
SMACK-680.
2015-07-02 16:10:50 +02:00
Florian Schmaus 236dfb009d Improve logging of parsing errors 2015-05-07 22:40:38 +02:00
Florian Schmaus f579fb2c77 Throw exception if smack-java7 is loaded on Android 2015-04-25 22:53:46 +02:00
Florian Schmaus 451eb4c826 Add missing break statements 2015-03-23 09:52:01 +01:00
Florian Schmaus 5e86db4f80 Substitute 'packet' with 'stanza(/packet)' in javadoc 2015-03-21 09:36:28 +01:00
Florian Schmaus e85c1881d7 Add TypedCloneable 2015-03-10 22:50:48 +01:00
Florian Schmaus dde0cfd7f6 Fix incoming file transfers
With bb8dcc9874 the concept if IQ request
handlers was introduced in Smack. This doesn't allow packet/stanza
collectors/listeners to filter for incoming IQ requests. Unfortunately
the file transfer code relied on this being able, so it broke with the
change.

There were two places where the file transfer code was listening for
incoming IQ requests:
- InitationListener(s)
- Negotiator(s)

With this change, we let the InitiationListener signal the existence of
an incoming initation request, send by an IQ of type 'set', using the
newly created EventManager utility.

The negotiator waits for those events to arrive and proceedes as it would
have done when the packet collector was used.
2015-03-02 15:56:26 +01:00
Florian Schmaus d4a6d8e653 Rename PacketFilter (and implementing classes) and PacketExtension
to StanzaFilter and ExtensionElement.
2015-02-28 13:49:38 +01:00
Florian Schmaus 39382b8b38 Shorten Smack's executor service names
instead of

"Smack Executor - Foo 42 (2)"

use

"Smack-Foo 42 (2)"

since sometimes the space for the name is limited (e.g. busybox's 'ps
-t').
2015-02-25 16:09:41 +01:00
Florian Schmaus afba123ba3 Javadoc improvements in MultiMap and Stanza 2015-02-23 10:49:33 +01:00
Florian Schmaus 4698805a34 Rename 'Packet' class to 'Stanza'
Smack still uses the term 'Packet' in some places. This is just the
first step towards using correct XMPP terms in Smack.
2015-02-06 09:34:51 +01:00
Florian Schmaus 9fc26f1d83 Use MultiMap for Stanza extension elements 2015-02-05 11:04:38 +01:00
Florian Schmaus 4013c68584 Use Objects.requireNonNull() in Presence
Also make Objects.requireNonNull() throw NullPointerException to match
the original API behavior.
2015-02-03 19:32:04 +01:00
Florian Schmaus 37081b2810 Send more information with the stream open tag 2015-01-28 09:31:28 +01:00
Florian Schmaus 86ea027301 Add StringUtils.requireNotNullOrEmpty and Objects.requireNonNull
and use this in a few places.
2015-01-26 20:47:09 +01:00
Florian Schmaus 4b10f36e9e Report failed DNS SRV lookup in ConnectionException
instead of just logging a warning if the XMPP domain has no DNS SRV
lookups, create the failedAddresses list now within DNSUtil and add the
information that the SRV lookup failed.
2015-01-26 07:54:12 +01:00
Florian Schmaus d97de5f42c Fix typo in DNSUtil.setIdnaTransformer 2015-01-21 09:50:50 +01:00
Florian Schmaus c5db012fc8 Improve privacy parsing and API. Add NumberUtil
Make 'order' an long

Parse fall-through case's child elements (message, iq, presence-in,
presence-out)

Remove

privacy.addExtension(new DefaultPacketExtension(parser.getName(), parser.getNamespace()));

at the beginning of PrivacyProvider. Was there since day one for an
unknown reason.
2015-01-21 09:50:44 +01:00
Florian Schmaus 8409dddffd Add PacketUtil.extensionElementFrom()
and deprecate extensionElementfromCollection()
2015-01-19 08:41:21 +01:00
Florian Schmaus 9ae66cc747 Use Exception.getString in HostAddress
instead of getMessage(), because some Exceptions, e.g. Android's
NetworkOnMainThreadException, will return null on
getMessage(). Exception.toString() does what we want, i.e. returns
- the exception class name
- and the return value of getLocalizedMessage()
2015-01-18 19:21:58 +01:00
Florian Schmaus 9ec7d628c8 TLSUtils.disableHostnameVerificationForTlsCertificates()
(yeah, I know)

Sometimes "a friend" has setup an XMPP service which uses a self-signed
cert. While we can get a decent amount of security by using techniques
like e.g. the MemorizingTrustManager, there's still a pitfall. If the
service's TLS certificates contains no or the wrong service/hostname
information, Smack will throw an CertificateException. Therefore provide
an API call to disable hostname verification.
2015-01-17 12:17:28 +01:00
Florian Schmaus b0cecee710 Rename IQ.ELEMENT to IQ.IQ_ELEMENT
to avoid confusion between the IQ element 'iq' and the IQs child
element. ELEMENT defined in an IQ sublcass should contain the *child*
element.

Add element to StreamInitation and fix FileTransferManager which still
used a packet listener instead of an IQ request handler to handle
incoming stream initiation requests.
2015-01-11 21:54:46 +01:00
Florian Schmaus 8f8e0c7138 Use Async.go() in ReconnectionManager 2015-01-10 01:12:37 +01:00
Florian Schmaus bb8dcc9874 Add IQ request handler API
This also moves the logic to send error IQ replies from "when there is
no IQ provider registerd" to "when there is no IQ request handler
registered". Which has for example the advantage that IQ parsing no
longer asks for a connection instance.
2015-01-08 23:15:24 +01:00
Florian Schmaus b23df7d2b8 Decrease logging verbosity in FileUtils.readFile(File) 2015-01-07 14:35:23 +01:00
Florian Schmaus f2703bc195 Improve SHIM API
- HeadersExtension.getHeaders() now returns a List instead of a
  Collection
- Use XmlStringBuilder in Header and HeadersExtension toXML()
- Add HeadersProviderTest
- Use Smack formatting

Also remove duplicate parsing code regarding SHIM from HOXT
implementation.
2015-01-02 00:09:30 +01:00
Florian Schmaus c5d0fb3c7b Add support for *optional* session establishment
Don't perform XMPP session binding if the server announced the feature
as optional.

Fixes SMACK-622
2014-12-30 14:34:04 +01:00
Anno van Vliet b08dbc1dbc Support for XEP-0122: Data Forms Validation.
Data Forms Validation are a part of Data Fields and implemented as
extensions, added to a Datafield.

Data validation extensions are validated before adding to the message,
using the consistency rules as described in the XEP.
Fixes SMACK-621.

Minor modifications done by Florian Schmaus <flo@geekplace.eu>
2014-12-30 02:03:12 +01:00
Florian Schmaus f4aaf387d4 Use assertAtStartTag in parseStanza 2014-12-28 17:45:11 +01:00
Florian Schmaus 755765120d Make FormField.Type an enum 2014-12-27 21:12:48 +01:00
Florian Schmaus 18ac83cf8c Move SmackExecutorThreadFactory out of
AbstractXMPPConnection. And use it in PingManager.
2014-12-19 12:53:16 +01:00
Florian Schmaus a87227c531 Rename ConnectionConfigurationBuilder to Builder 2014-12-18 10:15:35 +01:00
Florian Schmaus c89d06861b Use switch-case in PacketParserUtils.parseContentDepthWithoutRoundtrip() 2014-12-10 12:28:22 +01:00
Florian Schmaus 77f0fdc156 Add (IQ|PacketExtension)IntrospectionProvider
This simplifies code as there is no longer a distinction between
"normal" providers and introspection providers in ProviderManager
necessary.

It's also easier to get an idea where introspection is used for parsing.
2014-12-10 11:09:52 +01:00
Florian Schmaus 9286a1decb Rework XMPP Error class design
Introduce AbstractError, change 'Conditions' to enums. Because of
AbstractError, it was necessary that PlainStreamElement and
TopLevelStreamElement becomes an interface. Thus the implementation of
TopLevelStreamElement.toString() had to be removed.

This adds

- policy-violation
- unexpected-request

to XMPPError.Condition, and removes the

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

Conditions

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

Fixes SMACK-608. Makes it possible to resolves SMACK-386.
2014-11-25 13:19:32 +01:00
Florian Schmaus cc09192095 Smack 4.0.6
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQF8BAABCgBmBQJUci2fXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
 ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxMzU3QjAxODY1QjI1MDNDMTg0NTNEMjA4
 Q0FDMkE5Njc4NTQ4RTM1AAoJEIysKpZ4VI415IIH/j1eCvLIjNqNP6ytXdgomYY+
 j2i5KRHMv69La1JqtdmAeTeZfD13549s/66I5VUfegEfaADGUPr1NGrQKlb8lJBe
 YSqthMaQUybLBuCL9Lwg/3jE6s27GixRjW/Wip4ntac1wS2R3qD18lAxYIivsGJh
 gvyGHGoXvdct6teu9X0RtmyE/EOBfV63y1gVJG07Jv5/AJ2wCh9dIOD4jFuqvkoA
 cz2OfVJOIFletBV2psLxc0VVeqU9Lpba5TZuW1ZylY61z+X2rpt9BwCgBD35jTF9
 ztP2ytQY80+vZO6uP+Tl75QxdQd/e0O9oGnYbmMp1gfYQjgETaHUDxAL2uw4XNo=
 =7UY+
 -----END PGP SIGNATURE-----

Merge tag '4.0.6'

Smack 4.0.6

Conflicts:
	smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java
	version.gradle
2014-11-23 20:05:44 +01:00
Florian Schmaus 646a4a6f90 Add support for SASL failure 'text' elements
- Also move toString() into TopLevelStreamElement.
- Fix SASLFailure toXML xmlnsAttribute(NAMESPACE)
- Improve SASLFailure parsing
- And introduce XmlUnitUtils
2014-11-19 09:57:39 +01:00
Florian Schmaus 763f9c7c14 Implemented MD5 just like the SHA1 util 2014-11-15 09:46:39 +01:00
Florian Schmaus c81cd34561 Apply builder pattern to ConnectionConfiguration
Introducing a clean split between the constant connection configuration
parameters, which are now all in ConnectionConfiguration and the dynamic
connection state (e.g. hostAddresses) which are now in
AbstractXMPPConnection.

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

Also remove documentation/extensions/messageevents.md, as it's already
in documentation/legacy
2014-11-15 09:46:31 +01:00
Florian Schmaus 4000adb70c Fallback to host if DNS SRV lookup fails
Also fix javadoc for DNSUtil, _jabber SRV records are no longer tried.

Fixes SMACK-616.
2014-11-10 21:21:44 +01:00
Florian Schmaus 9e797c1b17 Enable PacketExtensions for IQs
This is actually only part one, i.e. with this commit if the user adds a
PacketExtension to an IQ it will be included in IQ.toXml(). Which was
previously only the case if the IQ subclass explicitly included packet
extensions.

The second part of the change is to change the IQ provider, so that
packet extensions are automatically parsed.

Cases where PacketExtensions are used for Message and IQ are slightly
changed. The IQ sublcass now only has a field with this
PacketExtension (see for example
bytestreams.ibb.packet.DataPacketExtension).

Also changed hoxt API: Removed unnecessary indirection and made the
API more Smack idiomatic.
2014-11-10 11:43:18 +01:00
Florian Schmaus 1de2fc2a81 Refactor Bind and Roster IQ parsing code into providers 2014-10-30 13:21:36 +01:00
Florian Schmaus e88583d287 Use switch/case in 'IQ parse(XmlPullParser)' 2014-10-30 13:21:36 +01:00
Florian Schmaus b5daee3032 Include the full content in UnparsedResultIQ
In order to prevent

<iq to='...' from='...' type='result' id='1'>
  <mynode xmlns='my:namespace' myattr='...'>
    <somenode\>
  </mynode>
</iq>

showing up as UnparsedResultIQ like this:

<iq to='...' from='...' type='result' id='1'>
  <somenode\>
</iq>
2014-10-30 13:21:36 +01:00
Florian Schmaus 53bba50f91 Call pingServerIfNecessary in new thread
in order to prevent the BroadcastReceiver from timing out.

To prevent:

10-24 10:59:35.096 W/BroadcastQueue( 1044): Timeout of broadcast BroadcastRecord{43400df0 u0 org.igniterealtime.smackx.ping.ACTION} - receiver=android.os.BinderProxy@42d37cc0, started 60000ms ago
10-24 10:59:35.096 W/BroadcastQueue( 1044): Receiver during timeout: BroadcastFilter{42cee7b0 u0 ReceiverList{42cfd9f0 16003 org.projectmaxs.transport.xmpp/10149/u0 remote:42d37cc0}}

10-24 10:59:38.201 E/ActivityManager( 1044): ANR in org.projectmaxs.transport.xmpp
10-24 10:59:38.201 E/ActivityManager( 1044): PID: 16003
10-24 10:59:38.201 E/ActivityManager( 1044): Reason: Broadcast of Intent { act=org.igniterealtime.smackx.ping.ACTION flg=0x14 (has extras) }
10-24 10:59:38.201 E/ActivityManager( 1044): Load: 18.97 / 31.7 / 45.71
10-24 10:59:38.201 E/ActivityManager( 1044): CPU usage from 20588ms to 0ms ago:
10-24 10:59:38.201 E/ActivityManager( 1044):   0.4% 1044/system_server: 0.2% user + 0.1% kernel / faults: 188 minor 1 major
10-24 10:59:38.201 E/ActivityManager( 1044):   0.4% 9089/kworker/0:3: 0% user + 0.4% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0.1% 1567/mpdecision: 0% user + 0.1% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0.1% 28507/kworker/u:5: 0% user + 0.1% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 7/kworker/u:0H: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 148/mmcqd/0: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 14687/com.teslacoilsw.launcher: 0% user + 0% kernel / faults: 6 minor
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 3/ksoftirqd/0: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 1111/MC_Thread: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 1135/wpa_supplicant: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 1283/com.android.phone: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 11469/com.getpebble.android: 0% user + 0% kernel / faults: 1 minor
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 14971/com.google.android.apps.unveil: 0% user + 0% kernel / faults: 6 minor
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 28677/watch_server: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   0% 31539/kworker/0:2: 0% user + 0% kernel
10-24 10:59:38.201 E/ActivityManager( 1044): 1.2% TOTAL: 0.4% user + 0.5% kernel + 0.2% iowait
10-24 10:59:38.201 E/ActivityManager( 1044): CPU usage from 2536ms to 3060ms later:
10-24 10:59:38.201 E/ActivityManager( 1044):   9.2% 1044/system_server: 1.8% user + 7.4% kernel / faults: 56 minor
10-24 10:59:38.201 E/ActivityManager( 1044):     5.5% 1058/ActivityManager: 0% user + 5.5% kernel
10-24 10:59:38.201 E/ActivityManager( 1044):   1.3% 23415/kworker/0:1H: 0% user + 1.3% kernel
10-24 10:59:38.201 E/ActivityManager( 1044): 0% TOTAL: 0% user + 0% kernel + 0% iowait
10-24 10:59:38.208 I/ActivityManager( 1044): Killing 16003:org.projectmaxs.transport.xmpp/u0a149 (adj 0): background ANR
2014-10-24 11:45:28 +02:00
Florian Schmaus 403ecff2b2 Add SCRAM-SHA1 support
Thanks to Stefan Karlsson for helping with the implementation.

Also add SASLMechanism.checkIfSuccessfulOrThrow(), to increase the
security by verifying the mechanisms state at the end of SASL
authentication.

SASLMechanism now has a SASLPrep StringTransformer.

Refactor SHA1 functions out of StringUtils into SHA1 utility class.

Add MAC utility class.

Make DummyConnection getSentpacket() methods use generics to make unit
testing SCRAM-SHA1 easier.

Fixes SMACK-398
2014-10-21 15:03:48 +02:00
Florian Schmaus 3733a6aaa5 Cache the parser availability of the roundtrip feature
As otherwise there would be multiple log statements (which are of level
fine but nevertheless).

PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1)
PacketParserUtils: 	at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2600(XMPPTCPConnection.java:1224)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1263)
PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1)
PacketParserUtils: 	at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989)
PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1)
PacketParserUtils: 	at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989)
PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1)
PacketParserUtils: 	at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150)
PacketParserUtils: 	at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970)
PacketParserUtils: 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989)
2014-10-19 20:58:42 +02:00
Florian Schmaus a90c1ac845 Remove 'throws Exception' from DNSUtil.resolve…(String) 2014-10-19 11:49:45 +02:00
Florian Schmaus ed58abbee7 Support XML_ROUNDTRIP where possible
The approach to avoid XmlPullParser's XML_ROUNDTRIP feature prevents
Smack from handling XML namespaces on e.g. PubSub payloads on platforms
where support for XML_ROUNDTRIP would be available.

We now check for this XmlPullParser feature and use it if it's
available.
2014-10-15 22:50:48 +02:00