Search in sources :

Example 1 with DisclosureValue

use of com.xabber.xmpp.ssn.DisclosureValue 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

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