Search in sources :

Example 56 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class FillableForm method setAnswer.

public void setAnswer(String fieldName, Collection<? extends CharSequence> answers) {
    FormField blankField = getFieldOrThrow(fieldName);
    FormField.Type type = blankField.getType();
    FormField filledFormField;
    switch(type) {
        case list_multi:
        case text_multi:
            filledFormField = createMultiKindFieldbuilder(fieldName, type).addValues(answers).build();
            break;
        case jid_multi:
            List<Jid> jids = new ArrayList<>(answers.size());
            List<XmppStringprepException> exceptions = new ArrayList<>();
            JidUtil.jidsFrom(answers, jids, exceptions);
            if (!exceptions.isEmpty()) {
                // TODO: Report all exceptions here.
                throw new IllegalArgumentException(exceptions.get(0));
            }
            filledFormField = FormField.jidMultiBuilder(fieldName).addValues(jids).build();
            break;
        default:
            throw new IllegalArgumentException("");
    }
    write(filledFormField);
}
Also used : Jid(org.jxmpp.jid.Jid) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) AbstractSingleStringValueFormField(org.jivesoftware.smackx.xdata.AbstractSingleStringValueFormField) AbstractMultiFormField(org.jivesoftware.smackx.xdata.AbstractMultiFormField) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 57 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class SignalOmemoStoreConnector method deleteAllSessions.

@Override
public void deleteAllSessions(String s) {
    BareJid jid;
    try {
        jid = JidCreate.bareFrom(s);
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    omemoStore.removeAllRawSessionsOf(getOurDevice(), jid);
}
Also used : BareJid(org.jxmpp.jid.BareJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 58 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class SignalOmemoStoreConnector method deleteSession.

@Override
public void deleteSession(SignalProtocolAddress signalProtocolAddress) {
    OmemoDevice device;
    try {
        device = asOmemoDevice(signalProtocolAddress);
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    omemoStore.removeRawSession(getOurDevice(), device);
}
Also used : OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 59 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class AbstractXMPPConnection method onStreamOpen.

/**
 * Must be called when a XMPP stream open tag is encountered. Sets values like the stream ID and the incoming stream
 * XML environment.
 * <p>
 * This method also returns a matching stream close tag. For example if the stream open is {@code <stream …>}, then
 * {@code </stream>} is returned. But if it is {@code <stream:stream>}, then {@code </stream:stream>} is returned.
 * Or if it is {@code <foo:stream>}, then {@code </foo:stream>} is returned.
 * </p>
 *
 * @param parser an XML parser that is positioned at the start of the stream open.
 * @return a String representing the corresponding stream end tag.
 */
protected String onStreamOpen(XmlPullParser parser) {
    assert StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE.equals(parser.getNamespace()) : parser.getNamespace() + " is not " + StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE;
    assert StreamOpen.UNPREFIXED_ELEMENT.equals(parser.getName());
    streamId = parser.getAttributeValue("id");
    incomingStreamXmlEnvironment = XmlEnvironment.from(parser);
    String reportedServerDomainString = parser.getAttributeValue("from");
    // in c2s connections is required or not.
    if (reportedServerDomainString != null) {
        DomainBareJid reportedServerDomain;
        try {
            reportedServerDomain = JidCreate.domainBareFrom(reportedServerDomainString);
            DomainBareJid configuredXmppServiceDomain = config.getXMPPServiceDomain();
            if (!configuredXmppServiceDomain.equals(reportedServerDomain)) {
                LOGGER.warning("Domain reported by server '" + reportedServerDomain + "' does not match configured domain '" + configuredXmppServiceDomain + "'");
            }
        } catch (XmppStringprepException e) {
            LOGGER.log(Level.WARNING, "XMPP service domain '" + reportedServerDomainString + "' as reported by server could not be transformed to a valid JID", e);
        }
    }
    String prefix = parser.getPrefix();
    if (StringUtils.isNotEmpty(prefix)) {
        return "</" + prefix + ":stream>";
    }
    return "</stream>";
}
Also used : XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 60 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class XmppConnectionManager method disconnectAndCleanup.

void disconnectAndCleanup() throws InterruptedException {
    int successfullyDeletedAccountsCount = 0;
    for (AbstractXMPPConnection connection : connections.keySet()) {
        if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {
            // Note that we use the account manager from the to-be-deleted connection.
            AccountManager accountManager = AccountManager.getInstance(connection);
            try {
                accountManager.deleteAccount();
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
        connection.disconnect();
        if (sinttestConfiguration.accountRegistration == AccountRegistration.serviceAdministration) {
            String username = connection.getConfiguration().getUsername().toString();
            Localpart usernameAsLocalpart;
            try {
                usernameAsLocalpart = Localpart.from(username);
            } catch (XmppStringprepException e) {
                throw new AssertionError(e);
            }
            EntityBareJid connectionAddress = JidCreate.entityBareFrom(usernameAsLocalpart, sinttestConfiguration.service);
            try {
                adminManager.deleteUser(connectionAddress);
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
    }
    if (sinttestConfiguration.isAccountRegistrationPossible()) {
        int unsuccessfullyDeletedAccountsCount = connections.size() - successfullyDeletedAccountsCount;
        if (unsuccessfullyDeletedAccountsCount == 0) {
            LOGGER.info("Successfully deleted all created accounts ✔");
        } else {
            LOGGER.warning("Could not delete all created accounts, " + unsuccessfullyDeletedAccountsCount + " remainaing");
        }
    }
    connections.clear();
    if (accountRegistrationConnection != null) {
        accountRegistrationConnection.disconnect();
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Localpart(org.jxmpp.jid.parts.Localpart) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) EntityBareJid(org.jxmpp.jid.EntityBareJid) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3