Search in sources :

Example 16 with OtrException

use of net.java.otr4j.OtrException in project xabber-android by redsolution.

the class RegularChat method onPacket.

@Override
protected boolean onPacket(UserJid bareAddress, Stanza packet, boolean isCarbons) {
    if (!super.onPacket(bareAddress, packet, isCarbons))
        return false;
    final Resourcepart resource = packet.getFrom().getResourceOrNull();
    if (packet instanceof Presence) {
        final Presence presence = (Presence) packet;
        if (this.resource != null && presence.getType() == Presence.Type.unavailable && resource != null && this.resource.equals(resource)) {
            this.resource = null;
        }
    // if (presence.getType() == Presence.Type.unavailable) {
    // OTRManager.getInstance().onContactUnAvailable(account, user);
    // }
    } else if (packet instanceof Message) {
        final Message message = (Message) packet;
        if (message.getType() == Message.Type.error)
            return true;
        MUCUser mucUser = MUCUser.from(message);
        if (mucUser != null && mucUser.getInvite() != null)
            return true;
        String text = message.getBody();
        if (text == null)
            return true;
        String thread = message.getThread();
        updateThreadId(thread);
        if (resource != null && !resource.equals(Resourcepart.EMPTY)) {
            this.resource = resource;
        }
        boolean encrypted = OTRManager.getInstance().isEncrypted(text);
        if (!isCarbons) {
            try {
                text = OTRManager.getInstance().transformReceiving(account, user, text);
            } catch (OtrException e) {
                if (e.getCause() instanceof OTRUnencryptedException) {
                    text = ((OTRUnencryptedException) e.getCause()).getText();
                    encrypted = false;
                } else {
                    LogManager.exception(this, e);
                    // Invalid message received.
                    return true;
                }
            }
        }
        // System message received.
        if (text == null || text.trim().equals(""))
            return true;
        createAndSaveNewMessage(resource, text, null, getDelayStamp(message), true, true, encrypted, isOfflineMessage(account.getFullJid().getDomain(), packet), packet.getStanzaId());
        EventBus.getDefault().post(new NewIncomingMessageEvent(account, user));
    }
    return true;
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) Presence(org.jivesoftware.smack.packet.Presence) OtrException(net.java.otr4j.OtrException) OTRUnencryptedException(com.xabber.android.data.extension.otr.OTRUnencryptedException) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 17 with OtrException

use of net.java.otr4j.OtrException in project xabber-android by redsolution.

the class OTRManager method onContactUnAvailable.

public void onContactUnAvailable(String account, String user) {
    Session session = sessions.get(account, user);
    if (session == null) {
        return;
    }
    if (session.getSessionStatus() == SessionStatus.ENCRYPTED) {
        try {
            LogManager.i(this, "onContactUnAvailable. Refresh session for " + user);
            session.refreshSession();
        } catch (OtrException e) {
            LogManager.exception(this, e);
        }
    }
}
Also used : OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 18 with OtrException

use of net.java.otr4j.OtrException in project xabber-android by redsolution.

the class OTRManager method initSmp.

/**
     * Initiate request using SM protocol.
     */
public void initSmp(String account, String user, String question, String secret) throws NetworkException {
    LogManager.i(this, "initializing smp... " + user);
    removeSMRequest(account, user);
    addSMProgress(account, user);
    try {
        getOrCreateSession(account, user).initSmp(question, secret);
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 19 with OtrException

use of net.java.otr4j.OtrException in project xabber-android by redsolution.

the class OTRManager method startSession.

public void startSession(String account, String user) throws NetworkException {
    LogManager.i(this, "Starting session for " + user);
    try {
        getOrCreateSession(account, user).startSession();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
    LogManager.i(this, "Started session for " + user);
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 20 with OtrException

use of net.java.otr4j.OtrException in project xabber-android by redsolution.

the class OTRManager method respondSmp.

/**
     * Respond using SM protocol.
     */
public void respondSmp(String account, String user, String question, String secret) throws NetworkException {
    LogManager.i(this, "responding smp... " + user);
    removeSMRequest(account, user);
    addSMProgress(account, user);
    try {
        getOrCreateSession(account, user).respondSmp(question, secret);
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

OtrException (net.java.otr4j.OtrException)23 NetworkException (com.xabber.android.data.NetworkException)11 Session (net.java.otr4j.session.Session)9 AbstractChat (com.xabber.android.data.message.AbstractChat)3 Message (org.jivesoftware.smack.packet.Message)3 OTRUnencryptedException (com.xabber.android.data.extension.otr.OTRUnencryptedException)2 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)2 SessionImpl (net.java.otr4j.session.SessionImpl)2 Presence (org.jivesoftware.smack.packet.Presence)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 RegularChat (com.xabber.android.data.message.RegularChat)1 Account (eu.siacs.conversations.entities.Account)1 PublicKey (java.security.PublicKey)1 OtrCryptoEngine (net.java.otr4j.crypto.OtrCryptoEngine)1 OtrCryptoEngineImpl (net.java.otr4j.crypto.OtrCryptoEngineImpl)1 OtrCryptoException (net.java.otr4j.crypto.OtrCryptoException)1 SessionID (net.java.otr4j.session.SessionID)1 SessionStatus (net.java.otr4j.session.SessionStatus)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1