Search in sources :

Example 71 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method pushTokenToAppServer.

public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(appServer);
    Element command = packet.addChild("command", "http://jabber.org/protocol/commands");
    command.setAttribute("node", "register-push-gcm");
    command.setAttribute("action", "execute");
    Data data = new Data();
    data.put("token", token);
    data.put("device-id", deviceId);
    data.submit();
    command.addChild(data);
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 72 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method publishVerification.

public IqPacket publishVerification(byte[] signature, X509Certificate[] certificates, final int deviceId) {
    final Element item = new Element("item");
    final Element verification = item.addChild("verification", AxolotlService.PEP_PREFIX);
    final Element chain = verification.addChild("chain");
    for (int i = 0; i < certificates.length; ++i) {
        try {
            Element certificate = chain.addChild("certificate");
            certificate.setContent(Base64.encodeToString(certificates[i].getEncoded(), Base64.DEFAULT));
            certificate.setAttribute("index", i);
        } catch (CertificateEncodingException e) {
            Log.d(Config.LOGTAG, "could not encode certificate");
        }
    }
    verification.addChild("signature").setContent(Base64.encodeToString(signature, Base64.DEFAULT));
    return publish(AxolotlService.PEP_VERIFICATION + ":" + deviceId, item);
}
Also used : Element(eu.siacs.conversations.xml.Element) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 73 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method publishBundles.

public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey, final Set<PreKeyRecord> preKeyRecords, final int deviceId) {
    final Element item = new Element("item");
    final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
    final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
    signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
    ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
    signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.DEFAULT));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.DEFAULT));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));
    final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
    for (PreKeyRecord preKeyRecord : preKeyRecords) {
        final Element prekey = prekeys.addChild("preKeyPublic");
        prekey.setAttribute("preKeyId", preKeyRecord.getId());
        prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
    }
    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item);
}
Also used : ECPublicKey(org.whispersystems.libaxolotl.ecc.ECPublicKey) Element(eu.siacs.conversations.xml.Element) PreKeyRecord(org.whispersystems.libaxolotl.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libaxolotl.state.SignedPreKeyRecord)

Example 74 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class Bookmark method getTags.

@Override
public List<Tag> getTags(Context context) {
    ArrayList<Tag> tags = new ArrayList<>();
    for (Element element : getChildren()) {
        if (element.getName().equals("group") && element.getContent() != null) {
            String group = element.getContent();
            tags.add(new Tag(group, UIHelper.getColorForName(group)));
        }
    }
    return tags;
}
Also used : Element(eu.siacs.conversations.xml.Element) ArrayList(java.util.ArrayList)

Example 75 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class Bookmark method setNick.

public void setNick(String nick) {
    Element element = this.findChild("nick");
    if (element == null) {
        element = this.addChild("nick");
    }
    element.setContent(nick);
}
Also used : Element(eu.siacs.conversations.xml.Element)

Aggregations

Element (eu.siacs.conversations.xml.Element)93 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)43 Account (eu.siacs.conversations.entities.Account)21 Jid (eu.siacs.conversations.xmpp.jid.Jid)17 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)16 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Contact (eu.siacs.conversations.entities.Contact)7 Conversation (eu.siacs.conversations.entities.Conversation)6 ArrayList (java.util.ArrayList)6 Data (eu.siacs.conversations.xmpp.forms.Data)5 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)5 IOException (java.io.IOException)5 MucOptions (eu.siacs.conversations.entities.MucOptions)4 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)4 Pair (android.util.Pair)3 Bookmark (eu.siacs.conversations.entities.Bookmark)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3