use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.
the class SSNManager method setSessionOtrMode.
/**
* Sets OTR mode for the session and starts negotiation / renegotiation.
*/
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(DataForm.Type.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);
}
try {
sendFeature(AccountJid.from(account), JidCreate.from(user), session, new Feature(dataForm));
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
}
}
use of org.jivesoftware.smackx.xdata.packet.DataForm 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));
}
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class HttpFileUploadManager method uploadServiceFrom.
private static UploadService uploadServiceFrom(DiscoverInfo discoverInfo) {
assert containsHttpFileUploadNamespace(discoverInfo);
UploadService.Version version;
if (discoverInfo.containsFeature(NAMESPACE)) {
version = Version.v0_3;
} else if (discoverInfo.containsFeature(NAMESPACE_0_2)) {
version = Version.v0_2;
} else {
throw new AssertionError();
}
DomainBareJid address = discoverInfo.getFrom().asDomainBareJid();
DataForm dataForm = DataForm.from(discoverInfo);
if (dataForm == null) {
return new UploadService(address, version);
}
FormField field = dataForm.getField("max-file-size");
if (field == null) {
return new UploadService(address, version);
}
String maxFileSizeValue = field.getFirstValue();
if (maxFileSizeValue == null) {
// there but has no value set.
return new UploadService(address, version);
}
Long maxFileSize = Long.valueOf(maxFileSizeValue);
return new UploadService(address, version, maxFileSize);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class MamManager method queryArchive.
public MamQuery queryArchive(MamQueryArgs mamQueryArgs) throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException {
String queryId = StringUtils.secureUniqueRandomString();
String node = mamQueryArgs.node;
DataForm dataForm = mamQueryArgs.getDataForm(mamVersion);
MamQueryIQ mamQueryIQ = getElementFactory().newQueryIQ(queryId, node, dataForm);
mamQueryIQ.setType(IQ.Type.set);
mamQueryIQ.setTo(archiveAddress);
mamQueryArgs.maybeAddRsmSet(mamQueryIQ);
return queryArchive(mamQueryIQ);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class FiltersTest method checkEndDateFilter.
@Test
public void checkEndDateFilter() throws Exception {
Date date = new Date();
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsBefore(date).build();
DataForm dataForm = mamQueryArgs.getDataForm(MamVersion.MAM2);
List<String> fields = new ArrayList<>();
fields.add("end");
List<String> values = new ArrayList<>();
values.add(XmppDateTime.formatXEP0082Date(date));
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
}
Aggregations