more disco. fixed chat markers with jappix

This commit is contained in:
iNPUTmice 2014-07-23 14:30:27 +02:00
parent 04156e945c
commit 5c118f6dd7
6 changed files with 99 additions and 18 deletions

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -2,9 +2,10 @@ package eu.siacs.conversations.generator;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
public class PresenceGenerator { public class PresenceGenerator extends AbstractGenerator {
private PresencePacket subscription(String type, Contact contact) { private PresencePacket subscription(String type, Contact contact) {
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
@ -38,6 +39,13 @@ public class PresenceGenerator {
packet.addChild("status").setContent("online"); packet.addChild("status").setContent("online");
packet.addChild("x", "jabber:x:signed").setContent(sig); 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; return packet;
} }
} }

View File

@ -56,23 +56,8 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
mXmppConnectionService.getJingleConnectionManager().deliverIbbPacket(account, packet); mXmppConnectionService.getJingleConnectionManager().deliverIbbPacket(account, packet);
} else if (packet.hasChild("query", } else if (packet.hasChild("query",
"http://jabber.org/protocol/disco#info")) { "http://jabber.org/protocol/disco#info")) {
IqPacket iqResponse = packet IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(packet);
.generateRespone(IqPacket.TYPE_RESULT); account.getXmppConnection().sendIqPacket(response, null);
Element query = iqResponse.addChild("query",
"http://jabber.org/protocol/disco#info");
query.addChild("feature").setAttribute("var",
"urn:xmpp:jingle:1");
query.addChild("feature").setAttribute("var",
"urn:xmpp:jingle:apps:file-transfer:3");
query.addChild("feature").setAttribute("var",
"urn:xmpp:jingle:transports:s5b:1");
query.addChild("feature").setAttribute("var",
"urn:xmpp:jingle:transports:ibb:1");
if (mXmppConnectionService.confirmMessages()) {
query.addChild("feature").setAttribute("var",
"urn:xmpp:receipts");
}
account.getXmppConnection().sendIqPacket(iqResponse, null);
} else { } else {
if ((packet.getType() == IqPacket.TYPE_GET) if ((packet.getType() == IqPacket.TYPE_GET)
|| (packet.getType() == IqPacket.TYPE_SET)) { || (packet.getType() == IqPacket.TYPE_SET)) {

View File

@ -295,6 +295,8 @@ public class MessageParser extends AbstractParser implements
message.markUnread(); message.markUnread();
} }
} }
} else {
parseNormal(packet, account);
} }
} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) { } else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {

View File

@ -29,6 +29,7 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.generator.MessageGenerator; import eu.siacs.conversations.generator.MessageGenerator;
import eu.siacs.conversations.generator.PresenceGenerator; import eu.siacs.conversations.generator.PresenceGenerator;
import eu.siacs.conversations.parser.IqParser; import eu.siacs.conversations.parser.IqParser;
@ -985,6 +986,7 @@ public class XmppConnectionService extends Service {
} }
private OnRenameListener renameListener = null; private OnRenameListener renameListener = null;
private IqGenerator mIqGenerator = new IqGenerator();
public void setOnRenameListener(OnRenameListener listener) { public void setOnRenameListener(OnRenameListener listener) {
this.renameListener = listener; this.renameListener = listener;
@ -1399,6 +1401,10 @@ public class XmppConnectionService extends Service {
return this.mPresenceGenerator; return this.mPresenceGenerator;
} }
public IqGenerator getIqGenerator() {
return this.mIqGenerator ;
}
public JingleConnectionManager getJingleConnectionManager() { public JingleConnectionManager getJingleConnectionManager() {
return this.mJingleConnectionManager; return this.mJingleConnectionManager;
} }