aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Account.java10
-rw-r--r--src/main/java/de/pixart/messenger/entities/Bookmark.java5
-rw-r--r--src/main/java/de/pixart/messenger/entities/Contact.java4
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java4
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/AvatarService.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java23
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/EnterJidDialog.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java5
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java18
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java4
-rw-r--r--src/main/java/de/pixart/messenger/utils/GeoHelper.java2
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java197
17 files changed, 148 insertions, 146 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java
index 4dcd028ba..8d750bf5c 100644
--- a/src/main/java/de/pixart/messenger/entities/Account.java
+++ b/src/main/java/de/pixart/messenger/entities/Account.java
@@ -236,7 +236,7 @@ public class Account extends AbstractEntity {
protected Jid jid;
protected String password;
protected int options = 0;
- protected String rosterVersion;
+ private String rosterVersion;
protected State status = State.OFFLINE;
protected final JSONObject keys;
protected String resource;
@@ -346,8 +346,8 @@ public class Account extends AbstractEntity {
return next != null && !next.equals(previousFull);
}
- public Jid getServer() {
- return Jid.ofDomain(jid.getDomain());
+ public String getServer() {
+ return jid.getDomain();
}
public String getPassword() {
@@ -367,8 +367,8 @@ public class Account extends AbstractEntity {
}
public boolean isOnion() {
- final Jid server = getServer();
- return server != null && server.toString().toLowerCase().endsWith(".onion");
+ final String server = getServer();
+ return server != null && server.endsWith(".onion");
}
public void setPort(int port) {
diff --git a/src/main/java/de/pixart/messenger/entities/Bookmark.java b/src/main/java/de/pixart/messenger/entities/Bookmark.java
index 8388d48f8..46b5ace06 100644
--- a/src/main/java/de/pixart/messenger/entities/Bookmark.java
+++ b/src/main/java/de/pixart/messenger/entities/Bookmark.java
@@ -1,6 +1,7 @@
package de.pixart.messenger.entities;
import android.content.Context;
+import android.support.annotation.NonNull;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -46,7 +47,7 @@ public class Bookmark extends Element implements ListItem {
}
@Override
- public int compareTo(final ListItem another) {
+ public int compareTo(final @NonNull ListItem another) {
return this.getDisplayName().compareToIgnoreCase(
another.getDisplayName());
}
@@ -55,7 +56,7 @@ public class Bookmark extends Element implements ListItem {
public String getDisplayName() {
final Conversation c = getConversation();
if (c != null) {
- return c.getName();
+ return c.getName().toString();
} else if (getBookmarkName() != null
&& !getBookmarkName().trim().isEmpty()) {
return getBookmarkName().trim();
diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java
index 76dd916f8..2af40e1fb 100644
--- a/src/main/java/de/pixart/messenger/entities/Contact.java
+++ b/src/main/java/de/pixart/messenger/entities/Contact.java
@@ -442,8 +442,8 @@ public class Contact implements ListItem, Blockable {
another.getDisplayName());
}
- public Jid getServer() {
- return Jid.ofDomain(getJid().getDomain());
+ public String getServer() {
+ return getJid().getDomain();
}
public boolean setAvatar(Avatar avatar) {
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 81c52aa1c..3f66f93b6 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -501,7 +501,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
- public String getName() {
+ public CharSequence getName() {
if (getMode() == MODE_MULTI) {
final String subject = getMucOptions().getSubject();
Bookmark bookmark = getBookmark();
@@ -520,7 +520,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
} else if (isWithStranger()) {
- return contactJid.asBareJid().toString();
+ return contactJid;
} else {
return this.getContact().getDisplayName();
}
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index a8f7d2e0c..1abbed25a 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -302,7 +302,7 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket generateSetPassword(final Account account, final String newPassword) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
- packet.setTo(account.getServer());
+ packet.setTo(Jid.of(account.getServer()));
final Element query = packet.addChild("query", Namespace.REGISTER);
final Jid jid = account.getJid();
query.addChild("username").setContent(jid.getLocal());
@@ -380,7 +380,7 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
register.setFrom(account.getJid().asBareJid());
- register.setTo(account.getServer());
+ register.setTo(Jid.of(account.getServer()));
register.setId(id);
Element query = register.query("jabber:iq:register");
if (data != null) {
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java
index 4e3ed756b..96114727e 100644
--- a/src/main/java/de/pixart/messenger/services/AvatarService.java
+++ b/src/main/java/de/pixart/messenger/services/AvatarService.java
@@ -220,7 +220,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
if (users.size() == 0) {
Conversation c = mucOptions.getConversation();
- bitmap = getImpl(c.getName(), c.getJid().asBareJid().toString(), size);
+ bitmap = getImpl(c.getName().toString(), c.getJid().asBareJid().toString(), size);
} else {
bitmap = getImpl(users, size);
}
diff --git a/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java b/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java
index 53a7b6625..e05c719dc 100644
--- a/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java
+++ b/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java
@@ -46,7 +46,7 @@ public class ContactChooserTargetService extends ChooserTargetService implements
final int pixel = (int) (48 * getResources().getDisplayMetrics().density);
for (int i = 0; i < Math.min(conversations.size(), MAX_TARGETS); ++i) {
final Conversation conversation = conversations.get(i);
- final String name = conversation.getName();
+ final String name = conversation.getName().toString();
final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
final float score = 1 - (1.0f / MAX_TARGETS) * i;
final Bundle extras = new Bundle();
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index ad6c9f518..64c168a1b 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -350,7 +350,7 @@ public class NotificationService {
for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
conversation = messages.get(0).getConversation();
- final String name = conversation.getName();
+ final String name = conversation.getName().toString();
SpannableString styledString;
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
@@ -389,7 +389,7 @@ public class NotificationService {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
if (messages.size() >= 1) {
final Conversation conversation = messages.get(0).getConversation();
- final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName());
+ final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName().toString());
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
.get(conversation, getPixel(64)));
mBuilder.setContentTitle(conversation.getName());
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 6f6c4188b..5c19a9de2 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -65,6 +65,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -3753,42 +3754,40 @@ public class XmppConnectionService extends Service {
}
- public List<String> getKnownHosts() {
- final List<String> hosts = new ArrayList<>();
+ public Collection<String> getKnownHosts() {
+ final Set<String> hosts = new HashSet<>();
for (final Account account : getAccounts()) {
- if (!hosts.contains(account.getServer().toString())) {
- hosts.add(account.getServer().toString());
- }
+ hosts.add(account.getServer());
for (final Contact contact : account.getRoster().getContacts()) {
if (contact.showInRoster()) {
- final String server = contact.getServer().toString();
+ final String server = contact.getServer();
if (server != null && !hosts.contains(server)) {
hosts.add(server);
}
}
}
}
- if (Config.DOMAIN_LOCK != null && !hosts.contains(Config.DOMAIN_LOCK)) {
+ if (Config.DOMAIN_LOCK != null) {
hosts.add(Config.DOMAIN_LOCK);
}
- if (Config.MAGIC_CREATE_DOMAIN != null && !hosts.contains(Config.MAGIC_CREATE_DOMAIN)) {
+ if (Config.MAGIC_CREATE_DOMAIN != null) {
hosts.add(Config.MAGIC_CREATE_DOMAIN);
}
return hosts;
}
- public List<String> getKnownConferenceHosts() {
- final ArrayList<String> mucServers = new ArrayList<>();
+ public Collection<String> getKnownConferenceHosts() {
+ final Set<String> mucServers = new HashSet<>();
for (final Account account : accounts) {
if (account.getXmppConnection() != null) {
final String server = account.getXmppConnection().getMucServer();
- if (server != null && !mucServers.contains(server)) {
+ if (server != null) {
mucServers.add(server);
}
for (Bookmark bookmark : account.getBookmarks()) {
final Jid jid = bookmark.getJid();
final String s = jid == null ? null : jid.getDomain();
- if (s != null && !mucServers.contains(s)) {
+ if (s != null) {
mucServers.add(s);
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index 7fb1dd349..26faf003e 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -5,8 +5,8 @@ import android.text.Editable;
import android.widget.Toast;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
@@ -15,7 +15,7 @@ import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import rocks.xmpp.addr.Jid;
public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist {
- private List<String> mKnownHosts = new ArrayList<>();
+ private Collection<String> mKnownHosts = new ArrayList<>();
private Account account = null;
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index a6203215a..64e47b1f3 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -17,6 +17,7 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -37,7 +38,7 @@ import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
private List<String> mActivatedAccounts = new ArrayList<>();
- private List<String> mKnownHosts;
+ private Collection<String> mKnownHosts;
private Set<Contact> selected;
private Set<String> filterContacts;
diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
index 713279422..ef1745fd9 100644
--- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
@@ -10,6 +10,7 @@ import android.widget.AutoCompleteTextView;
import android.widget.Spinner;
import android.widget.TextView;
+import java.util.Collection;
import java.util.List;
import de.pixart.messenger.Config;
@@ -40,7 +41,7 @@ public class EnterJidDialog {
protected OnEnterJidDialogPositiveListener listener = null;
public EnterJidDialog(
- final Context context, List<String> knownHosts, final List<String> activatedAccounts,
+ final Context context, Collection<String> knownHosts, final List<String> activatedAccounts,
final String title, final String positiveButton,
final String prefilledJid, final String account, boolean allowEditJid, boolean multipleAccounts
) {
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index 6e2135780..43e81b1f9 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -52,6 +52,7 @@ import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -89,8 +90,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private List<ListItem> conferences = new ArrayList<>();
private ListItemAdapter mConferenceAdapter;
private List<String> mActivatedAccounts = new ArrayList<>();
- private List<String> mKnownHosts;
- private List<String> mKnownConferenceHosts;
+ private Collection<String> mKnownHosts;
+ private Collection<String> mKnownConferenceHosts;
private Invite mPendingInvite = null;
private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
index ad1f9df7b..078efdb60 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
@@ -9,6 +9,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import android.view.LayoutInflater;
@@ -31,8 +32,10 @@ import de.pixart.messenger.ui.ConversationFragment;
import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.ui.util.Color;
import de.pixart.messenger.utils.EmojiWrapper;
+import de.pixart.messenger.utils.IrregularUnicodeDetector;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.chatstate.ChatState;
+import rocks.xmpp.addr.Jid;
public class ConversationAdapter extends ArrayAdapter<Conversation> {
@@ -45,7 +48,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
this.activity = activity;
}
- public static boolean cancelPotentialWork(Conversation conversation, ImageView imageView) {
+ private static boolean cancelPotentialWork(Conversation conversation, ImageView imageView) {
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
if (bitmapWorkerTask != null) {
@@ -71,7 +74,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
}
@Override
- public View getView(int position, View view, ViewGroup parent) {
+ public View getView(int position, View view, @NonNull ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.conversation_list_row, parent, false);
@@ -83,7 +86,12 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
viewHolder.swipeableItem.setBackgroundColor(c);
}
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
- viewHolder.name.setText(EmojiWrapper.transform(conversation.getName()));
+ CharSequence name = conversation.getName();
+ if (name instanceof Jid) {
+ viewHolder.name.setText(IrregularUnicodeDetector.style(activity, (Jid) name));
+ } else {
+ viewHolder.name.setText(EmojiWrapper.transform(name));
+ }
} else {
viewHolder.name.setText(conversation.getJid().asBareJid().toString());
}
@@ -275,7 +283,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
return view;
}
- public void loadAvatar(Conversation conversation, ImageView imageView) {
+ private void loadAvatar(Conversation conversation, ImageView imageView) {
if (cancelPotentialWork(conversation, imageView)) {
final Bitmap bm = activity.avatarService().get(conversation, activity.getPixel(56), true);
if (bm != null) {
@@ -283,7 +291,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
imageView.setImageBitmap(bm);
imageView.setBackgroundColor(0x00000000);
} else {
- imageView.setBackgroundColor(UIHelper.getColorForName(conversation.getName()));
+ imageView.setBackgroundColor(UIHelper.getColorForName(conversation.getName().toString()));
imageView.setImageDrawable(null);
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
final AsyncDrawable asyncDrawable = new AsyncDrawable(activity.getResources(), null, task);
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
index 56e9f63b0..59255accd 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
@@ -6,9 +6,9 @@ import android.widget.ArrayAdapter;
import android.widget.Filter;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Locale;
public class KnownHostsAdapter extends ArrayAdapter<String> {
@@ -60,7 +60,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
}
};
- public KnownHostsAdapter(Context context, int viewResourceId, List<String> mKnownHosts) {
+ public KnownHostsAdapter(Context context, int viewResourceId, Collection<String> mKnownHosts) {
super(context, viewResourceId, new ArrayList<>());
if (mKnownHosts == null) {
diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
index f9a0b8db8..e8ca33fb3 100644
--- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
@@ -66,7 +66,7 @@ public class GeoHelper {
String label;
if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
try {
- label = "(" + URLEncoder.encode(message.getConversation().getName(), "UTF-8") + ")";
+ label = "(" + URLEncoder.encode(message.getConversation().getName().toString(), "UTF-8") + ")";
} catch (UnsupportedEncodingException e) {
label = "";
}
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 9d8dd48ee..cb289db64 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -318,10 +318,10 @@ public class XmppConnection implements Runnable {
} catch (Exception e) {
throw new IOException(e.getMessage());
}
- } else if (IP.matches(account.getServer().toString())) {
+ } else if (IP.matches(account.getServer())) {
localSocket = new Socket();
try {
- localSocket.connect(new InetSocketAddress(account.getServer().toString(), 5222), Config.SOCKET_TIMEOUT * 1000);
+ localSocket.connect(new InetSocketAddress(account.getServer(), 5222), Config.SOCKET_TIMEOUT * 1000);
} catch (IOException e) {
throw new UnknownHostException();
}
@@ -381,12 +381,12 @@ public class XmppConnection implements Runnable {
}
SSLSocketHelper.setSecurity((SSLSocket) localSocket);
- SSLSocketHelper.setSNIHost(tlsFactoryVerifier.factory, (SSLSocket) localSocket, account.getServer().getDomain());
+ SSLSocketHelper.setSNIHost(tlsFactoryVerifier.factory, (SSLSocket) localSocket, account.getServer());
SSLSocketHelper.setAlpnProtocol(tlsFactoryVerifier.factory, (SSLSocket) localSocket, "xmpp-client");
localSocket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
- if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomain(), verifiedHostname, ((SSLSocket) localSocket).getSession())) {
+ if (!tlsFactoryVerifier.verifier.verify(account.getServer(), verifiedHostname, ((SSLSocket) localSocket).getSession())) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS certificate verification failed");
if (!iterator.hasNext()) {
throw new StateChangingException(Account.State.TLS_ERROR);
@@ -823,7 +823,7 @@ public class XmppConnection implements Runnable {
SSLSocketHelper.setSecurity(sslSocket);
- if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomain(), this.verifiedHostname, sslSocket.getSession())) {
+ if (!tlsFactoryVerifier.verifier.verify(account.getServer(), this.verifiedHostname, sslSocket.getSession())) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS certificate verification failed");
throw new StateChangingException(Account.State.TLS_ERROR);
}
@@ -927,74 +927,69 @@ public class XmppConnection implements Runnable {
private void sendRegistryRequest() {
final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
register.query("jabber:iq:register");
- register.setTo(account.getServer());
- sendUnmodifiedIqPacket(register, new OnIqPacketReceived() {
-
- @Override
- public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
- return;
- }
- if (packet.getType() == IqPacket.TYPE.ERROR) {
- throw new StateChangingError(Account.State.REGISTRATION_FAILED);
- }
- final Element query = packet.query("jabber:iq:register");
- if (query.hasChild("username") && (query.hasChild("password"))) {
- final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
- final Element username = new Element("username").setContent(account.getUsername());
- final Element password = new Element("password").setContent(account.getPassword());
- register.query("jabber:iq:register").addChild(username);
- register.query().addChild(password);
- register.setFrom(account.getJid().asBareJid());
- sendUnmodifiedIqPacket(register, registrationResponseListener, true);
- } else if (query.hasChild("x", Namespace.DATA)) {
- final Data data = Data.parse(query.findChild("x", Namespace.DATA));
- final Element blob = query.findChild("data", "urn:xmpp:bob");
- final String id = packet.getId();
- InputStream is;
- if (blob != null) {
- try {
- final String base64Blob = blob.getContent();
- final byte[] strBlob = Base64.decode(base64Blob, Base64.DEFAULT);
- is = new ByteArrayInputStream(strBlob);
- } catch (Exception e) {
- is = null;
- }
- } else {
- try {
- Field field = data.getFieldByName("url");
- URL url = field != null && field.getValue() != null ? new URL(field.getValue()) : null;
- is = url != null ? url.openStream() : null;
- } catch (IOException e) {
- is = null;
- }
+ register.setTo(Jid.of(account.getServer()));
+ sendUnmodifiedIqPacket(register, (account, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
+ return;
+ }
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
+ throw new StateChangingError(Account.State.REGISTRATION_FAILED);
+ }
+ final Element query = packet.query("jabber:iq:register");
+ if (query.hasChild("username") && (query.hasChild("password"))) {
+ final IqPacket register1 = new IqPacket(IqPacket.TYPE.SET);
+ final Element username = new Element("username").setContent(account.getUsername());
+ final Element password = new Element("password").setContent(account.getPassword());
+ register1.query("jabber:iq:register").addChild(username);
+ register1.query().addChild(password);
+ register1.setFrom(account.getJid().asBareJid());
+ sendUnmodifiedIqPacket(register1, registrationResponseListener, true);
+ } else if (query.hasChild("x", Namespace.DATA)) {
+ final Data data = Data.parse(query.findChild("x", Namespace.DATA));
+ final Element blob = query.findChild("data", "urn:xmpp:bob");
+ final String id = packet.getId();
+ InputStream is;
+ if (blob != null) {
+ try {
+ final String base64Blob = blob.getContent();
+ final byte[] strBlob = Base64.decode(base64Blob, Base64.DEFAULT);
+ is = new ByteArrayInputStream(strBlob);
+ } catch (Exception e) {
+ is = null;
}
-
- if (is != null) {
- Bitmap captcha = BitmapFactory.decodeStream(is);
- try {
- if (mXmppConnectionService.displayCaptchaRequest(account, id, data, captcha)) {
- return;
- }
- } catch (Exception e) {
- throw new StateChangingError(Account.State.REGISTRATION_FAILED);
- }
+ } else {
+ try {
+ Field field = data.getFieldByName("url");
+ URL url = field != null && field.getValue() != null ? new URL(field.getValue()) : null;
+ is = url != null ? url.openStream() : null;
+ } catch (IOException e) {
+ is = null;
}
- throw new StateChangingError(Account.State.REGISTRATION_FAILED);
- } else if (query.hasChild("instructions") || query.hasChild("x", Namespace.OOB)) {
- final String instructions = query.findChildContent("instructions");
- final Element oob = query.findChild("x", Namespace.OOB);
- final String url = oob == null ? null : oob.findChildContent("url");
- if (url != null) {
- setAccountCreationFailed(url);
- } else if (instructions != null) {
- Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
- if (matcher.find()) {
- setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end()));
+ }
+ if (is != null) {
+ Bitmap captcha = BitmapFactory.decodeStream(is);
+ try {
+ if (mXmppConnectionService.displayCaptchaRequest(account, id, data, captcha)) {
+ return;
}
+ } catch (Exception e) {
+ throw new StateChangingError(Account.State.REGISTRATION_FAILED);
+ }
+ }
+ throw new StateChangingError(Account.State.REGISTRATION_FAILED);
+ } else if (query.hasChild("instructions") || query.hasChild("x", Namespace.OOB)) {
+ final String instructions = query.findChildContent("instructions");
+ final Element oob = query.findChild("x", Namespace.OOB);
+ final String url = oob == null ? null : oob.findChildContent("url");
+ if (url != null) {
+ setAccountCreationFailed(url);
+ } else if (instructions != null) {
+ Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
+ if (matcher.find()) {
+ setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end()));
}
- throw new StateChangingError(Account.State.REGISTRATION_FAILED);
}
+ throw new StateChangingError(Account.State.REGISTRATION_FAILED);
}
}, true);
}
@@ -1172,17 +1167,17 @@ public class XmppConnection implements Runnable {
}
final boolean requestDiscoItemsFirst = !account.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
if (requestDiscoItemsFirst) {
- sendServiceDiscoveryItems(account.getServer());
+ sendServiceDiscoveryItems(Jid.of(account.getServer()));
}
if (discoveryResult == null) {
- sendServiceDiscoveryInfo(account.getServer());
+ sendServiceDiscoveryInfo(Jid.of(account.getServer()));
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache");
- disco.put(account.getServer(), discoveryResult);
+ disco.put(Jid.of(account.getServer()), discoveryResult);
}
sendServiceDiscoveryInfo(account.getJid().asBareJid());
if (!requestDiscoItemsFirst) {
- sendServiceDiscoveryItems(account.getServer());
+ sendServiceDiscoveryItems(Jid.of(account.getServer()));
}
if (!mWaitForDisco.get()) {
@@ -1196,32 +1191,28 @@ public class XmppConnection implements Runnable {
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(jid);
iq.query("http://jabber.org/protocol/disco#info");
- this.sendIqPacket(iq, new OnIqPacketReceived() {
-
- @Override
- public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.RESULT) {
- boolean advancedStreamFeaturesLoaded;
- synchronized (XmppConnection.this.disco) {
- ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
- if (jid.equals(account.getServer())) {
- mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
- }
- disco.put(jid, result);
- advancedStreamFeaturesLoaded = disco.containsKey(account.getServer())
- && disco.containsKey(account.getJid().asBareJid());
- }
- if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().asBareJid()))) {
- enableAdvancedStreamFeatures();
+ this.sendIqPacket(iq, (account, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ boolean advancedStreamFeaturesLoaded;
+ synchronized (XmppConnection.this.disco) {
+ ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
+ if (jid.equals(Jid.of(account.getServer()))) {
+ mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
}
- } else {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco info for " + jid.toString());
+ disco.put(jid, result);
+ advancedStreamFeaturesLoaded = disco.containsKey(Jid.of(account.getServer()))
+ && disco.containsKey(account.getJid().asBareJid());
}
- if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
- if (mPendingServiceDiscoveries.decrementAndGet() == 0
- && mWaitForDisco.compareAndSet(true, false)) {
- finalizeBind();
- }
+ if (advancedStreamFeaturesLoaded && (jid.equals(Jid.of(account.getServer())) || jid.equals(account.getJid().asBareJid()))) {
+ enableAdvancedStreamFeatures();
+ }
+ } else {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco info for " + jid.toString());
+ }
+ if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
+ if (mPendingServiceDiscoveries.decrementAndGet() == 0
+ && mWaitForDisco.compareAndSet(true, false)) {
+ finalizeBind();
}
}
});
@@ -1647,7 +1638,7 @@ public class XmppConnection implements Runnable {
private final SSLSocketFactory factory;
private final DomainHostnameVerifier verifier;
- public TlsFactoryVerifier(final SSLSocketFactory factory, final DomainHostnameVerifier verifier) throws IOException {
+ TlsFactoryVerifier(final SSLSocketFactory factory, final DomainHostnameVerifier verifier) throws IOException {
this.factory = factory;
this.verifier = verifier;
if (factory == null || verifier == null) {
@@ -1733,23 +1724,23 @@ public class XmppConnection implements Runnable {
}
public boolean carbons() {
- return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
+ return hasDiscoFeature(Jid.of(account.getServer()), "urn:xmpp:carbons:2");
}
public boolean blocking() {
- return hasDiscoFeature(account.getServer(), Namespace.BLOCKING);
+ return hasDiscoFeature(Jid.of(account.getServer()), Namespace.BLOCKING);
}
public boolean spamReporting() {
- return hasDiscoFeature(account.getServer(), "urn:xmpp:reporting:reason:spam:0");
+ return hasDiscoFeature(Jid.of(account.getServer()), "urn:xmpp:reporting:reason:spam:0");
}
public boolean flexibleOfflineMessageRetrieval() {
- return hasDiscoFeature(account.getServer(), Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL);
+ return hasDiscoFeature(Jid.of(account.getServer()), Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL);
}
public boolean register() {
- return hasDiscoFeature(account.getServer(), Namespace.REGISTER);
+ return hasDiscoFeature(Jid.of(account.getServer()), Namespace.REGISTER);
}
public boolean sm() {
@@ -1795,7 +1786,7 @@ public class XmppConnection implements Runnable {
public boolean push() {
return hasDiscoFeature(account.getJid().asBareJid(), "urn:xmpp:push:0")
- || hasDiscoFeature(account.getServer(), "urn:xmpp:push:0");
+ || hasDiscoFeature(Jid.of(account.getServer()), "urn:xmpp:push:0");
}
public boolean rosterVersioning() {