Search in sources :

Example 1 with Localpart

use of org.jxmpp.jid.parts.Localpart in project xabber-android by redsolution.

the class AccountEditorFragment method setValues.

@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
    if (listener == null) {
        return false;
    }
    ProxyType proxyType = ProxyType.values()[getInt(result, R.string.account_proxy_type_key)];
    if (proxyType == ProxyType.orbot && !OrbotHelper.isOrbotInstalled()) {
        listener.showOrbotDialog();
        return false;
    }
    DomainBareJid serverName;
    Localpart userName;
    Resourcepart resource;
    try {
        serverName = JidCreate.domainBareFrom(getString(result, R.string.account_server_key).trim());
        userName = Localpart.from(getString(result, R.string.account_username_key).trim());
        resource = Resourcepart.from(getString(result, R.string.account_resource_key).trim());
    } catch (XmppStringprepException e) {
        LogManager.exception(this, e);
        return false;
    }
    AccountManager.getInstance().updateAccount(listener.getAccount(), getBoolean(result, R.string.account_custom_key), getString(result, R.string.account_host_key), getInt(result, R.string.account_port_key), serverName, userName, getBoolean(result, R.string.account_store_password_key), getString(result, R.string.account_password_key), "", resource, getInt(result, R.string.account_priority_key), getBoolean(result, R.string.account_enabled_key), getBoolean(result, R.string.account_sasl_key), TLSMode.values()[getInt(result, R.string.account_tls_mode_key)], getBoolean(result, R.string.account_compression_key), proxyType, getString(result, R.string.account_proxy_host_key), getInt(result, R.string.account_proxy_port_key), getString(result, R.string.account_proxy_user_key), getString(result, R.string.account_proxy_password_key), getBoolean(result, R.string.account_syncable_key), ArchiveMode.values()[getInt(result, R.string.account_archive_mode_key)], getInt(result, R.string.account_color_key));
    return true;
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) ProxyType(com.xabber.android.data.connection.ProxyType) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 2 with Localpart

use of org.jxmpp.jid.parts.Localpart 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 3 with Localpart

use of org.jxmpp.jid.parts.Localpart 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 4 with Localpart

use of org.jxmpp.jid.parts.Localpart 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)

Example 5 with Localpart

use of org.jxmpp.jid.parts.Localpart in project xabber-android by redsolution.

the class ConferenceSelectFragment method onNextClick.

private void onNextClick() {
    if (account == null) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_SHORT).show();
        return;
    }
    DomainBareJid server;
    try {
        server = JidCreate.domainBareFrom(serverView.getText().toString());
    } catch (XmppStringprepException e) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_SERVER_NAME), Toast.LENGTH_SHORT).show();
        return;
    }
    Localpart room;
    try {
        room = Localpart.from(roomView.getText().toString());
    } catch (XmppStringprepException e) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_ROOM_NAME), Toast.LENGTH_LONG).show();
        return;
    }
    UserJid roomJid = null;
    try {
        roomJid = UserJid.from(JidCreate.entityBareFrom(room, server));
        startActivity(ConferenceAddActivity.createIntent(getActivity(), account, roomJid));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
    }
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Aggregations

Localpart (org.jxmpp.jid.parts.Localpart)9 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)7 DomainBareJid (org.jxmpp.jid.DomainBareJid)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)4 AccountRealm (com.xabber.android.data.database.realm.AccountRealm)2 Realm (io.realm.Realm)2 HashMap (java.util.HashMap)2 AccountManager (org.jivesoftware.smackx.iqregister.AccountManager)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 NetworkException (com.xabber.android.data.NetworkException)1 ProxyType (com.xabber.android.data.connection.ProxyType)1 UserJid (com.xabber.android.data.entity.UserJid)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1