mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
caps: handle multiple data forms of extened service discovery information
This commit is contained in:
parent
5e921e6393
commit
e79710840b
1 changed files with 36 additions and 40 deletions
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.caps;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
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.
|
||||
hash = hash.toLowerCase(Locale.US);
|
||||
|
||||
DataForm extendedInfo = DataForm.from(discoverInfo);
|
||||
|
||||
// 1. Initialize an empty string S ('sb' in this method).
|
||||
StringBuilder sb = new StringBuilder(); // Use StringBuilder as we don't
|
||||
// need thread-safe StringBuffer
|
||||
|
@ -705,11 +704,14 @@ public final class EntityCapsManager extends Manager {
|
|||
sb.append('<');
|
||||
}
|
||||
|
||||
// only use the data form for calculation is it has a hidden FORM_TYPE
|
||||
// field
|
||||
// see XEP-0115 5.4 step 3.6
|
||||
if (extendedInfo != null && extendedInfo.hasHiddenFormTypeField()) {
|
||||
synchronized (extendedInfo) {
|
||||
List<DataForm> extendedInfos = discoverInfo.getExtensions(DataForm.class);
|
||||
for (DataForm extendedInfo : extendedInfos) {
|
||||
if (!extendedInfo.hasHiddenFormTypeField()) {
|
||||
// Only use the data form for calculation is it has a hidden FORM_TYPE field.
|
||||
// See XEP-0115 5.4 step 3.f
|
||||
continue;
|
||||
}
|
||||
|
||||
// 6. If the service discovery information response includes
|
||||
// XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e.,
|
||||
// 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()) {
|
||||
if (!f.getVariable().equals("FORM_TYPE")) {
|
||||
fs.add(f);
|
||||
} else {
|
||||
ft = f;
|
||||
}
|
||||
}
|
||||
|
||||
// Add FORM_TYPE values
|
||||
if (ft != null) {
|
||||
formFieldValuesToCaps(ft.getValues(), sb);
|
||||
}
|
||||
formFieldValuesToCaps(Collections.singletonList(extendedInfo.getFormType()), sb);
|
||||
|
||||
// 7. 3. For each field other than FORM_TYPE:
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Ensure that S is encoded according to the UTF-8 encoding (RFC
|
||||
// 3269).
|
||||
// 9. Compute the verification string by hashing S using the algorithm
|
||||
|
|
Loading…
Reference in a new issue