added no-copy

This commit is contained in:
Daniel Gultsch 2014-03-20 15:49:53 +01:00
parent 5653880156
commit b6ea028a9d
5 changed files with 36 additions and 53 deletions

View File

@ -158,9 +158,8 @@ public class OtrEngine implements OtrEngineHost {
packet.setFrom(account.getFullJid()); //sender packet.setFrom(account.getFullJid()); //sender
packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient
packet.setBody(body); packet.setBody(body);
Element privateTag = new Element("private"); packet.addChild("private","urn:xmpp:carbons:2");
privateTag.setAttribute("xmlns","urn:xmpp:carbons:2"); packet.addChild("no-copy","urn:xmpp:hints");
packet.addChild(privateTag);
packet.setType(MessagePacket.TYPE_CHAT); packet.setType(MessagePacket.TYPE_CHAT);
Log.d(LOGTAG,packet.toString()); Log.d(LOGTAG,packet.toString());
account.getXmppConnection().sendMessagePacket(packet); account.getXmppConnection().sendMessagePacket(packet);

View File

@ -619,11 +619,8 @@ public class XmppConnectionService extends Service {
.getFullJid()); .getFullJid());
packet.setTo(message.getCounterpart()); packet.setTo(message.getCounterpart());
packet.setBody("This is an XEP-0027 encryted message"); packet.setBody("This is an XEP-0027 encryted message");
Element x = new Element("x"); packet.addChild("x","jabber:x:encrypted").setContent(this.getPgpEngine().encrypt(keyId,
x.setAttribute("xmlns", "jabber:x:encrypted");
x.setContent(this.getPgpEngine().encrypt(keyId,
message.getBody())); message.getBody()));
packet.addChild(x);
account.getXmppConnection().sendMessagePacket(packet); account.getXmppConnection().sendMessagePacket(packet);
message.setStatus(Message.STATUS_SEND); message.setStatus(Message.STATUS_SEND);
message.setEncryption(Message.ENCRYPTION_DECRYPTED); message.setEncryption(Message.ENCRYPTION_DECRYPTED);
@ -694,9 +691,8 @@ public class XmppConnectionService extends Service {
+ ": could not encrypt message to " + ": could not encrypt message to "
+ message.getCounterpart()); + message.getCounterpart());
} }
Element privateMarker = new Element("private"); packet.addChild("private","urn:xmpp:carbons:2");
privateMarker.setAttribute("xmlns", "urn:xmpp:carbons:2"); packet.addChild("no-copy","urn:xmpp:hints");
packet.addChild(privateMarker);
packet.setTo(otrSession.getSessionID().getAccountID() + "/" packet.setTo(otrSession.getSessionID().getAccountID() + "/"
+ otrSession.getSessionID().getUserID()); + otrSession.getSessionID().getUserID());
packet.setFrom(account.getFullJid()); packet.setFrom(account.getFullJid());
@ -736,16 +732,13 @@ public class XmppConnectionService extends Service {
public void updateRoster(final Account account, public void updateRoster(final Account account,
final OnRosterFetchedListener listener) { final OnRosterFetchedListener listener) {
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET); IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
Element query = new Element("query");
query.setAttribute("xmlns", "jabber:iq:roster");
if (!"".equals(account.getRosterVersion())) { if (!"".equals(account.getRosterVersion())) {
Log.d(LOGTAG, account.getJid() + ": fetching roster version " Log.d(LOGTAG, account.getJid() + ": fetching roster version "
+ account.getRosterVersion()); + account.getRosterVersion());
} else { } else {
Log.d(LOGTAG, account.getJid() + ": fetching roster"); Log.d(LOGTAG, account.getJid() + ": fetching roster");
} }
query.setAttribute("ver", account.getRosterVersion()); iqPacket.query("jabber:iq:roster").setAttribute("ver", account.getRosterVersion());
iqPacket.addChild(query);
account.getXmppConnection().sendIqPacket(iqPacket, account.getXmppConnection().sendIqPacket(iqPacket,
new OnIqPacketReceived() { new OnIqPacketReceived() {
@ -958,13 +951,8 @@ public class XmppConnectionService extends Service {
public void deleteContact(Contact contact) { public void deleteContact(Contact contact) {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET); IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element query = new Element("query"); Element query = iq.query("jabber:iq:roster");
query.setAttribute("xmlns", "jabber:iq:roster"); query.addChild("item").setAttribute("jid", contact.getJid()).setAttribute("subscription", "remove");
Element item = new Element("item");
item.setAttribute("jid", contact.getJid());
item.setAttribute("subscription", "remove");
query.addChild(item);
iq.addChild(query);
contact.getAccount().getXmppConnection().sendIqPacket(iq, null); contact.getAccount().getXmppConnection().sendIqPacket(iq, null);
replaceContactInConversation(contact.getJid(), null); replaceContactInConversation(contact.getJid(), null);
databaseBackend.deleteContact(contact); databaseBackend.deleteContact(contact);
@ -1035,8 +1023,7 @@ public class XmppConnectionService extends Service {
Element history = new Element("history"); Element history = new Element("history");
long lastMsgTime = conversation.getLatestMessage().getTimeSent(); long lastMsgTime = conversation.getLatestMessage().getTimeSent();
long diff = (System.currentTimeMillis() - lastMsgTime) / 1000 - 1; long diff = (System.currentTimeMillis() - lastMsgTime) / 1000 - 1;
history.setAttribute("seconds", diff + ""); x.addChild("history").setAttribute("seconds", diff + "");
x.addChild(history);
} }
packet.addChild(x); packet.addChild(x);
conversation.getAccount().getXmppConnection() conversation.getAccount().getXmppConnection()

View File

@ -17,7 +17,22 @@ public class Element {
public Element addChild(Element child) { public Element addChild(Element child) {
this.content = null; this.content = null;
children.add(child); children.add(child);
return this; return child;
}
public Element addChild(String name) {
this.content = null;
Element child = new Element(name);
children.add(child);
return child;
}
public Element addChild(String name, String xmlns) {
this.content = null;
Element child = new Element(name);
child.setAttribute("xmlns", xmlns);
children.add(child);
return child;
} }
public Element setContent(String content) { public Element setContent(String content) {

View File

@ -461,11 +461,7 @@ public class XmppConnection implements Runnable {
if (this.streamFeatures.hasChild("session")) { if (this.streamFeatures.hasChild("session")) {
Log.d(LOGTAG,"sending session"); Log.d(LOGTAG,"sending session");
IqPacket startSession = new IqPacket(IqPacket.TYPE_SET); IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
Element session = new Element("session"); startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session"); //setContent("")
session.setAttribute("xmlns",
"urn:ietf:params:xml:ns:xmpp-session");
session.setContent("");
startSession.addChild(session);
this.sendIqPacket(startSession, null); this.sendIqPacket(startSession, null);
} }
} }
@ -484,7 +480,8 @@ public class XmppConnection implements Runnable {
IqPacket register = new IqPacket(IqPacket.TYPE_SET); IqPacket register = new IqPacket(IqPacket.TYPE_SET);
Element username = new Element("username").setContent(account.getUsername()); Element username = new Element("username").setContent(account.getUsername());
Element password = new Element("password").setContent(account.getPassword()); Element password = new Element("password").setContent(account.getPassword());
register.query("jabber:iq:register").addChild(username).addChild(password); register.query("jabber:iq:register").addChild(username);
register.query().addChild(password);
sendIqPacket(register, new OnIqPacketReceived() { sendIqPacket(register, new OnIqPacketReceived() {
@Override @Override
@ -515,14 +512,9 @@ public class XmppConnection implements Runnable {
packet.setAttribute("from", account.getFullJid()); packet.setAttribute("from", account.getFullJid());
if (account.getKeys().has("pgp_signature")) { if (account.getKeys().has("pgp_signature")) {
try { try {
String signature = account.getKeys().getString("pgp_signature"); String signature = account.getKeys().getString("pgp_signature");
Element status = new Element("status"); packet.addChild("status").setContent("online");
status.setContent("online"); packet.addChild("x","jabber:x:signed").setContent(signature);
packet.addChild(status);
Element x = new Element("x");
x.setAttribute("xmlns", "jabber:x:signed");
x.setContent(signature);
packet.addChild(x);
} catch (JSONException e) { } catch (JSONException e) {
// //
} }
@ -532,12 +524,7 @@ public class XmppConnection implements Runnable {
private void sendBindRequest() throws IOException { private void sendBindRequest() throws IOException {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET); IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element bind = new Element("bind"); iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind").addChild("resource").setContent("Conversations");
bind.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-bind");
Element resource = new Element("resource");
resource.setContent("Conversations");
bind.addChild(resource);
iq.addChild(bind);
this.sendIqPacket(iq, new OnIqPacketReceived() { this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
@ -601,9 +588,7 @@ public class XmppConnection implements Runnable {
private void sendEnableCarbons() { private void sendEnableCarbons() {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET); IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element enable = new Element("enable"); iq.addChild("enable","urn:xmpp:carbons:2");
enable.setAttribute("xmlns", "urn:xmpp:carbons:2");
iq.addChild(enable);
this.sendIqPacket(iq, new OnIqPacketReceived() { this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override @Override
@ -679,10 +664,8 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(new RequestPacket()); tagWriter.writeStanzaAsync(new RequestPacket());
} else { } else {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET); IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
Element ping = new Element("ping"); iq.setFrom(account.getFullJid());
iq.setAttribute("from",account.getFullJid()); iq.addChild("ping","urn:xmpp:ping");
ping.setAttribute("xmlns", "urn:xmpp:ping");
iq.addChild(ping);
this.sendIqPacket(iq, null); this.sendIqPacket(iq, null);
} }
} }

View File

@ -39,8 +39,7 @@ public class IqPacket extends AbstractStanza {
public Element query() { public Element query() {
Element query = findChild("query"); Element query = findChild("query");
if (query==null) { if (query==null) {
query = new Element("query"); query = addChild("query");
addChild(query);
} }
return query; return query;
} }