Search in sources :

Example 11 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class XmppConnectionService method sendUnblockRequest.

public void sendUnblockRequest(final Blockable blockable) {
    if (blockable != null && blockable.getJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetUnblockRequest(jid), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().remove(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.UNBLOCKED);
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 12 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    this.account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    this.mime = this.file.getMimeType();
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        this.key = new byte[48];
        mXmppConnectionService.getRNG().nextBytes(this.key);
        this.file.setKeyAndIv(this.key);
    }
    Pair<InputStream, Integer> pair;
    try {
        pair = AbstractConnectionManager.createInputStream(file, true);
    } catch (FileNotFoundException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
        fail(e.getMessage());
        return;
    }
    this.file.setExpectedSize(pair.second);
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
                if (slot != null) {
                    try {
                        mGetUrl = new URL(slot.findChildContent("get"));
                        mPutUrl = new URL(slot.findChildContent("put"));
                        if (!canceled) {
                            new Thread(new FileUploader()).start();
                        }
                        return;
                    } catch (MalformedURLException e) {
                    //fall through
                    }
                }
            }
            Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
            fail(IqParser.extractErrorMessage(packet));
        }
    });
    message.setTransferable(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
Also used : Account(eu.siacs.conversations.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) InputStream(java.io.InputStream) Element(eu.siacs.conversations.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 13 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class JingleConnection method receiveFallbackToIbb.

private boolean receiveFallbackToIbb(JinglePacket packet) {
    Log.d(Config.LOGTAG, "receiving fallack to ibb");
    String receivedBlockSize = packet.getJingleContent().ibbTransport().getAttribute("block-size");
    if (receivedBlockSize != null) {
        int bs = Integer.parseInt(receivedBlockSize);
        if (bs > this.ibbBlockSize) {
            this.ibbBlockSize = bs;
        }
    }
    this.transportId = packet.getJingleContent().getTransportId();
    this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
    JinglePacket answer = bootstrapPacket("transport-accept");
    Content content = new Content("initiator", "a-file-offer");
    content.setTransportId(this.transportId);
    content.ibbTransport().setAttribute("block-size", this.ibbBlockSize);
    answer.setContent(content);
    if (initiator.equals(account.getJid())) {
        this.sendJinglePacket(answer, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " recipient ACKed our transport-accept. creating ibb");
                    transport.connect(onIbbTransportConnected);
                }
            }
        });
    } else {
        this.transport.receive(file, onFileTransmissionSatusChanged);
        this.sendJinglePacket(answer);
    }
    return true;
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 14 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class JingleConnection method connect.

private void connect() {
    final JingleSocks5Transport connection = chooseConnection();
    this.transport = connection;
    if (connection == null) {
        Log.d(Config.LOGTAG, "could not find suitable candidate");
        this.disconnectSocks5Connections();
        if (this.initiator.equals(account.getJid())) {
            this.sendFallbackToIbb();
        }
    } else {
        this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
        if (connection.needsActivation()) {
            if (connection.getCandidate().isOurs()) {
                final String sid;
                if (ftVersion == Content.Version.FT_3) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": use session ID instead of transport ID to activate proxy");
                    sid = getSessionId();
                } else {
                    sid = getTransportId();
                }
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was our proxy. going to activate");
                IqPacket activation = new IqPacket(IqPacket.TYPE.SET);
                activation.setTo(connection.getCandidate().getJid());
                activation.query("http://jabber.org/protocol/bytestreams").setAttribute("sid", sid);
                activation.query().addChild("activate").setContent(this.getCounterPart().toString());
                mXmppConnectionService.sendIqPacket(account, activation, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        if (packet.getType() != IqPacket.TYPE.RESULT) {
                            onProxyActivated.failed();
                        } else {
                            onProxyActivated.success();
                            sendProxyActivated(connection.getCandidate().getCid());
                        }
                    }
                });
            } else {
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was a proxy. waiting for other party to activate");
            }
        } else {
            if (initiator.equals(account.getJid())) {
                Log.d(Config.LOGTAG, "we were initiating. sending file");
                connection.send(file, onFileTransmissionSatusChanged);
            } else {
                Log.d(Config.LOGTAG, "we were responding. receiving file");
                connection.receive(file, onFileTransmissionSatusChanged);
            }
        }
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 15 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)33 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)33 Element (eu.siacs.conversations.xml.Element)16 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)4 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)4 Conversation (eu.siacs.conversations.entities.Conversation)3 HashSet (java.util.HashSet)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libaxolotl.UntrustedIdentityException)3 Bundle (android.os.Bundle)2 Pair (android.util.Pair)2 Contact (eu.siacs.conversations.entities.Contact)2 Data (eu.siacs.conversations.xmpp.forms.Data)2 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)2 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)2 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)2 FileNotFoundException (java.io.FileNotFoundException)2