Search in sources :

Example 41 with XmppStringprepException

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

the class Stanza method setTo.

/**
     * Sets who the stanza(/packet) is being sent "to". The XMPP protocol often makes
     * the "to" attribute optional, so it does not always need to be set.
     *
     * @param to who the stanza(/packet) is being sent to.
     * @throws IllegalArgumentException if to is not a valid JID String.
     * @deprecated use {@link #setTo(Jid)} instead.
     */
@Deprecated
public void setTo(String to) {
    Jid jid;
    try {
        jid = JidCreate.from(to);
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
    setTo(jid);
}
Also used : Jid(org.jxmpp.jid.Jid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 42 with XmppStringprepException

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

the class IntTestUtil method registerAccountViaIbr.

public static UsernameAndPassword registerAccountViaIbr(XMPPConnection connection, String username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    AccountManager accountManager = AccountManager.getInstance(connection);
    if (!accountManager.supportsAccountCreation()) {
        throw new UnsupportedOperationException("Account creation/registation is not supported");
    }
    Set<String> requiredAttributes = accountManager.getAccountAttributes();
    if (requiredAttributes.size() > 4) {
        throw new IllegalStateException("Unkown required attributes");
    }
    Map<String, String> additionalAttributes = new HashMap<>();
    additionalAttributes.put("name", "Smack Integration Test");
    additionalAttributes.put("email", "flow@igniterealtime.org");
    Localpart usernameLocalpart;
    try {
        usernameLocalpart = Localpart.from(username);
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException("Invalid username: " + username, e);
    }
    accountManager.createAccount(usernameLocalpart, password, additionalAttributes);
    return new UsernameAndPassword(username, password);
}
Also used : HashMap(java.util.HashMap) Localpart(org.jxmpp.jid.parts.Localpart) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 43 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Zom-Android by zom.

the class XmppConnection method makeContact.

private Contact makeContact(String address) {
    Contact contact = null;
    // load from roster if we don't have the contact
    RosterEntry rEntry = null;
    try {
        if (mConnection != null)
            rEntry = mRoster.getEntry(JidCreate.bareFrom(address));
        if (rEntry != null) {
            XmppAddress xAddress = new XmppAddress(address);
            String name = rEntry.getName();
            if (name == null)
                name = xAddress.getUser();
            // TODO we should check the type from here
            contact = new Contact(xAddress, name, Imps.Contacts.TYPE_NORMAL);
        } else {
            XmppAddress xAddress = new XmppAddress(address);
            contact = new Contact(xAddress, xAddress.getUser(), Imps.Contacts.TYPE_NORMAL);
        }
    } catch (XmppStringprepException xe) {
    // nothing return null;
    }
    return contact;
}
Also used : RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Contact(org.awesomeapp.messenger.model.Contact)

Example 44 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Zom-Android by zom.

the class ChatSessionAdapter method checkForLinkedMedia.

String checkForLinkedMedia(String jid, String message, boolean allowWebDownloads) {
    Matcher matcher = aesGcmUrlPattern.matcher(message);
    // if we match the aesgcm crypto pattern, then it is a match
    if (matcher.find()) {
        int matchStart = matcher.start(1);
        int matchEnd = matcher.end();
        return message.substring(matchStart, matchEnd);
    } else if (allowWebDownloads) {
        // if someone sends us a random URL, only get it if it is from the same host as the jabberid
        matcher = urlPattern.matcher(message);
        if (matcher.find()) {
            int matchStart = matcher.start(1);
            int matchEnd = matcher.end();
            String urlDownload = message.substring(matchStart, matchEnd);
            try {
                String domain = JidCreate.bareFrom(jid).getDomain().toString();
                // remove the conference subdomain when checking a match to the media upload
                if (domain.contains("conference."))
                    domain = domain.replace("conference.", "");
                if (urlDownload.contains(domain)) {
                    return urlDownload;
                }
            } catch (XmppStringprepException se) {
            // This shouldn't happeN!
            }
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 45 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class ChatFragment method showResourceChoiceAlert.

public void showResourceChoiceAlert(final AccountJid account, final UserJid user, final boolean restartSession) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    final List<Map<String, String>> items = new ArrayList<>();
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
        } else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
            client = getString(R.string.unknown);
        } else {
            String name = clientInfo.getName();
            if (name != null) {
                client = name;
            }
            String type = clientInfo.getType();
            if (type != null) {
                if (client.isEmpty()) {
                    client = type;
                } else {
                    client = client + "/" + type;
                }
            }
        }
        Map<String, String> map = new HashMap<>();
        if (!client.isEmpty()) {
            map.put(ResourceAdapter.KEY_CLIENT, client);
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        if (resourceOrNull != null) {
            map.put(ResourceAdapter.KEY_RESOURCE, resourceOrNull.toString());
            items.add(map);
        }
    }
    final ResourceAdapter adapter = new ResourceAdapter(getActivity(), items);
    adapter.setCheckedItem(checkedResource);
    if (items.size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.otr_select_resource);
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
            }
        });
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
                try {
                    AbstractChat chat = getChat();
                    if (chat instanceof RegularChat) {
                        ((RegularChat) chat).setOTRresource(Resourcepart.from(items.get(checkedResource).get(ResourceAdapter.KEY_RESOURCE)));
                        if (restartSession)
                            restartEncryption(account, user);
                        else
                            startEncryption(account, user);
                    } else {
                        Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                    }
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setSingleChoiceItems(adapter, checkedResource, null).show();
    } else {
        Toast.makeText(getActivity(), R.string.otr_select_toast_resources_not_found, Toast.LENGTH_SHORT).show();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Presence(org.jivesoftware.smack.packet.Presence) ResourceAdapter(com.xabber.android.ui.adapter.ResourceAdapter) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) Map(java.util.Map) HashMap(java.util.HashMap)

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