Search in sources :

Example 31 with Element

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

the class AxolotlService method publishOwnDeviceIdIfNeeded.

public void publishOwnDeviceIdIfNeeded() {
    if (pepBroken) {
        Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... ");
        return;
    }
    IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid());
    mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                Log.d(Config.LOGTAG, getLogprefix(account) + "Timeout received while retrieving own Device Ids.");
            } else {
                Element item = mXmppConnectionService.getIqParser().getItem(packet);
                Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved own device list: " + deviceIds);
                registerDevices(account.getJid().toBareJid(), deviceIds);
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Set(java.util.Set) HashSet(java.util.HashSet) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 32 with Element

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

the class JingleInbandTransport method sendClose.

private void sendClose() {
    IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.setTo(this.counterpart);
    Element close = iq.addChild("close", "http://jabber.org/protocol/ibb");
    close.setAttribute("sid", this.sessionId);
    this.account.getXmppConnection().sendIqPacket(iq, null);
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 33 with Element

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

the class JingleInbandTransport method sendNextBlock.

private void sendNextBlock() {
    byte[] buffer = new byte[this.blockSize];
    try {
        int count = fileInputStream.read(buffer);
        if (count == -1) {
            sendClose();
            file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
            this.onFileTransmissionStatusChanged.onFileTransmitted(file);
            fileInputStream.close();
            return;
        } else if (count != buffer.length) {
            int rem = fileInputStream.read(buffer, count, buffer.length - count);
            if (rem > 0) {
                count += rem;
            }
        }
        this.remainingSize -= count;
        this.digest.update(buffer, 0, count);
        String base64 = Base64.encodeToString(buffer, 0, count, Base64.NO_WRAP);
        IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        iq.setTo(this.counterpart);
        Element data = iq.addChild("data", "http://jabber.org/protocol/ibb");
        data.setAttribute("seq", Integer.toString(this.seq));
        data.setAttribute("block-size", Integer.toString(this.blockSize));
        data.setAttribute("sid", this.sessionId);
        data.setContent(base64);
        this.account.getXmppConnection().sendIqPacket(iq, this.onAckReceived);
        //don't fill up stanza queue too much
        this.account.getXmppConnection().r();
        this.seq++;
        if (this.remainingSize > 0) {
            connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
        } else {
            sendClose();
            file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
            this.onFileTransmissionStatusChanged.onFileTransmitted(file);
            fileInputStream.close();
        }
    } catch (IOException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": io exception during sendNextBlock() " + e.getMessage());
        FileBackend.close(fileInputStream);
        this.onFileTransmissionStatusChanged.onFileTransferAborted();
    }
}
Also used : Element(eu.siacs.conversations.xml.Element) IOException(java.io.IOException) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 34 with Element

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

the class Content method setFileOffer.

public Element setFileOffer(DownloadableFile actualFile, boolean otr, Version version) {
    Element description = this.addChild("description", version.namespace);
    Element file;
    if (version == Version.FT_3) {
        Element offer = description.addChild("offer");
        file = offer.addChild("file");
    } else {
        file = description.addChild("file");
    }
    file.addChild("size").setContent(Long.toString(actualFile.getExpectedSize()));
    if (otr) {
        file.addChild("name").setContent(actualFile.getName() + ".otr");
    } else {
        file.addChild("name").setContent(actualFile.getName());
    }
    return file;
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 35 with Element

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

the class Content method socks5transport.

public Element socks5transport() {
    Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
    if (transport == null) {
        transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
        transport.setAttribute("sid", this.transportId);
    }
    return transport;
}
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