From e1845a52cad445a77d1e83f8dc6aada0bc1561bf Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 15 Dec 2021 20:14:18 +0100 Subject: [PATCH 1/6] [formtypes] Add FormFieldRegistry.register(String, FormField.Type, String...) --- .../jivesoftware/smackx/formtypes/FormFieldRegistry.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java index 9eab79b73..87ecda00b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java @@ -67,6 +67,12 @@ public class FormFieldRegistry { } } + public static void register(String formType, FormField.Type fieldType, String... fieldNames) { + for (String fieldName : fieldNames) { + register(formType, fieldName, fieldType); + } + } + public static void register(String formType, String fieldName, FormField.Type fieldType) { StringUtils.requireNotNullNorEmpty(fieldName, "fieldName must be provided"); Objects.requireNonNull(fieldType); From 182d01a4b06550bf77dfaec1d2f1fe419fd0ed48 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 15 Dec 2021 20:14:49 +0100 Subject: [PATCH 2/6] [softwareinfo] Register urn:xmpp:dataforms:softwareinfo's field types --- .../smackx/softwareinfo/form/SoftwareInfoForm.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/softwareinfo/form/SoftwareInfoForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/softwareinfo/form/SoftwareInfoForm.java index 6774c3b73..b52949b49 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/softwareinfo/form/SoftwareInfoForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/softwareinfo/form/SoftwareInfoForm.java @@ -1,6 +1,6 @@ /** * - * Copyright 2020 Aditya Borikar + * Copyright 2020 Aditya Borikar, 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 java.util.List; import org.jivesoftware.smack.util.EqualsUtil; import org.jivesoftware.smack.util.HashCode; +import org.jivesoftware.smackx.formtypes.FormFieldRegistry; import org.jivesoftware.smackx.mediaelement.element.MediaElement; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.FormFieldChildElement; @@ -47,6 +48,11 @@ public final class SoftwareInfoForm extends FilledForm { public static final String SOFTWARE_VERSION = "software_version"; public static final String ICON = "icon"; + static { + FormFieldRegistry.register(FORM_TYPE, FormField.Type.text_single, + OS, OS_VERSION, SOFTWARE, SOFTWARE_VERSION); + } + private SoftwareInfoForm(DataForm dataForm) { super(dataForm); } From 993a3072225726d74277e24fa87d8ff32e9b0bca Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 17 Dec 2021 09:51:19 +0100 Subject: [PATCH 3/6] Add o.j.smackx.softwareinfo.form.SoftwareInfoForm to startup classes This ensures that the form fields are registered. --- .../resources/org.jivesoftware.smack.extensions/extensions.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.xml b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.xml index d234bb5b3..5921821a1 100644 --- a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.xml +++ b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.xml @@ -20,5 +20,6 @@ org.jivesoftware.smackx.receipts.DeliveryReceiptManager org.jivesoftware.smackx.iqversion.VersionManager org.jivesoftware.smackx.caps.EntityCapsManager + org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm From 817dc0ed3ae8745d23c6749d4f3ba64164b3e3cc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 21 Dec 2021 12:46:08 +0100 Subject: [PATCH 4/6] Prevent password enforcement for SASL GSSAPI Similar fix as 9b339efbc1cf ("Prevent password enforcement for SASL anonymous") just for SASL GSSAPI. Fixes SMACK-920. Fixes: 92f4aadfdc45 ("[sasl] Avoid mechanisms that need a password when none is available") --- .../jivesoftware/smack/sasl/javax/SASLGSSAPIMechanism.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLGSSAPIMechanism.java b/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLGSSAPIMechanism.java index 210e94ab9..bdef7d673 100644 --- a/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLGSSAPIMechanism.java +++ b/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLGSSAPIMechanism.java @@ -66,4 +66,8 @@ public class SASLGSSAPIMechanism extends SASLJavaXMechanism { return new SASLGSSAPIMechanism(); } + @Override + public boolean requiresPassword() { + return false; + } } From 940d7bf02abc0997eabc4cda12157ad2ceedfcf7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Dec 2021 21:17:57 +0100 Subject: [PATCH 5/6] [xdata] Adjust behavior of BooleanFormField.getValueAsBoolean() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to XEP-0004 § 3.3, the default value of a boolean form field is 'false'. And since users are typically interested in getting the value, and not potentially 'null' as result, we adjust the behavior of the getValueAsBoolean() method consider the default value. --- .../jivesoftware/smackx/xdata/BooleanFormField.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java index 85e351649..6208e4979 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java @@ -35,7 +35,17 @@ public class BooleanFormField extends SingleValueFormField { return value.toString(); } - public Boolean getValueAsBoolean() { + /** + * Get the value of the booelan field. Note that, if no explicit boolean value is provided, in the form of "true", + * "false", "0", or "1", then the default value of a boolean field is false, according to + * XEP-0004 § 3.3. + * + * @return the boolean value of this form field. + */ + public boolean getValueAsBoolean() { + if (value == null) { + return false; + } return value; } From 5c46451cd204f932fc48fced90a6b9bdb8847339 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Dec 2021 21:19:05 +0100 Subject: [PATCH 6/6] [xdata] Add BooleanFormField.getValueAsBooleanOrNull() This method is meant to provide 'raw' access to what has been sent over the wire. It is assumed to be not of much use in the typically case, but provided for completeness. --- .../smackx/xdata/BooleanFormField.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java index 6208e4979..6681e6408 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java @@ -49,6 +49,20 @@ public class BooleanFormField extends SingleValueFormField { return value; } + /** + * Get the value of the boolean field or maybe null. Note that you usually want to use + * {@link #getValueAsBoolean()} instead of this method, as {@link #getValueAsBoolean()} considers the default value + * of boolean fields. That is, boolean form fields have the value false if not explicitly set to + * something else. + * + * @return the boolean value of this form field or null if no value was explicitly provided. + * @see #getValueAsBoolean() + * @since 4.4.5 + */ + public Boolean getValueAsBooleanOrNull() { + return value; + } + public Builder asBuilder() { return new Builder(this); }