caps: handle multiple data forms of extened service discovery information

This commit is contained in:
Florian Schmaus 2020-04-18 22:56:24 +02:00
parent 5e921e6393
commit e79710840b
1 changed files with 36 additions and 40 deletions

View File

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.caps;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -664,8 +665,6 @@ public final class EntityCapsManager extends Manager {
// be "broken" implementation in the wild, so we *always* transform to lowercase. // be "broken" implementation in the wild, so we *always* transform to lowercase.
hash = hash.toLowerCase(Locale.US); hash = hash.toLowerCase(Locale.US);
DataForm extendedInfo = DataForm.from(discoverInfo);
// 1. Initialize an empty string S ('sb' in this method). // 1. Initialize an empty string S ('sb' in this method).
StringBuilder sb = new StringBuilder(); // Use StringBuilder as we don't StringBuilder sb = new StringBuilder(); // Use StringBuilder as we don't
// need thread-safe StringBuffer // need thread-safe StringBuffer
@ -705,11 +704,14 @@ public final class EntityCapsManager extends Manager {
sb.append('<'); sb.append('<');
} }
// only use the data form for calculation is it has a hidden FORM_TYPE List<DataForm> extendedInfos = discoverInfo.getExtensions(DataForm.class);
// field for (DataForm extendedInfo : extendedInfos) {
// see XEP-0115 5.4 step 3.6 if (!extendedInfo.hasHiddenFormTypeField()) {
if (extendedInfo != null && extendedInfo.hasHiddenFormTypeField()) { // Only use the data form for calculation is it has a hidden FORM_TYPE field.
synchronized (extendedInfo) { // See XEP-0115 5.4 step 3.f
continue;
}
// 6. If the service discovery information response includes // 6. If the service discovery information response includes
// XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e., // XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e.,
// by the XML character data of the <value/> element). // by the XML character data of the <value/> element).
@ -720,20 +722,14 @@ public final class EntityCapsManager extends Manager {
} }
}); });
FormField ft = null;
for (FormField f : extendedInfo.getFields()) { for (FormField f : extendedInfo.getFields()) {
if (!f.getVariable().equals("FORM_TYPE")) { if (!f.getVariable().equals("FORM_TYPE")) {
fs.add(f); fs.add(f);
} else {
ft = f;
} }
} }
// Add FORM_TYPE values // Add FORM_TYPE values
if (ft != null) { formFieldValuesToCaps(Collections.singletonList(extendedInfo.getFormType()), sb);
formFieldValuesToCaps(ft.getValues(), sb);
}
// 7. 3. For each field other than FORM_TYPE: // 7. 3. For each field other than FORM_TYPE:
// 1. Append the value of the "var" attribute, followed by the // 1. Append the value of the "var" attribute, followed by the
@ -748,7 +744,7 @@ public final class EntityCapsManager extends Manager {
formFieldValuesToCaps(f.getValues(), sb); formFieldValuesToCaps(f.getValues(), sb);
} }
} }
}
// 8. Ensure that S is encoded according to the UTF-8 encoding (RFC // 8. Ensure that S is encoded according to the UTF-8 encoding (RFC
// 3269). // 3269).
// 9. Compute the verification string by hashing S using the algorithm // 9. Compute the verification string by hashing S using the algorithm