Search in sources :

Example 16 with DataForm

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);
    }
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Feature(com.xabber.xmpp.ssn.Feature)

Example 17 with DataForm

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));
    }
}
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 18 with 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);
}
Also used : Version(org.jivesoftware.smackx.httpfileupload.UploadService.Version) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) DomainBareJid(org.jxmpp.jid.DomainBareJid) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 19 with DataForm

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);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 20 with DataForm

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());
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ArrayList(java.util.ArrayList) Date(java.util.Date) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2