From 867d0ef191faf5af2573e7721d2fb14390eca0ee Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 31 Mar 2016 14:21:56 +0200 Subject: [PATCH] include form fields into caps hash calculation --- .../entities/ServiceDiscoveryResult.java | 19 +++++++++++++++++-- .../siacs/conversations/xmpp/forms/Data.java | 12 ++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java index 42f2d8409..31570d2d6 100644 --- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java +++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java @@ -17,6 +17,7 @@ import org.json.JSONObject; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.forms.Data; +import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.stanzas.IqPacket; public class ServiceDiscoveryResult { @@ -219,8 +220,22 @@ public class ServiceDiscoveryResult { }); for(Data form : forms) { - s.append(form.getFormType()+"<"); - //TODO append fields and values + s.append(form.getFormType() + "<"); + List fields = form.getFields(); + Collections.sort(fields, new Comparator() { + @Override + public int compare(Field lhs, Field rhs) { + return lhs.getFieldName().compareTo(rhs.getFieldName()); + } + }); + for(Field field : fields) { + s.append(field.getFieldName()+"<"); + List values = field.getValues(); + Collections.sort(values); + for(String value : values) { + s.append(value+"<"); + } + } } MessageDigest md; diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java index 380f02808..8dabcb5be 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java +++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java @@ -9,6 +9,8 @@ import eu.siacs.conversations.xml.Element; public class Data extends Element { + private static final String FORM_TYPE = "FORM_TYPE"; + public Data() { super("x"); this.setAttribute("xmlns","jabber:x:data"); @@ -17,7 +19,8 @@ public class Data extends Element { public List getFields() { ArrayList fields = new ArrayList(); for(Element child : getChildren()) { - if (child.getName().equals("field")) { + if (child.getName().equals("field") + && !FORM_TYPE.equals(child.getAttribute("var"))) { fields.add(Field.parse(child)); } } @@ -26,7 +29,8 @@ public class Data extends Element { public Field getFieldByName(String needle) { for(Element child : getChildren()) { - if (child.getName().equals("field") && needle.equals(child.getAttribute("var"))) { + if (child.getName().equals("field") + && needle.equals(child.getAttribute("var"))) { return Field.parse(child); } } @@ -76,11 +80,11 @@ public class Data extends Element { } public void setFormType(String formType) { - this.put("FORM_TYPE", formType); + this.put(FORM_TYPE, formType); } public String getFormType() { - String type = getValue("FORM_TYPE"); + String type = getValue(FORM_TYPE); return type == null ? "" : type; }