Search in sources :

Example 1 with Feature

use of com.xabber.xmpp.ssn.Feature in project xabber-android by redsolution.

the class SSNManager method setSessionOtrMode.

/**
     * Sets OTR mode for the session and starts negotiation / renegotiation.
     *
     * @param account
     * @param user
     * @param session
     * @param otrMode
     * @throws NetworkException
     */
public void setSessionOtrMode(String account, String user, String session, OtrMode otrMode) {
    if (sessionOtrs.get(account, session) == otrMode)
        return;
    sessionOtrs.put(account, session, otrMode);
    SessionState state = sessionStates.get(account, session);
    DataForm dataForm = Feature.createDataForm(DataFormType.form);
    Feature.addLoggingField(dataForm, otrMode.getLoggingValues(), otrMode.getLoggingValues()[0]);
    Feature.addDisclosureField(dataForm, DisclosureValue.values(), otrMode.getDisclosureValue());
    Feature.addSecurityField(dataForm, SecurityValue.values(), otrMode.getSecurityValue());
    if (state == null || state == SessionState.requesting) {
        sessionStates.put(account, session, SessionState.requesting);
        Feature.addAcceptField(dataForm, true);
    } else {
        sessionStates.put(account, session, SessionState.renegotiation);
        Feature.addRenegotiateField(dataForm, true);
    }
    sendFeature(account, user, session, new Feature(dataForm));
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Example 2 with Feature

use of com.xabber.xmpp.ssn.Feature in project xabber-android by redsolution.

the class SSNManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    String from = packet.getFrom();
    if (from == null)
        return;
    if (!(connection instanceof AccountItem) || !(packet instanceof Message))
        return;
    String account = ((AccountItem) connection).getAccount();
    Message message = (Message) packet;
    String session = message.getThread();
    if (session == null)
        return;
    for (ExtensionElement packetExtension : packet.getExtensions()) if (packetExtension instanceof Feature) {
        Feature feature = (Feature) packetExtension;
        if (!feature.isValid())
            continue;
        DataFormType type = feature.getDataFormType();
        if (type == DataFormType.form)
            onFormReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.submit)
            onSubmitReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.result)
            onResultReceived(account, from, bareAddress, session, feature);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataFormType(com.xabber.xmpp.form.DataFormType) Feature(com.xabber.xmpp.ssn.Feature)

Example 3 with Feature

use of com.xabber.xmpp.ssn.Feature in project xabber-android by redsolution.

the class SSNManager method onTerminateReceived.

private void onTerminateReceived(String account, String from, String session) {
    if (sessionStates.get(account, session) == null)
        return;
    sessionStates.remove(account, session);
    DataForm dataForm = Feature.createDataForm(DataFormType.result);
    Feature.addTerminateField(dataForm);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Example 4 with Feature

use of com.xabber.xmpp.ssn.Feature 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 5 with Feature

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

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