Search in sources :

Example 41 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class JingleConnectionManager method deliverIbbPacket.

public void deliverIbbPacket(Account account, IqPacket packet) {
    String sid = null;
    Element payload = null;
    if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("open", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    } else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    } else if (packet.hasChild("close", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("close", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    }
    if (sid != null) {
        for (JingleConnection connection : connections) {
            if (connection.getAccount() == account && connection.hasTransportId(sid)) {
                JingleTransport transport = connection.getTransport();
                if (transport instanceof JingleInbandTransport) {
                    JingleInbandTransport inbandTransport = (JingleInbandTransport) transport;
                    inbandTransport.deliverPayload(packet, payload);
                    return;
                }
            }
        }
        Log.d(Config.LOGTAG, "couldn't deliver payload: " + payload.toString());
    } else {
        Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
    }
}
Also used : Element(de.pixart.messenger.xml.Element)

Example 42 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

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(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(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(de.pixart.messenger.xml.Element) IOException(java.io.IOException) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 43 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 44 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class Content method ibbTransport.

public Element ibbTransport() {
    Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:ibb:1");
    if (transport == null) {
        transport = this.addChild("transport", "urn:xmpp:jingle:transports:ibb:1");
        transport.setAttribute("sid", this.transportId);
    }
    return transport;
}
Also used : Element(de.pixart.messenger.xml.Element)

Example 45 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.xml.Element)

Aggregations

Element (de.pixart.messenger.xml.Element)100 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)48 Account (de.pixart.messenger.entities.Account)23 Jid (de.pixart.messenger.xmpp.jid.Jid)19 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)17 Contact (de.pixart.messenger.entities.Contact)9 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)8 ArrayList (java.util.ArrayList)7 Conversation (de.pixart.messenger.entities.Conversation)6 IOException (java.io.IOException)6 Data (de.pixart.messenger.xmpp.forms.Data)5 Avatar (de.pixart.messenger.xmpp.pep.Avatar)5 HashSet (java.util.HashSet)5 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)4 MucOptions (de.pixart.messenger.entities.MucOptions)4 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)4 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)4 Pair (android.util.Pair)3 Bookmark (de.pixart.messenger.entities.Bookmark)3 Message (de.pixart.messenger.entities.Message)3