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));
}
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);
}
}
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));
}
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));
}
}
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));
}
Aggregations