Search in sources :

Example 1 with OtrMode

use of com.xabber.xmpp.archive.OtrMode in project xabber-android by redsolution.

the class SSNManager method onSubmitReceived.

private void onSubmitReceived(String account, String from, String bareAddress, String session, Feature feature) {
    if (feature.getTerminateValue() != null) {
        onTerminateReceived(account, from, session);
        return;
    }
    if (!isAccepted(account, from, bareAddress, session, feature))
        return;
    OtrMode otrMode = getOtrMode(account, bareAddress, session);
    LoggingValue loggingValue = feature.getLoggingValue();
    if (loggingValue == null || otrMode.acceptLoggingValue(loggingValue)) {
        DataForm dataForm = Feature.createDataForm(DataFormType.result);
        if (feature.getAcceptValue() != null)
            Feature.addAcceptField(dataForm, true);
        else
            Feature.addRenegotiateField(dataForm, true);
        sendFeature(account, from, session, new Feature(dataForm));
        sessionStates.put(account, session, SessionState.active);
    } else {
        DataForm dataForm = Feature.createDataForm(DataFormType.result);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account, session);
        } else
            Feature.addRenegotiateField(dataForm, false);
        sendFeature(account, from, session, new Feature(dataForm));
    }
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) OtrMode(com.xabber.xmpp.archive.OtrMode) Feature(com.xabber.xmpp.ssn.Feature)

Example 2 with OtrMode

use of com.xabber.xmpp.archive.OtrMode in project xabber-android by redsolution.

the class SSNManager method onSubmitReceived.

private void onSubmitReceived(AccountJid account, Jid from, String session, Feature feature) {
    if (feature.getTerminateValue() != null) {
        onTerminateReceived(account, from, session);
        return;
    }
    if (!isAccepted(account, session, feature)) {
        return;
    }
    OtrMode otrMode = getOtrMode(account, session);
    LoggingValue loggingValue = feature.getLoggingValue();
    if (loggingValue == null || otrMode.acceptLoggingValue(loggingValue)) {
        DataForm dataForm = Feature.createDataForm(DataForm.Type.result);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, true);
        } else {
            Feature.addRenegotiateField(dataForm, true);
        }
        sendFeature(account, from, session, new Feature(dataForm));
        sessionStates.put(account.toString(), session, SessionState.active);
    } else {
        DataForm dataForm = Feature.createDataForm(DataForm.Type.result);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account.toString(), session);
        } else {
            Feature.addRenegotiateField(dataForm, false);
        }
        sendFeature(account, from, session, new Feature(dataForm));
    }
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) OtrMode(com.xabber.xmpp.archive.OtrMode) Feature(com.xabber.xmpp.ssn.Feature)

Example 3 with OtrMode

use of com.xabber.xmpp.archive.OtrMode in project xabber-android by redsolution.

the class SSNManager method onFormReceived.

private void onFormReceived(AccountJid account, Jid from, String session, Feature feature) {
    OtrMode otrMode = getOtrMode(account, session);
    boolean cancel = false;
    Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions();
    DisclosureValue disclosureValue = DisclosureValue.never;
    if (disclosureValues == null)
        disclosureValue = null;
    else if (!disclosureValues.contains(disclosureValue))
        cancel = true;
    Collection<SecurityValue> securityValues = feature.getSecurityOptions();
    SecurityValue securityValue;
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem != null && accountItem.getConnectionSettings().getTlsMode() == TLSMode.required) {
        securityValue = SecurityValue.c2s;
    } else {
        securityValue = SecurityValue.none;
    }
    if (securityValues == null)
        securityValue = null;
    else if (!securityValues.contains(securityValue))
        cancel = true;
    Collection<LoggingValue> loggingValues = feature.getLoggingOptions();
    LoggingValue loggingValue;
    if (loggingValues == null)
        loggingValue = null;
    else {
        loggingValue = otrMode.selectLoggingValue(loggingValues);
        if (loggingValue == null)
            cancel = true;
    }
    if (cancel) {
        DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account.toString(), session);
        } else {
            Feature.addRenegotiateField(dataForm, false);
        }
        sendFeature(account, from, session, new Feature(dataForm));
        return;
    }
    DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
    if (feature.getAcceptValue() != null)
        Feature.addAcceptField(dataForm, true);
    else
        Feature.addRenegotiateField(dataForm, true);
    if (disclosureValue != null)
        Feature.addDisclosureField(dataForm, null, disclosureValue);
    if (securityValue != null)
        Feature.addSecurityField(dataForm, null, securityValue);
    if (loggingValue != null) {
        Feature.addLoggingField(dataForm, null, loggingValue);
    }
    sessionStates.put(account.toString(), session, SessionState.active);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) AccountItem(com.xabber.android.data.account.AccountItem) DisclosureValue(com.xabber.xmpp.ssn.DisclosureValue) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) OtrMode(com.xabber.xmpp.archive.OtrMode) Feature(com.xabber.xmpp.ssn.Feature) SecurityValue(com.xabber.xmpp.ssn.SecurityValue)

Example 4 with OtrMode

use of com.xabber.xmpp.archive.OtrMode in project xabber-android by redsolution.

the class SSNManager method getOtrMode.

private OtrMode getOtrMode(String account, String bareAddress, String session) {
    OtrMode otrMode = sessionOtrs.get(account, session);
    if (otrMode != null)
        return otrMode;
    otrMode = MessageArchiveManager.getInstance().getOtrMode(account, bareAddress);
    if (otrMode != null)
        return otrMode;
    return OtrMode.concede;
}
Also used : OtrMode(com.xabber.xmpp.archive.OtrMode)

Example 5 with OtrMode

use of com.xabber.xmpp.archive.OtrMode in project xabber-android by redsolution.

the class SSNManager method onFormReceived.

private void onFormReceived(String account, String from, String bareAddress, String session, Feature feature) {
    OtrMode otrMode = getOtrMode(account, bareAddress, session);
    boolean cancel = false;
    Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions();
    DisclosureValue disclosureValue = DisclosureValue.never;
    if (disclosureValues == null)
        disclosureValue = null;
    else if (!disclosureValues.contains(disclosureValue))
        cancel = true;
    Collection<SecurityValue> securityValues = feature.getSecurityOptions();
    SecurityValue securityValue;
    if (AccountManager.getInstance().getAccount(account).getConnectionSettings().getTlsMode() == TLSMode.required)
        securityValue = SecurityValue.c2s;
    else
        securityValue = SecurityValue.none;
    if (securityValues == null)
        securityValue = null;
    else if (!securityValues.contains(securityValue))
        cancel = true;
    Collection<LoggingValue> loggingValues = feature.getLoggingOptions();
    LoggingValue loggingValue;
    if (loggingValues == null)
        loggingValue = null;
    else {
        loggingValue = otrMode.selectLoggingValue(loggingValues);
        if (loggingValue == null)
            cancel = true;
    }
    if (cancel) {
        DataForm dataForm = Feature.createDataForm(DataFormType.submit);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account, session);
        } else {
            Feature.addRenegotiateField(dataForm, false);
        }
        sendFeature(account, from, session, new Feature(dataForm));
        return;
    }
    DataForm dataForm = Feature.createDataForm(DataFormType.submit);
    if (feature.getAcceptValue() != null)
        Feature.addAcceptField(dataForm, true);
    else
        Feature.addRenegotiateField(dataForm, true);
    if (disclosureValue != null)
        Feature.addDisclosureField(dataForm, null, disclosureValue);
    if (securityValue != null)
        Feature.addSecurityField(dataForm, null, securityValue);
    if (loggingValue != null) {
        try {
            if (loggingValue == LoggingValue.mustnot)
                MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.fls);
            else
                MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.body);
        } catch (NetworkException e) {
        }
        Feature.addLoggingField(dataForm, null, loggingValue);
    }
    sessionStates.put(account, session, SessionState.active);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) DisclosureValue(com.xabber.xmpp.ssn.DisclosureValue) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) OtrMode(com.xabber.xmpp.archive.OtrMode) Feature(com.xabber.xmpp.ssn.Feature) NetworkException(com.xabber.android.data.NetworkException) SecurityValue(com.xabber.xmpp.ssn.SecurityValue)

Aggregations

OtrMode (com.xabber.xmpp.archive.OtrMode)5 Feature (com.xabber.xmpp.ssn.Feature)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)4 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2 SecurityValue (com.xabber.xmpp.ssn.SecurityValue)2 NetworkException (com.xabber.android.data.NetworkException)1 AccountItem (com.xabber.android.data.account.AccountItem)1