diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-07-23 14:30:27 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-07-23 14:30:27 +0200 |
commit | 5c118f6dd751905ccab2d9d65f28ec8e210c484a (patch) | |
tree | 474e0ba6acd64d82abcfb6cae139ac27112c857e /src/eu/siacs/conversations/generator | |
parent | 04156e945cc832e83c0f12e4ed6ebe06b3070b53 (diff) |
more disco. fixed chat markers with jappix
Diffstat (limited to 'src/eu/siacs/conversations/generator')
3 files changed, 89 insertions, 1 deletions
diff --git a/src/eu/siacs/conversations/generator/AbstractGenerator.java b/src/eu/siacs/conversations/generator/AbstractGenerator.java new file mode 100644 index 00000000..49b5d614 --- /dev/null +++ b/src/eu/siacs/conversations/generator/AbstractGenerator.java @@ -0,0 +1,49 @@ +package eu.siacs.conversations.generator; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import android.util.Base64; + +public abstract class AbstractGenerator { + public final String[] FEATURES = { "urn:xmpp:jingle:1", + "urn:xmpp:jingle:apps:file-transfer:3", + "urn:xmpp:jingle:transports:s5b:1", + "urn:xmpp:jingle:transports:ibb:1", + "urn:xmpp:receipts", + "urn:xmpp:chat-markers:0", + "http://jabber.org/protocol/muc", + "jabber:x:conference", + "http://jabber.org/protocol/caps", + "http://jabber.org/protocol/disco#info"}; + //public final String[] FEATURES = { "http://jabber.org/protocol/muc","http://jabber.org/protocol/disco#info", "http://jabber.org/protocol/disco#items", "http://jabber.org/protocol/caps" }; + + //public final String IDENTITY_NAME = "Exodus 0.9.1"; + //public final String IDENTITY_TYPE = "pc"; + + + public final String IDENTITY_NAME = "Conversations 0.5"; + public final String IDENTITY_TYPE = "phone"; + + public String getCapHash() { + StringBuilder s = new StringBuilder(); + s.append("client/"+IDENTITY_TYPE+"//"+IDENTITY_NAME+"<"); + MessageDigest md = null; + try { + md = MessageDigest.getInstance("SHA-1"); + } + catch(NoSuchAlgorithmException e) { + return null; + } + List<String> features = Arrays.asList(FEATURES); + Collections.sort(features); + for(String feature : features) { + s.append(feature+"<"); + } + byte[] sha1 = md.digest(s.toString().getBytes()); + return new String(Base64.encode(sha1, Base64.DEFAULT)); + } +} diff --git a/src/eu/siacs/conversations/generator/IqGenerator.java b/src/eu/siacs/conversations/generator/IqGenerator.java new file mode 100644 index 00000000..7b3350d4 --- /dev/null +++ b/src/eu/siacs/conversations/generator/IqGenerator.java @@ -0,0 +1,31 @@ +package eu.siacs.conversations.generator; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xmpp.stanzas.IqPacket; + +public class IqGenerator extends AbstractGenerator { + + + + public IqPacket discoResponse(IqPacket request) { + IqPacket packet = new IqPacket(IqPacket.TYPE_RESULT); + packet.setId(request.getId()); + packet.setTo(request.getFrom()); + Element query = packet.addChild("query","http://jabber.org/protocol/disco#info"); + query.setAttribute("node", request.query().getAttribute("node")); + Element identity = query.addChild("identity"); + identity.setAttribute("category","client"); + identity.setAttribute("type", this.IDENTITY_TYPE); + identity.setAttribute("name", IDENTITY_NAME); + List<String> features = Arrays.asList(FEATURES); + Collections.sort(features); + for(String feature : features) { + query.addChild("feature").setAttribute("var",feature); + } + return packet; + } +} diff --git a/src/eu/siacs/conversations/generator/PresenceGenerator.java b/src/eu/siacs/conversations/generator/PresenceGenerator.java index a301392e..b3431568 100644 --- a/src/eu/siacs/conversations/generator/PresenceGenerator.java +++ b/src/eu/siacs/conversations/generator/PresenceGenerator.java @@ -2,9 +2,10 @@ package eu.siacs.conversations.generator; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; -public class PresenceGenerator { +public class PresenceGenerator extends AbstractGenerator { private PresencePacket subscription(String type, Contact contact) { PresencePacket packet = new PresencePacket(); @@ -38,6 +39,13 @@ public class PresenceGenerator { packet.addChild("status").setContent("online"); packet.addChild("x", "jabber:x:signed").setContent(sig); } + String capHash = getCapHash(); + if (capHash != null) { + Element cap = packet.addChild("c","http://jabber.org/protocol/caps"); + cap.setAttribute("hash", "sha-1"); + cap.setAttribute("node","http://conversions.siacs.eu"); + cap.setAttribute("ver", capHash); + } return packet; } }
\ No newline at end of file |