Commit Graph

393 Commits

Author SHA1 Message Date
Florian Schmaus 11cc2d8d77 [core] Align behavior of getParserFor(InputStream) and getParserFor(Reader)
Reported-by: Ingo Bauersachs <ingo@jitsi.org>
2021-11-30 10:49:55 +01:00
Florian Schmaus 7dc8cc176e [core] Add DoOnce utility 2021-11-01 19:27:09 +01:00
Florian Schmaus e842195b71 Merge branch '4.4' 2021-10-19 14:33:21 +02:00
Florian Schmaus ab92bc4b40
Merge pull request #501 from Flowdalic/fix-redundant-namespaces
Fix redundant namespaces
2021-10-19 14:29:18 +02:00
Florian Schmaus b243a40e26 [core] Pass down the XML environment in IQChildElementXmlStringBuilder
This allows to avoid redundant XML namespaces within IQs, like for
example here:

<iq xmlns='jabber:client' id='EKP8I-1' type='set'>
    <jingle xmlns='urn:xmpp:jingle:1' action='content-accept' sid='MySession'>
        <content xmlns='urn:xmpp:jingle:1' creator='initiator' name='Hello world'>
        </content>
    </jingle>
</iq>

Fixes SMACK-917

Reported-by: Jonathan Lennox
2021-10-19 11:29:23 +02:00
Florian Schmaus 55299fb7e7 [core] Assert that 'event' is not END_DOCUMENT in forwardToEndTagOfDepth() 2021-09-13 10:10:55 +02:00
Florian Schmaus 3f2418dec7 [core] Fix spelling errors in code comment within PacketParserUtils 2021-08-25 22:54:23 +02:00
Florian Schmaus 001985647a Merge branch '4.4'
This also fixes a errornous merge where the same branch with different
commit was merged into master and 4.4

The conflicting commits are

4.4:
8f760eaeb3  getRawValueCharSequences
e626580f68

master:
b47225c2c1  getRawValues
097d245358
2021-08-23 18:02:00 +02:00
Florian Schmaus 59d3d75a71 Merge branch '4.4' 2021-08-03 21:54:50 +02:00
Florian Schmaus e626580f68 [xdata] Safe the raw character data of form field values
Related to SMACK-909.
2021-07-19 15:38:42 +02:00
Florian Schmaus 097d245358 [xdata] Safe the raw character data of form field values 2021-07-18 17:21:50 +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 e04a3877fb Merge branch '4.4' 2021-03-25 19:28:58 +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 4fefa92e40 Merge branch '4.4' 2021-03-19 09:47:07 +01:00
Florian Schmaus 17ac41c8cb [core] Add RandomUtil.fillWithSecureRandom(byte[]) 2021-03-14 12:48:01 +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 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 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 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
Florian Schmaus 35a71f0131 Merge branch '4.4' 2021-01-06 13:51:38 +01:00
Florian Schmaus fcc372754e Fix NPE in BoBIQ by adding XmlStringBuilder.optIntAttribute(String, Integer)
The method was missing and hence BoBIQ used optIntAttribute(String,
int) instead, which resulted in an NPE if the Integer was null.

Fixes SMACK-895.
2021-01-06 13:45:13 +01:00
Florian Schmaus d8642847ea Smack 4.4.0
-----BEGIN PGP SIGNATURE-----
 
 iQGTBAABCgB9FiEEl3UFnzoh3OFr5PuuIjmn6PWFIFIFAl/Msl5fFIAAAAAALgAo
 aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDk3
 NzUwNTlGM0EyMURDRTE2QkU0RkJBRTIyMzlBN0U4RjU4NTIwNTIACgkQIjmn6PWF
 IFIq8gf9GZp0Cl9Gr+seA/C8nczE/cNRKfHnDR224klbjlGrnojb+bL2QgeKG6wN
 u/eL3+UMus8uw3+R8NKARawqt/r6mbk4bgdGEbzoByLO6iiPYTr7TuZmTOQyZa5L
 tMNkFIvfvMzDeDDqI4z4uTgT3s7YBg0d4BT7cL8T6RaZGHF57OxqhWnKxMuaiTXH
 HJzVTPrtAcYg17QZl5+mrhiWyynE5+4QGeluYHlh7vvsniwNOqrwO1vWHg2BX003
 DjaHK+6oLjKxVljCklXxE7Wsx0VcMrBfv2qZwW3Q4ZzZVcrAn8TC4HrUtR8DL176
 DpGlEhmmdr3xKKX0JQ9RmIod+xSabw==
 =4wGX
 -----END PGP SIGNATURE-----

Merge tag '4.4.0'

Smack 4.4.0
2020-12-06 12:16:44 +01:00
Florian Schmaus a4bb5bfda8 [ibb] Use UInt16 for 'seq' and fix its handling
Fixes a off-by-one error when incrementing 'seq'. Thanks to Kim
Alvefur <zash@zash.se> for spotting this.
2020-12-05 23:04:17 +01:00
Florian Schmaus 1a963cc794 Merge branch '4.4' 2020-11-25 20:57:44 +01:00
Florian Schmaus 02c9058c3d [core] Remove @SuppressWarnings for parseContentDepthWithRoundtrip()
Also use the most specific return type in the method's signature.
2020-11-25 20:55:05 +01:00
Florian Schmaus ca497a2199 [core] Fix parseContentDepthWithRoundtrip() and add tests 2020-11-25 20:55:05 +01:00
Florian Schmaus 5782fff2a4 Merge branch '4.4' 2020-09-23 21:42:51 +02:00
Florian Schmaus 15e3d267f6 Add Pair utility class 2020-09-23 19:46:01 +02:00
Florian Schmaus b857f33ac3 Merge branch '4.4' 2020-09-20 14:12:37 +02:00
Florian Schmaus 525ee09ea1 [tcp] Do not send SM ack after we send a </stream:stream>
Do net put an ack to the queue if it has already been shutdown. Some
servers, like ejabberd, like to request an ack even after we have send
a stream close (and hance the queue was shutdown). If we would not
check here, then the ack would dangle around in the queue, and be send
on the next re-connection attempt even before the stream open.

See the following trace of the MUC bookmarks integration test. The
fact that it is a MUC test does not matter, but this test does
disconnect the connection and reconnect it. Not how the server,
ejabberd in this case, requests an SM ack by sending an <r/> even
though we already send the </stream:stream>:

22:22:05 SENT (4):
<iq id='MD4UC-61' type='set'>
  <query xmlns='jabber:iq:private'>
    <storage xmlns='storage:bookmarks'>
      <conference name='Smack Inttest: 7in7j' autojoin='true' jid='y9jcn5@conference.salem.geekplace.eu'>
        <nick>
          Nick-P2VXD7
        </nick>
      </conference>
    </storage>
  </query>
</iq>
22:22:05 RECV (4):
<r xmlns='urn:xmpp:sm:3'/>
22:22:05 SENT (4):
<a xmlns='urn:xmpp:sm:3' h='29'/>
22:22:05 RECV (4):
<message to='sinttest-7in7j-4@salem.geekplace.eu' from='sinttest-7in7j-4@salem.geekplace.eu' type='headline'>
  <event xmlns='http://jabber.org/protocol/pubsub#event'>
    <items node='storage:bookmarks'>
      <item id='current'>
        <storage xmlns='storage:bookmarks'>
          <conference name='Smack Inttest: 7in7j' autojoin='true' jid='y9jcn5@conference.salem.geekplace.eu'>
            <nick>
              Nick-P2VXD7
            </nick>
          </conference>
        </storage>
      </item>
    </items>
  </event>
  <addresses xmlns='http://jabber.org/protocol/address'>
    <address jid='sinttest-7in7j-4@salem.geekplace.eu/1415073683806426185213090' type='replyto'/>
  </addresses>
</message>
22:22:05 RECV (4):
<iq xml:lang='en-US' to='sinttest-7in7j-4@salem.geekplace.eu/1415073683806426185213090' from='sinttest-7in7j-4@salem.geekplace.eu' type='result' id='MD4UC-61'/>
22:22:05 SENT (4):
<presence id='6MS6J-20' type='unavailable'/>
<a xmlns='urn:xmpp:sm:3' h='31'/>
<!-- We have closed the stream -->
</stream:stream>
<!-- But the server still requests an SM ack -->
22:22:05 RECV (4):
<r xmlns='urn:xmpp:sm:3'/>
22:22:05 RECV (4):
</stream:stream>
22:22:05 XMPPConnection closed (XMPPTCPConnection[sinttest-7in7j-4@salem.geekplace.eu/1415073683806426185213090] (4))
22:22:05 SENT (4):
<a xmlns='urn:xmpp:sm:3' h='31'/>
22:22:05 SENT (4):
<stream:stream xmlns='jabber:client' to='salem.geekplace.eu' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='sinttest-7in7j-4@salem.geekplace.eu' xml:lang='en-US'>
22:22:05 RECV (4): ?xml version='1.0'?>
<stream:stream id='3379123514446782311' ver
22:22:05 RECV (4): sion='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>
<stream:error>
  <invalid-xml xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
</stream:error>
</stream:stream>
22:22:05 XMPPConnection closed due to an exception (XMPPTCPConnection[sinttest-7in7j-4@salem.geekplace.eu/1415073683806426185213090] (4))
org.jivesoftware.smack.XMPPException$StreamErrorException: invalid-xml You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
<stream:error><invalid-xml xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:981)
	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.base/java.lang.Thread.run(Thread.java:834)
2020-09-18 14:36:26 +02:00
Florian Schmaus b7824f008d Introduce and use XmlStringBuilder.text()
Smack currently does unnecessary escaping of XML text, where it
escapes e.g. '"' to '&quot;'. This bloats the stanza size, especially
if JSON payloads are involved.

Fixes SMACK-892 (although there are probably still places where
XmlStringBuilder.escape() is used when XmlStringBuild.text() could
have been used).
2020-09-17 14:20:11 +02:00
Florian Schmaus 525f27abf1 Merge branch '4.4' 2020-08-29 16:39:15 +02:00
Florian Schmaus d06e9499e8 [core] Add XmppElementUtil.castOrThrow(ExtensionElement, Class)
This method throws an IllegalStateException if the provided extension
element is not of the expected type and hints users towards potential
causes.
2020-08-29 16:29:22 +02:00
adiaholic 7ed29b9d5f Introduce websocket module into smack 2020-08-28 23:40:40 +05:30
Florian Schmaus 1aab0b8aac [core] Add cache to XmppElementUtil.getQNameFor(Class) 2020-08-28 09:47:09 +02:00
Florian Schmaus 2a9671ca93 [core] Change type of XmlStringBuilder cosntructor to FullyQualifiedElement
There is no reason we should do this only for ExtensionElements, this
behavior is sane for every FulllyQualifiedElement.
2020-08-26 11:35:22 +02:00
Aditya Borikar 7796b367cc Position parser at START_ELEMENT before parsing
This PR aims to provide parseXrdLinkReferencesFor() method the ability
to parse forward to the first START_ELEMENT tag.The HttpLookupMethodTest
tests the HttpLookupMethod class by parsing String. This makes use of
PacketParserUtils.getParserFor(String), which already does forward
winding to reach START_ELEMENT. However when fetching endpoints from a
remote host meta data, PacketParserUtils.getParserFor(InputStream) is
used which doesn't do winding in any form. And thus, even though
HttpLookupMethodTest tests pass, this implementation would crash while
parsing remote host-meta.
2020-08-07 15:01:53 +05:30
Florian Schmaus 2b423b911e Merge branch 'master' of github.com:igniterealtime/Smack 2020-07-18 21:47:06 +02:00
Paul Schaub bb3c491e0c
StringUtils: Fix typo and expose unambiguous alphabet as string 2020-07-15 22:15:38 +02:00
Florian Schmaus d3a99a133a [core] Fix log/exception message of XmppElementUtil
The Class.toString() already prefixes the resulting string with "class
", no need to state it explicitly in the log message that this is a
class.
2020-07-13 08:50:10 +02:00
Florian Schmaus 3f9ca68134 Delete TypedCloneable 2020-06-14 17:38:51 +02:00
Florian Schmaus 57961a8cc1 Remove SynchronizationPoint
This continues the design started with e98d42790 ("SmackReactor/NIO,
Java8/Android19, Pretty print XML, FSM connections"), where the
exceptions that caused an operation to fail, are not recorded within
SynchronizationPoint but within the connection instance itself.
2020-05-31 19:48:47 +02:00
Florian Schmaus f5448c5faa [core] Rework TLS logic
This moves the logic in AbstractXMPPConnection.getSmackTlsContext()
into the ConnectionConfiguration constructor.

Also introduce SslContextFactory and use it in
ConnectionConfiguration.
2020-05-25 15:41:57 +02:00
Florian Schmaus d65f2c932e Bump Error Prone version to 2.3.4 and fix new bug patterns 2020-05-24 21:10:01 +02:00
Florian Schmaus 9a8ee3c8e3 [core] Improve NumberUtil's exception message and fix javadoc 2020-05-24 13:08:03 +02:00
Florian Schmaus dfdd0acf91 Introduce AbstractStats 2020-05-18 09:15:14 +02:00
Florian Schmaus 77e26fc575 Re-work data form API
Apply builder pattern to form fields and replace getVariable() with
getFieldName(). Refer to the field name as "field name" instead of
"variable" everyone, just as XEP-0004 does.

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

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

Smack also now does omit the form field type declaration on 'submit'
type forms, as it is allowed by XEP-0004.
2020-05-13 20:14:41 +02:00
Florian Schmaus ad13effe41
Merge pull request #382 from vanitasvitae/typo
Fix typo in XmppElementUtil
2020-04-13 23:03:34 +02:00
Florian Schmaus 5114f6dfa4 core: remove deprecated methods in PacketUtil
Those where deprecated in 2015 with 8409dddff ("Add
PacketUtil.extensionElementFrom()"), and in 2017 with
2288825b1 ("Retain smack-core API").
2020-04-13 21:25:28 +02:00