diff options
Diffstat (limited to 'src/eu')
5 files changed, 36 insertions, 53 deletions
diff --git a/src/eu/siacs/conversations/crypto/OtrEngine.java b/src/eu/siacs/conversations/crypto/OtrEngine.java index 3aa87658..8efa21eb 100644 --- a/src/eu/siacs/conversations/crypto/OtrEngine.java +++ b/src/eu/siacs/conversations/crypto/OtrEngine.java @@ -158,9 +158,8 @@ public class OtrEngine implements OtrEngineHost { packet.setFrom(account.getFullJid()); //sender packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient packet.setBody(body); - Element privateTag = new Element("private"); - privateTag.setAttribute("xmlns","urn:xmpp:carbons:2"); - packet.addChild(privateTag); + packet.addChild("private","urn:xmpp:carbons:2"); + packet.addChild("no-copy","urn:xmpp:hints"); packet.setType(MessagePacket.TYPE_CHAT); Log.d(LOGTAG,packet.toString()); account.getXmppConnection().sendMessagePacket(packet); diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 3e964800..187f6879 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -619,11 +619,8 @@ public class XmppConnectionService extends Service { .getFullJid()); packet.setTo(message.getCounterpart()); packet.setBody("This is an XEP-0027 encryted message"); - Element x = new Element("x"); - x.setAttribute("xmlns", "jabber:x:encrypted"); - x.setContent(this.getPgpEngine().encrypt(keyId, + packet.addChild("x","jabber:x:encrypted").setContent(this.getPgpEngine().encrypt(keyId, message.getBody())); - packet.addChild(x); account.getXmppConnection().sendMessagePacket(packet); message.setStatus(Message.STATUS_SEND); message.setEncryption(Message.ENCRYPTION_DECRYPTED); @@ -694,9 +691,8 @@ public class XmppConnectionService extends Service { + ": could not encrypt message to " + message.getCounterpart()); } - Element privateMarker = new Element("private"); - privateMarker.setAttribute("xmlns", "urn:xmpp:carbons:2"); - packet.addChild(privateMarker); + packet.addChild("private","urn:xmpp:carbons:2"); + packet.addChild("no-copy","urn:xmpp:hints"); packet.setTo(otrSession.getSessionID().getAccountID() + "/" + otrSession.getSessionID().getUserID()); packet.setFrom(account.getFullJid()); @@ -736,16 +732,13 @@ public class XmppConnectionService extends Service { public void updateRoster(final Account account, final OnRosterFetchedListener listener) { IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET); - Element query = new Element("query"); - query.setAttribute("xmlns", "jabber:iq:roster"); if (!"".equals(account.getRosterVersion())) { Log.d(LOGTAG, account.getJid() + ": fetching roster version " + account.getRosterVersion()); } else { Log.d(LOGTAG, account.getJid() + ": fetching roster"); } - query.setAttribute("ver", account.getRosterVersion()); - iqPacket.addChild(query); + iqPacket.query("jabber:iq:roster").setAttribute("ver", account.getRosterVersion()); account.getXmppConnection().sendIqPacket(iqPacket, new OnIqPacketReceived() { @@ -958,13 +951,8 @@ public class XmppConnectionService extends Service { public void deleteContact(Contact contact) { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); - Element query = new Element("query"); - query.setAttribute("xmlns", "jabber:iq:roster"); - Element item = new Element("item"); - item.setAttribute("jid", contact.getJid()); - item.setAttribute("subscription", "remove"); - query.addChild(item); - iq.addChild(query); + Element query = iq.query("jabber:iq:roster"); + query.addChild("item").setAttribute("jid", contact.getJid()).setAttribute("subscription", "remove"); contact.getAccount().getXmppConnection().sendIqPacket(iq, null); replaceContactInConversation(contact.getJid(), null); databaseBackend.deleteContact(contact); @@ -1035,8 +1023,7 @@ public class XmppConnectionService extends Service { Element history = new Element("history"); long lastMsgTime = conversation.getLatestMessage().getTimeSent(); long diff = (System.currentTimeMillis() - lastMsgTime) / 1000 - 1; - history.setAttribute("seconds", diff + ""); - x.addChild(history); + x.addChild("history").setAttribute("seconds", diff + ""); } packet.addChild(x); conversation.getAccount().getXmppConnection() diff --git a/src/eu/siacs/conversations/xml/Element.java b/src/eu/siacs/conversations/xml/Element.java index 6cf6d3a5..91d9ed6b 100644 --- a/src/eu/siacs/conversations/xml/Element.java +++ b/src/eu/siacs/conversations/xml/Element.java @@ -17,7 +17,22 @@ public class Element { public Element addChild(Element child) { this.content = null; 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) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 49aca167..9b332c94 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -461,11 +461,7 @@ public class XmppConnection implements Runnable { if (this.streamFeatures.hasChild("session")) { Log.d(LOGTAG,"sending session"); IqPacket startSession = new IqPacket(IqPacket.TYPE_SET); - Element session = new Element("session"); - session.setAttribute("xmlns", - "urn:ietf:params:xml:ns:xmpp-session"); - session.setContent(""); - startSession.addChild(session); + startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session"); //setContent("") this.sendIqPacket(startSession, null); } } @@ -484,7 +480,8 @@ public class XmppConnection implements Runnable { IqPacket register = new IqPacket(IqPacket.TYPE_SET); Element username = new Element("username").setContent(account.getUsername()); 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() { @Override @@ -515,14 +512,9 @@ public class XmppConnection implements Runnable { packet.setAttribute("from", account.getFullJid()); if (account.getKeys().has("pgp_signature")) { try { - String signature = account.getKeys().getString("pgp_signature"); - Element status = new Element("status"); - status.setContent("online"); - packet.addChild(status); - Element x = new Element("x"); - x.setAttribute("xmlns", "jabber:x:signed"); - x.setContent(signature); - packet.addChild(x); + String signature = account.getKeys().getString("pgp_signature"); + packet.addChild("status").setContent("online"); + packet.addChild("x","jabber:x:signed").setContent(signature); } catch (JSONException e) { // } @@ -532,12 +524,7 @@ public class XmppConnection implements Runnable { private void sendBindRequest() throws IOException { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); - Element bind = new Element("bind"); - bind.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-bind"); - Element resource = new Element("resource"); - resource.setContent("Conversations"); - bind.addChild(resource); - iq.addChild(bind); + iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind").addChild("resource").setContent("Conversations"); this.sendIqPacket(iq, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -601,9 +588,7 @@ public class XmppConnection implements Runnable { private void sendEnableCarbons() { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); - Element enable = new Element("enable"); - enable.setAttribute("xmlns", "urn:xmpp:carbons:2"); - iq.addChild(enable); + iq.addChild("enable","urn:xmpp:carbons:2"); this.sendIqPacket(iq, new OnIqPacketReceived() { @Override @@ -679,10 +664,8 @@ public class XmppConnection implements Runnable { tagWriter.writeStanzaAsync(new RequestPacket()); } else { IqPacket iq = new IqPacket(IqPacket.TYPE_GET); - Element ping = new Element("ping"); - iq.setAttribute("from",account.getFullJid()); - ping.setAttribute("xmlns", "urn:xmpp:ping"); - iq.addChild(ping); + iq.setFrom(account.getFullJid()); + iq.addChild("ping","urn:xmpp:ping"); this.sendIqPacket(iq, null); } } diff --git a/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java index f70a74dd..8cd1abc0 100644 --- a/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java +++ b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java @@ -39,8 +39,7 @@ public class IqPacket extends AbstractStanza { public Element query() { Element query = findChild("query"); if (query==null) { - query = new Element("query"); - addChild(query); + query = addChild("query"); } return query; } |