Search in sources :

Example 26 with XmppStringprepException

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

the class ConferenceFilterActivity method restoreConferenceList.

public static List<HostedRoom> restoreConferenceList(Bundle bundleExtra) {
    List<String> conferencesNames = bundleExtra.getStringArrayList(ARG_CONFERENCE_LIST_NAMES);
    List<String> conferencesJids = bundleExtra.getStringArrayList(ARG_CONFERENCE_LIST_JIDS);
    List<HostedRoom> conferences = new ArrayList<>();
    if (conferencesNames != null && conferencesJids != null && conferencesNames.size() == conferencesJids.size()) {
        for (int i = 0; i < conferencesNames.size(); i++) {
            try {
                DiscoverItems.Item item = new DiscoverItems.Item(JidCreate.from(conferencesJids.get(i)));
                item.setName(conferencesNames.get(i));
                conferences.add(new HostedRoom(item));
            } catch (XmppStringprepException e) {
                LogManager.exception(LOG_TAG, e);
            }
        }
    }
    return conferences;
}
Also used : ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) HostedRoom(org.jivesoftware.smackx.muc.HostedRoom)

Example 27 with XmppStringprepException

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

the class ChatActivity method handleOtrIntent.

private void handleOtrIntent(Intent intent) {
    String account = intent.getStringExtra(KEY_ACCOUNT);
    String user = intent.getStringExtra(KEY_USER);
    String question = intent.getStringExtra(KEY_QUESTION);
    if (account != null && user != null) {
        try {
            AccountJid accountJid = AccountJid.from(account);
            UserJid userJid = UserJid.from(user);
            AbstractChat chat = MessageManager.getInstance().getOrCreateChat(accountJid, userJid);
            if (chat != null && chat instanceof RegularChat) {
                if (intent.getBooleanExtra(EXTRA_OTR_PROGRESS, false)) {
                    ((RegularChat) chat).setIntent(QuestionActivity.createCancelIntent(Application.getInstance(), accountJid, userJid));
                } else {
                    ((RegularChat) chat).setIntent(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question));
                }
            }
        } catch (UserJid.UserJidCreateException | XmppStringprepException e) {
            e.printStackTrace();
        }
    }
    getIntent().removeExtra(EXTRA_OTR_REQUEST);
    getIntent().removeExtra(EXTRA_OTR_PROGRESS);
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat)

Example 28 with XmppStringprepException

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

the class AccountManager method onPreInitialize.

public void onPreInitialize() {
    Realm realm = RealmManager.getInstance().getRealmUiThread();
    RealmResults<AccountRealm> accountRealms = realm.where(AccountRealm.class).findAll();
    for (AccountRealm accountRealm : accountRealms) {
        DomainBareJid serverName = null;
        try {
            serverName = JidCreate.domainBareFrom(accountRealm.getServerName());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        Localpart userName = null;
        try {
            userName = Localpart.from(accountRealm.getUserName());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        Resourcepart resource = null;
        try {
            resource = Resourcepart.from(accountRealm.getResource());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        if (serverName == null || userName == null || resource == null) {
            LogManager.e(LOG_TAG, "could not create account. username " + userName + ", server name " + serverName + ", resource " + resource);
            continue;
        }
        if (accountRealm.isEnabled())
            cachedEnabledAccounts.add(AccountJid.from(userName, serverName, resource));
    }
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Realm(io.realm.Realm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) DomainBareJid(org.jxmpp.jid.DomainBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 29 with XmppStringprepException

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

the class AccountManager method addAccount.

/**
 * Creates new account.
 *
 * @param user full or bare jid.
 * @return assigned account name.
 * @throws NetworkException if user or server part are invalid.
 */
public AccountJid addAccount(String user, String password, String token, boolean syncable, boolean storePassword, boolean xabberSync, boolean useOrbot, boolean registerNewAccount, boolean enabled, boolean tlsRequired) throws NetworkException {
    if (user == null) {
        throw new NetworkException(R.string.EMPTY_USER_NAME);
    }
    if (user.contains(" ")) {
        throw new NetworkException(R.string.INCORRECT_USER_NAME);
    }
    DomainBareJid serverName;
    try {
        serverName = JidCreate.domainBareFrom(user);
    } catch (XmppStringprepException e) {
        throw new NetworkException(R.string.INCORRECT_USER_NAME);
    }
    Localpart userName;
    try {
        userName = Localpart.from(XmppStringUtils.parseLocalpart(user));
    } catch (XmppStringprepException e) {
        throw new NetworkException(R.string.INCORRECT_USER_NAME);
    }
    if (isAccountExist(user))
        throw new NetworkException(R.string.ACCOUNT_EXIST);
    Resourcepart resource = null;
    String resourceString = XmppStringUtils.parseResource(user).trim();
    if (!TextUtils.isEmpty(resourceString)) {
        try {
            resource = Resourcepart.from(resourceString);
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
    }
    String host = serverName.getDomain().toString();
    int port = 5222;
    if (resource == null) {
        resource = generateResource();
    }
    AccountItem accountItem;
    boolean useCustomHost = application.getResources().getBoolean(R.bool.account_use_custom_host_default);
    boolean useCompression = application.getResources().getBoolean(R.bool.account_use_compression_default);
    ArchiveMode archiveMode = ArchiveMode.valueOf(application.getString(R.string.account_archive_mode_default_value));
    accountItem = addAccount(useCustomHost, host, port, serverName, userName, storePassword, password, token, resource, getNextColorIndex(), getNextOrder(), false, XabberAccountManager.getInstance().getCurrentTime(), 0, StatusMode.available, SettingsManager.statusText(), enabled, true, tlsRequired ? TLSMode.required : TLSMode.enabled, useCompression, useOrbot ? ProxyType.orbot : ProxyType.none, "localhost", 8080, "", "", syncable, null, null, archiveMode, registerNewAccount);
    if (accountItem == null) {
        throw new NetworkException(R.string.ACCOUNT_REGISTER_FAILED);
    }
    onAccountChanged(accountItem.getAccount());
    if (accountItems.size() > 1 && SettingsManager.contactsEnableShowAccounts()) {
        SettingsManager.enableContactsShowAccount();
    }
    // add xmpp account settings
    if (xabberSync)
        XabberAccountManager.getInstance().addAccountSyncState(accountItem.getAccount().getFullJid().asBareJid().toString(), true);
    else
        SettingsManager.setSyncAllAccounts(false);
    return accountItem.getAccount();
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NetworkException(com.xabber.android.data.NetworkException) DomainBareJid(org.jxmpp.jid.DomainBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 30 with XmppStringprepException

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

the class AccountManager method onLoad.

@Override
public void onLoad() {
    final Collection<SavedStatus> savedStatuses = loadSavedStatuses();
    final Collection<AccountItem> accountItems = new ArrayList<>();
    Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
    RealmResults<AccountRealm> accountRealms = realm.where(AccountRealm.class).findAll();
    LogManager.i(LOG_TAG, "onLoad got realm accounts: " + accountRealms.size());
    for (AccountRealm accountRealm : accountRealms) {
        DomainBareJid serverName = null;
        try {
            serverName = JidCreate.domainBareFrom(accountRealm.getServerName());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        Localpart userName = null;
        try {
            userName = Localpart.from(accountRealm.getUserName());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        Resourcepart resource = null;
        try {
            resource = Resourcepart.from(accountRealm.getResource());
        } catch (XmppStringprepException e) {
            LogManager.exception(this, e);
        }
        if (serverName == null || userName == null || resource == null) {
            LogManager.e(LOG_TAG, "could not create account. username " + userName + ", server name " + serverName + ", resource " + resource);
            continue;
        }
        // fix for db migration
        int order = accountRealm.getOrder();
        if (order == 0) {
            for (AccountItem item : accountItems) {
                if (item.getOrder() > order)
                    order = item.getOrder();
            }
            order++;
        }
        AccountItem accountItem = new AccountItem(accountRealm.isCustom(), accountRealm.getHost(), accountRealm.getPort(), serverName, userName, resource, accountRealm.isStorePassword(), accountRealm.getPassword(), accountRealm.getToken(), accountRealm.getXToken() != null ? XTokenManager.xTokenRealmToXToken(accountRealm.getXToken()) : null, accountRealm.getColorIndex(), order, accountRealm.isSyncNotAllowed(), accountRealm.getTimestamp(), accountRealm.getPriority(), accountRealm.getStatusMode(), accountRealm.getStatusText(), accountRealm.isEnabled(), accountRealm.isSaslEnabled(), accountRealm.getTlsMode(), accountRealm.isCompression(), accountRealm.getProxyType(), accountRealm.getProxyHost(), accountRealm.getProxyPort(), accountRealm.getProxyUser(), accountRealm.getProxyPassword(), accountRealm.isSyncable(), accountRealm.getKeyPair(), accountRealm.getLastSync(), accountRealm.getArchiveMode(), accountRealm.isXabberAutoLoginEnabled());
        accountItem.setId(accountRealm.getId());
        accountItem.setClearHistoryOnExit(accountRealm.isClearHistoryOnExit());
        if (accountRealm.getMamDefaultBehavior() != null) {
            accountItem.setMamDefaultBehaviour(accountRealm.getMamDefaultBehavior());
        }
        if (accountRealm.getLoadHistorySettings() != null) {
            accountItem.setLoadHistorySettings(accountRealm.getLoadHistorySettings());
        }
        accountItem.setSuccessfulConnectionHappened(accountRealm.isSuccessfulConnectionHappened());
        accountItem.setPushNode(accountRealm.getPushNode());
        accountItem.setPushServiceJid(accountRealm.getPushServiceJid());
        accountItem.setPushEnabled(accountRealm.isPushEnabled());
        accountItem.setPushWasEnabled(accountRealm.isPushWasEnabled());
        accountItems.add(accountItem);
    }
    realm.close();
    Application.getInstance().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            onLoaded(savedStatuses, accountItems);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Localpart(org.jxmpp.jid.parts.Localpart) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) Realm(io.realm.Realm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) DomainBareJid(org.jxmpp.jid.DomainBareJid)

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