aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2018-05-11 19:49:27 +0200
committersteckbrief <steckbrief@chefmail.de>2018-05-11 19:49:27 +0200
commitbff97731deed4c599dcb6c3a2887c9f47165dd3f (patch)
tree1a1479be225fef127146f58d69f32a947c4d013e /src
parent1d8c547b447d68daf079d9db2b1d792fc631e462 (diff)
introduces JidUtil for Jid creation, fixes duplication of childs while adding childs with xmlns and name
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/Config.java1
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java11
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Account.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Contact.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java13
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/CryptoHelper.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/XmppUri.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xml/Element.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/jid/Jid.java151
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/jid/JidUtil.java145
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/stanzas/JinglePacket.java4
30 files changed, 241 insertions, 217 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/Config.java b/src/main/java/de/thedevstack/conversationsplus/Config.java
index a6825246..50c1faf9 100644
--- a/src/main/java/de/thedevstack/conversationsplus/Config.java
+++ b/src/main/java/de/thedevstack/conversationsplus/Config.java
@@ -68,7 +68,6 @@ public final class Config {
public static final boolean DISABLE_PROXY_LOOKUP = BuildConfig.DISABLE_PROXY_LOOKUP; //useful to debug ibb
public static final boolean DISABLE_HTTP_UPLOAD = BuildConfig.DISABLE_HTTP_UPLOAD;
- public static final boolean DISABLE_STRING_PREP = BuildConfig.DISABLE_STRING_PREP; // setting to true might increase startup performance
public static final boolean EXTENDED_SM_LOGGING = BuildConfig.EXTENDED_SM_LOGGING; // log stanza counts
public static final boolean RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE = BuildConfig.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE; //setting to true might increase power consumption
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
index 34023d9f..56ee4dbc 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java
@@ -35,6 +35,7 @@ import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.MessagePacket;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
@@ -102,7 +103,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
@Override
public void askForSecret(SessionID id, InstanceTag instanceTag, String question) {
try {
- final Jid jid = Jid.fromSessionID(id);
+ final Jid jid = JidUtil.fromSessionID(id);
Conversation conversation = this.mXmppConnectionService.find(this.account,jid);
if (conversation!=null) {
conversation.smp().hint = question;
@@ -182,7 +183,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
packet.setBody(body);
MessageGenerator.addMessageHints(packet);
try {
- Jid jid = Jid.fromSessionID(session);
+ Jid jid = JidUtil.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account,jid);
if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
if (ConversationsPlusPreferences.chatStates()) {
@@ -227,7 +228,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
private void setSmpStatus(SessionID id, int status) {
try {
- final Jid jid = Jid.fromSessionID(id);
+ final Jid jid = JidUtil.fromSessionID(id);
Conversation conversation = this.mXmppConnectionService.find(this.account,jid);
if (conversation!=null) {
conversation.smp().status = status;
@@ -259,7 +260,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
public void sendOtrErrorMessage(SessionID session, String errorText) {
try {
- Jid jid = Jid.fromSessionID(session);
+ Jid jid = JidUtil.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account, jid);
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
if (id != null) {
@@ -285,7 +286,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost {
public void verify(SessionID id, String fingerprint, boolean approved) {
Logging.d(Config.LOGTAG,"OtrService.verify("+id.toString()+","+fingerprint+","+String.valueOf(approved)+")");
try {
- final Jid jid = Jid.fromSessionID(id);
+ final Jid jid = JidUtil.fromSessionID(id);
Conversation conversation = this.mXmppConnectionService.find(this.account,jid);
if (conversation!=null) {
if (approved) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
index 3569a7a5..cdf78761 100644
--- a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
+++ b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlServiceImpl.java
@@ -52,6 +52,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacketReceiver;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, AxolotlService {
@@ -166,7 +167,7 @@ public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, Axolo
Bundle information = CryptoHelper.extractCertificateInformation(certificate);
try {
final String cn = information.getString("subject_cn");
- final Jid jid = Jid.fromString(bareJid);
+ final Jid jid = JidUtil.fromString(bareJid);
Log.d(Config.LOGTAG,"setting common name for "+jid+" to "+cn);
account.getRoster().getContact(jid).setCommonName(cn);
} catch (final InvalidJidException ignored) {
@@ -660,7 +661,7 @@ public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, Axolo
final AxolotlAddress address = session.getRemoteAddress();
final IdentityKey identityKey = session.getIdentityKey();
try {
- IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveVerificationForDevice(Jid.fromString(address.getName()), address.getDeviceId());
+ IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveVerificationForDevice(JidUtil.fromString(address.getName()), address.getDeviceId());
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
@@ -681,7 +682,7 @@ public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, Axolo
Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
try {
final String cn = information.getString("subject_cn");
- final Jid jid = Jid.fromString(address.getName());
+ final Jid jid = JidUtil.fromString(address.getName());
Log.d(Config.LOGTAG,"setting common name for "+jid+" to "+cn);
account.getRoster().getContact(jid).setCommonName(cn);
} catch (final InvalidJidException ignored) {
@@ -733,7 +734,7 @@ public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, Axolo
try {
IqPacket bundlesPacket = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(
- Jid.fromString(address.getName()), address.getDeviceId());
+ JidUtil.fromString(address.getName()), address.getDeviceId());
Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Retrieving bundle: " + bundlesPacket);
mXmppConnectionService.sendIqPacket(account, bundlesPacket, new OnIqPacketReceived() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Account.java b/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
index 1c7ad288..2421d86e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Account.java
@@ -32,6 +32,7 @@ import de.thedevstack.conversationsplus.utils.SimpleCryptoUtil;
import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class Account extends AbstractEntity {
@@ -201,7 +202,7 @@ public class Account extends AbstractEntity {
public static Account fromCursor(final Cursor cursor) {
Jid jid = null;
try {
- jid = Jid.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)),
+ jid = JidUtil.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)),
cursor.getString(cursor.getColumnIndex(SERVER)), "mobile");
} catch (final InvalidJidException ignored) {
}
@@ -294,7 +295,7 @@ public class Account extends AbstractEntity {
final String oldResource = jid.getResourcepart();
if (oldResource == null || !oldResource.equals(resource)) {
try {
- jid = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), resource);
+ jid = JidUtil.fromParts(jid.getLocalpart(), jid.getDomainpart(), resource);
return true;
} catch (final InvalidJidException ignored) {
return true;
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Contact.java b/src/main/java/de/thedevstack/conversationsplus/entities/Contact.java
index 3dc7c10a..dd832b9b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Contact.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Contact.java
@@ -17,6 +17,7 @@ import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.dto.Avatar;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class Contact implements ListItem, Blockable {
public static final String TABLENAME = "contacts";
@@ -87,7 +88,7 @@ public class Contact implements ListItem, Blockable {
cursor.getLong(cursor.getColumnIndex(LAST_TIME)));
final Jid jid;
try {
- jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID)), true);
+ jid = JidUtil.fromString(cursor.getString(cursor.getColumnIndex(JID)), true);
} catch (final InvalidJidException e) {
// TODO: Borked DB... handle this somehow?
return null;
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
index 0cce63f4..19f21610 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Conversation.java
@@ -22,7 +22,6 @@ import java.util.NavigableSet;
import java.util.TreeSet;
import de.thedevstack.conversationsplus.dto.LoadAvatarFor;
-import de.thedevstack.conversationsplus.enums.MessageDirection;
import de.thedevstack.conversationsplus.enums.MessageStatus;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.Config;
@@ -30,6 +29,7 @@ import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class Conversation extends AbstractEntity implements Blockable, LoadAvatarFor {
public static final String TABLENAME = "conversations";
@@ -461,7 +461,7 @@ public class Conversation extends AbstractEntity implements Blockable, LoadAvata
public static Conversation fromCursor(Cursor cursor) {
Jid jid;
try {
- jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)), true);
+ jid = JidUtil.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)), true);
} catch (final InvalidJidException e) {
// Borked DB..
jid = null;
@@ -826,7 +826,7 @@ public class Conversation extends AbstractEntity implements Blockable, LoadAvata
JSONArray array = this.attributes.getJSONArray(key);
for (int i = 0; i < array.length(); ++i) {
try {
- list.add(Jid.fromString(array.getString(i)));
+ list.add(JidUtil.fromString(array.getString(i)));
} catch (InvalidJidException e) {
//ignored
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index 86adb4af..debcaca1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -17,6 +17,7 @@ import de.thedevstack.conversationsplus.utils.MessageParserUtil;
import de.thedevstack.conversationsplus.utils.MimeUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class Message extends AbstractEntity implements LoadAvatarFor {
@@ -151,7 +152,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
try {
String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
if (value != null) {
- jid = Jid.fromString(value, true);
+ jid = JidUtil.fromString(value, true);
} else {
jid = null;
}
@@ -162,7 +163,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
try {
String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
if (value != null) {
- trueCounterpart = Jid.fromString(value, true);
+ trueCounterpart = JidUtil.fromString(value, true);
} else {
trueCounterpart = null;
}
@@ -449,7 +450,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
return true;
} else if (presences.size() >= 1) {
try {
- counterpart = Jid.fromParts(conversation.getJid().getLocalpart(),
+ counterpart = JidUtil.fromParts(conversation.getJid().getLocalpart(),
conversation.getJid().getDomainpart(),
presences.asStringArray()[0]);
return true;
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
index abc45f0b..6b578c2b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
@@ -17,6 +17,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.dto.Avatar;
import de.thedevstack.conversationsplus.xmpp.mam.Mam;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
@SuppressLint("DefaultLocale")
public class MucOptions {
@@ -463,7 +464,7 @@ public class MucOptions {
public Jid createJoinJid(String nick) {
try {
- return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick);
+ return JidUtil.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick);
} catch (final InvalidJidException e) {
return null;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
index fd227e5a..d006628e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
+++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java
@@ -50,6 +50,7 @@ import de.thedevstack.conversationsplus.persistance.db.access.MessageDatabaseAcc
import de.thedevstack.conversationsplus.utils.SimpleCryptoUtil;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class DatabaseBackend extends SQLiteOpenHelper {
@@ -297,7 +298,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) {
String newJid;
try {
- newJid = Jid.fromString(
+ newJid = JidUtil.fromString(
cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID))
).toString();
} catch (InvalidJidException ignored) {
@@ -322,7 +323,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) {
String newJid;
try {
- newJid = Jid.fromString(
+ newJid = JidUtil.fromString(
cursor.getString(cursor.getColumnIndex(Contact.JID))
).toString();
} catch (InvalidJidException ignored) {
@@ -349,7 +350,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) {
String newServer;
try {
- newServer = Jid.fromParts(
+ newServer = JidUtil.fromParts(
cursor.getString(cursor.getColumnIndex(Account.USERNAME)),
cursor.getString(cursor.getColumnIndex(Account.SERVER)),
"mobile"
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 2285a29d..a6dff1f0 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -55,7 +55,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.enums.MessageDirection;
import de.thedevstack.conversationsplus.enums.MessageStatus;
import de.thedevstack.conversationsplus.services.avatar.AvatarCache;
import de.thedevstack.conversationsplus.services.avatar.AvatarService;
@@ -83,6 +82,7 @@ import de.thedevstack.conversationsplus.xmpp.openpgp.OpenPgpXep;
import de.thedevstack.conversationsplus.xmpp.ping.PingXep;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacketReceiver;
import de.thedevstack.conversationsplus.xmpp.time.EntityTimeXep;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -406,7 +406,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
case ACTION_DISABLE_ACCOUNT:
try {
String jid = intent.getStringExtra("account");
- Account account = jid == null ? null : findAccountByJid(Jid.fromString(jid));
+ Account account = jid == null ? null : findAccountByJid(JidUtil.fromString(jid));
if (account != null) {
account.setOption(Account.OPTION_DISABLED, true);
updateAccount(account);
@@ -795,7 +795,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
SessionImpl otrSession = conversation.getOtrSession();
if (otrSession != null && otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
try {
- message.setCounterpart(Jid.fromSessionID(otrSession.getSessionID()));
+ message.setCounterpart(JidUtil.fromSessionID(otrSession.getSessionID()));
} catch (InvalidJidException e) {
break;
}
@@ -992,7 +992,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
Jid jid;
try {
- jid = Jid.fromString(phoneContact.getString("jid"));
+ jid = JidUtil.fromString(phoneContact.getString("jid"));
} catch (final InvalidJidException e) {
continue;
}
@@ -1789,7 +1789,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return;
}
String name = new BigInteger(75, ConversationsPlusApplication.getSecureRandom()).toString(32);
- Jid jid = Jid.fromParts(name, server, null);
+ Jid jid = JidUtil.fromParts(name, server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
@@ -2002,7 +2002,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onMessageFound(Message message) {
SessionID id = otrSession.getSessionID();
try {
- message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
+ message.setCounterpart(JidUtil.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (InvalidJidException e) {
return;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
index 245b7a38..9b054d03 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
@@ -44,7 +44,6 @@ import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.ListItem;
-import de.thedevstack.conversationsplus.services.avatar.AvatarService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterUpdate;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
@@ -55,6 +54,7 @@ import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated {
public static final String ACTION_VIEW_CONTACT = "view_contact";
@@ -184,11 +184,11 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
try {
- this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
+ this.accountJid = JidUtil.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final InvalidJidException ignored) {
}
try {
- this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
+ this.contactJid = JidUtil.fromString(getIntent().getExtras().getString("contact"));
} catch (final InvalidJidException ignored) {
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index 69c1f817..f3e2539a 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -50,6 +50,7 @@ import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManage
import de.thedevstack.conversationsplus.utils.AccountUtil;
import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
import de.timroes.android.listview.EnhancedListView;
import de.thedevstack.conversationsplus.Config;
@@ -1249,7 +1250,7 @@ public class ConversationActivity extends XmppActivity
if (pm) {
Jid jid = getSelectedConversation().getJid();
try {
- Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
+ Jid next = JidUtil.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
this.privateMessageWith(next);
} catch (final InvalidJidException ignored) {
//do nothing
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
index 725e10a9..1f8fd7f7 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
@@ -61,6 +61,7 @@ import de.thedevstack.conversationsplus.xmpp.forms.Data;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.dto.Avatar;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
@@ -132,9 +133,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
final Jid jid;
try {
if (Config.DOMAIN_LOCK != null) {
- jid = Jid.fromParts(mAccountJid.getText().toString(), Config.DOMAIN_LOCK, null);
+ jid = JidUtil.fromParts(mAccountJid.getText().toString(), Config.DOMAIN_LOCK, null);
} else {
- jid = Jid.fromString(mAccountJid.getText().toString());
+ jid = JidUtil.fromString(mAccountJid.getText().toString());
}
} catch (final InvalidJidException e) {
if (Config.DOMAIN_LOCK != null) {
@@ -504,7 +505,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
super.onStart();
if (getIntent() != null) {
try {
- this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
+ this.jidToEdit = JidUtil.fromString(getIntent().getStringExtra("jid"));
} catch (final InvalidJidException | NullPointerException ignored) {
this.jidToEdit = null;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java
index 9e52d390..5bef1624 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java
@@ -16,6 +16,7 @@ import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.ui.adapter.KnownHostsAdapter;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class EnterJidDialog {
public interface OnEnterJidDialogPositiveListener {
@@ -91,9 +92,9 @@ public class EnterJidDialog {
}
try {
if (Config.DOMAIN_LOCK != null) {
- accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ accountJid = JidUtil.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
- accountJid = Jid.fromString((String) spinner.getSelectedItem());
+ accountJid = JidUtil.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) {
return;
@@ -101,9 +102,9 @@ public class EnterJidDialog {
final Jid contactJid;
try {
if (lock) {
- contactJid = Jid.fromParts(jid.getText().toString(), Config.DOMAIN_LOCK, null);
+ contactJid = JidUtil.fromParts(jid.getText().toString(), Config.DOMAIN_LOCK, null);
} else {
- contactJid = Jid.fromString(jid.getText().toString());
+ contactJid = JidUtil.fromString(jid.getText().toString());
}
} catch (final InvalidJidException e) {
jid.setError(context.getString(lock ? R.string.invalid_username : R.string.invalid_jid));
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
index e376b6b3..b620f1ed 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
@@ -35,6 +35,7 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccount
import de.thedevstack.conversationsplus.ui.adapter.AccountAdapter;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate, KeyChainAliasCallback, XmppConnectionService.OnAccountCreated {
@@ -81,7 +82,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
if (jid != null) {
try {
- this.selectedAccountJid = Jid.fromString(jid);
+ this.selectedAccountJid = JidUtil.fromString(jid);
} catch (InvalidJidException e) {
this.selectedAccountJid = null;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
index 080c7a51..117e0160 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
@@ -34,7 +34,7 @@ import de.thedevstack.conversationsplus.utils.ConversationUtil;
import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate {
@@ -250,7 +250,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
}else{
Account account;
try {
- account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
+ account = xmppConnectionService.findAccountByJid(JidUtil.fromString(share.account));
} catch (final InvalidJidException e) {
account = null;
}
@@ -260,7 +260,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
try {
conversation = xmppConnectionService
- .findOrCreateConversation(account, Jid.fromString(share.contact), false);
+ .findOrCreateConversation(account, JidUtil.fromString(share.contact), false);
} catch (final InvalidJidException e) {
return;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
index 2dc8d1a5..d159d044 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
@@ -74,6 +74,7 @@ import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class StartConversationActivity extends XmppActivity implements OnRosterUpdate, OnUpdateBlocklist {
@@ -424,9 +425,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final Jid conferenceJid;
try {
if (lock) {
- conferenceJid = Jid.fromParts(jid.getText().toString(),Config.CONFERENCE_DOMAIN_LOCK, null);
+ conferenceJid = JidUtil.fromParts(jid.getText().toString(),Config.CONFERENCE_DOMAIN_LOCK, null);
} else {
- conferenceJid = Jid.fromString(jid.getText().toString());
+ conferenceJid = JidUtil.fromString(jid.getText().toString());
}
} catch (final InvalidJidException e) {
jid.setError(getString(lock ? R.string.invalid_conference_name : R.string.invalid_jid));
@@ -476,9 +477,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Jid jid;
try {
if (Config.DOMAIN_LOCK != null) {
- jid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ jid = JidUtil.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
- jid = Jid.fromString((String) spinner.getSelectedItem());
+ jid = JidUtil.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) {
return null;
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
index dfddbb78..850a6c38 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
@@ -28,6 +28,7 @@ import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;
import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdated {
private List<Jid> contactJids;
@@ -77,7 +78,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
this.contactJids = new ArrayList<>();
for(String jid : getIntent().getStringArrayExtra("contacts")) {
try {
- this.contactJids.add(Jid.fromString(jid));
+ this.contactJids.add(JidUtil.fromString(jid));
} catch (InvalidJidException e) {
e.printStackTrace();
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
index d6b3d838..fe427361 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
@@ -29,7 +29,7 @@ import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.XmppUri;
import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class VerifyOTRActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate {
@@ -203,7 +203,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
return false;
}
try {
- this.mConversation = this.xmppConnectionService.find(this.mAccount,Jid.fromString(intent.getExtras().getString("contact")));
+ this.mConversation = this.xmppConnectionService.find(this.mAccount, JidUtil.fromString(intent.getExtras().getString("contact")));
if (this.mConversation == null) {
return false;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index 21292cec..516bd214 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -70,6 +70,7 @@ import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public abstract class XmppActivity extends Activity {
@@ -771,7 +772,7 @@ public abstract class XmppActivity extends Activity {
SessionID id = conversation.getOtrSession().getSessionID();
Jid jid;
try {
- jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
+ jid = JidUtil.fromString(id.getAccountID() + "/" + id.getUserID());
} catch (InvalidJidException e) {
jid = null;
}
@@ -796,7 +797,7 @@ public abstract class XmppActivity extends Activity {
} else if (presences.size() == 1) {
String presence = presences.asStringArray()[0];
try {
- conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(),contact.getJid().getDomainpart(),presence));
+ conversation.setNextCounterpart(JidUtil.fromParts(contact.getJid().getLocalpart(),contact.getJid().getDomainpart(),presence));
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
@@ -831,7 +832,7 @@ public abstract class XmppActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
- conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(),contact.getJid().getDomainpart(),presence.toString()));
+ conversation.setNextCounterpart(JidUtil.fromParts(contact.getJid().getLocalpart(),contact.getJid().getDomainpart(),presence.toString()));
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
@@ -950,7 +951,7 @@ public abstract class XmppActivity extends Activity {
protected Account extractAccount(Intent intent) {
String jid = intent != null ? intent.getStringExtra(EXTRA_ACCOUNT) : null;
try {
- return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null;
+ return jid != null ? xmppConnectionService.findAccountByJid(JidUtil.fromString(jid)) : null;
} catch (InvalidJidException e) {
return null;
}
@@ -970,10 +971,10 @@ public abstract class XmppActivity extends Activity {
if (data.getBooleanExtra("multiple", false)) {
String[] toAdd = data.getStringArrayExtra("contacts");
for (String item : toAdd) {
- invite.jids.add(Jid.fromString(item));
+ invite.jids.add(JidUtil.fromString(item));
}
} else {
- invite.jids.add(Jid.fromString(data.getStringExtra("contact")));
+ invite.jids.add(JidUtil.fromString(data.getStringExtra("contact")));
}
} catch (final InvalidJidException ignored) {
return null;
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java
index c86653bf..383e7003 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java
@@ -8,7 +8,7 @@ import java.util.List;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.xmpp.forms.Field;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class FormJidSingleFieldWrapper extends FormTextFieldWrapper {
@@ -23,7 +23,7 @@ public class FormJidSingleFieldWrapper extends FormTextFieldWrapper {
String value = getValue();
if (!value.isEmpty()) {
try {
- Jid.fromString(value);
+ JidUtil.fromString(value);
} catch (InvalidJidException e) {
editText.setError(context.getString(R.string.invalid_jid));
editText.requestFocus();
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/CryptoHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/CryptoHelper.java
index 7e4a4fc5..663ea5b5 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/CryptoHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/CryptoHelper.java
@@ -26,6 +26,7 @@ import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public final class CryptoHelper {
public static final String FILETRANSFER = "?FILETRANSFERv1:";
@@ -150,7 +151,7 @@ public final class CryptoHelper {
}
String name = IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue());
if (emails.size() >= 1) {
- return new Pair<>(Jid.fromString(emails.get(0)), name);
+ return new Pair<>(JidUtil.fromString(emails.get(0)), name);
} else {
return null;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
index 907e7fd7..ac160960 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
@@ -25,7 +25,7 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class ExceptionHelper {
public static void init(Context context) {
@@ -92,7 +92,7 @@ public class ExceptionHelper {
Conversation conversation = null;
try {
conversation = service.findOrCreateConversation(finalAccount,
- Jid.fromString(activity.getString(R.string.cplus_bugreport_jabberid)), false);
+ JidUtil.fromString(activity.getString(R.string.cplus_bugreport_jabberid)), false);
} catch (final InvalidJidException ignored) {
}
Message message = MessageUtil.createOutgoingMessage(conversation, report.toString());
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/XmppUri.java b/src/main/java/de/thedevstack/conversationsplus/utils/XmppUri.java
index 5d3a2694..8d5967b6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/XmppUri.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/XmppUri.java
@@ -7,6 +7,7 @@ import java.net.URLDecoder;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class XmppUri {
@@ -19,7 +20,7 @@ public class XmppUri {
parse(Uri.parse(uri));
} catch (IllegalArgumentException e) {
try {
- jid = Jid.fromString(uri).toBareJid().toString();
+ jid = JidUtil.fromString(uri).toBareJid().toString();
} catch (InvalidJidException e2) {
jid = null;
}
@@ -50,7 +51,7 @@ public class XmppUri {
}
} else {
try {
- jid = Jid.fromString(uri.toString()).toBareJid().toString();
+ jid = JidUtil.fromString(uri.toString()).toBareJid().toString();
} catch (final InvalidJidException ignored) {
jid = null;
}
@@ -73,7 +74,7 @@ public class XmppUri {
public Jid getJid() {
try {
- return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase());
+ return this.jid == null ? null : JidUtil.fromString(this.jid.toLowerCase());
} catch (InvalidJidException e) {
return null;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
index 95ed4c4e..ba37d6c0 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java
@@ -8,6 +8,7 @@ import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class Element {
private final String name;
@@ -37,7 +38,6 @@ public class Element {
public Element addChild(String name, String xmlns) {
Element child = new Element(name);
child.setAttribute("xmlns", xmlns);
- children.add(child);
return this.addChild(child);
}
@@ -47,7 +47,7 @@ public class Element {
public Element setContent(String content) {
this.content = content;
- this.children.clear();
+ this.clearChildren();
return this;
}
@@ -159,7 +159,7 @@ public class Element {
final String jid = this.getAttribute(name);
if (jid != null && !jid.isEmpty()) {
try {
- return Jid.fromString(jid);
+ return JidUtil.fromString(jid);
} catch (final InvalidJidException e) {
Logging.e(Config.LOGTAG, "could not parse jid " + jid);
return null;
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
index f6e6edb8..14f2a648 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
@@ -96,6 +96,7 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.streammgmt.AckPacket;
import de.thedevstack.conversationsplus.xmpp.stanzas.streammgmt.EnablePacket;
import de.thedevstack.conversationsplus.xmpp.stanzas.streammgmt.RequestPacket;
import de.thedevstack.conversationsplus.xmpp.stanzas.streammgmt.ResumePacket;
+import de.thedevstack.conversationsplus.xmpp.jid.JidUtil;
public class XmppConnection implements Runnable {
private static final int DEFAULT_PORT = 5222;
@@ -898,7 +899,7 @@ public class XmppConnection implements Runnable {
final Element jid = bind.findChild("jid");
if (jid != null && jid.getContent() != null) {
try {
- account.setResource(Jid.fromString(jid.getContent()).getResourcepart());
+ account.setResource(JidUtil.fromString(jid.getContent()).getResourcepart());
} catch (final InvalidJidException e) {
// TODO: Handle the case where an external JID is technically invalid?
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java
index 88b3155c..0509d473 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java
@@ -23,12 +23,12 @@ public class Field extends Element {
}
public void setValue(String value) {
- this.children.clear();
+ this.clearChildren();
this.addChild("value").setContent(value);
}
public void setValues(Collection<String> values) {
- this.children.clear();
+ this.clearChildren();
for(String value : values) {
this.addChild("value").setContent(value);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/Jid.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/Jid.java
index bb32e821..a85c0bed 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/Jid.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/Jid.java
@@ -1,22 +1,12 @@
package de.thedevstack.conversationsplus.xmpp.jid;
-import android.util.LruCache;
-
-import net.java.otr4j.session.SessionID;
-
import java.net.IDN;
-import de.thedevstack.conversationsplus.Config;
-import gnu.inet.encoding.Stringprep;
-import gnu.inet.encoding.StringprepException;
-
/**
* The `Jid' class provides an immutable representation of a JID.
*/
public final class Jid {
- private static LruCache<String,Jid> cache = new LruCache<>(1024);
-
private final String localpart;
private final String domainpart;
private final String resourcepart;
@@ -37,143 +27,16 @@ public final class Jid {
return resourcepart;
}
- public static Jid fromSessionID(final SessionID id) throws InvalidJidException{
- if (id.getUserID().isEmpty()) {
- return Jid.fromString(id.getAccountID());
- } else {
- return Jid.fromString(id.getAccountID()+"/"+id.getUserID());
- }
- }
-
- public static Jid fromString(final String jid) throws InvalidJidException {
- return Jid.fromString(jid, false);
- }
-
- public static Jid fromString(final String jid, final boolean safe) throws InvalidJidException {
- return new Jid(jid, safe);
- }
-
- public static Jid fromParts(final String localpart,
- final String domainpart,
- final String resourcepart) throws InvalidJidException {
- String out;
- if (localpart == null || localpart.isEmpty()) {
- out = domainpart;
- } else {
- out = localpart + "@" + domainpart;
- }
- if (resourcepart != null && !resourcepart.isEmpty()) {
- out = out + "/" + resourcepart;
- }
- return new Jid(out, false);
- }
-
- private Jid(final String jid, final boolean safe) throws InvalidJidException {
- if (jid == null) throw new InvalidJidException(InvalidJidException.IS_NULL);
-
- Jid fromCache = Jid.cache.get(jid);
- if (fromCache != null) {
- displayjid = fromCache.displayjid;
- localpart = fromCache.localpart;
- domainpart = fromCache.domainpart;
- resourcepart = fromCache.resourcepart;
- return;
- }
-
- // Hackish Android way to count the number of chars in a string... should work everywhere.
- final int atCount = jid.length() - jid.replace("@", "").length();
- final int slashCount = jid.length() - jid.replace("/", "").length();
-
- // Throw an error if there's anything obvious wrong with the JID...
- if (jid.isEmpty() || jid.length() > 3071) {
- throw new InvalidJidException(InvalidJidException.INVALID_LENGTH);
- }
-
- // Go ahead and check if the localpart or resourcepart is empty.
- if (jid.startsWith("@") || (jid.endsWith("@") && slashCount == 0) || jid.startsWith("/") || (jid.endsWith("/") && slashCount < 2)) {
- throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
- }
-
- String finaljid;
-
- final int domainpartStart;
- final int atLoc = jid.indexOf("@");
- final int slashLoc = jid.indexOf("/");
- // If there is no "@" in the JID (eg. "example.net" or "example.net/resource")
- // or there are one or more "@" signs but they're all in the resourcepart (eg. "example.net/@/rp@"):
- if (atCount == 0 || (atCount > 0 && slashLoc != -1 && atLoc > slashLoc)) {
- localpart = "";
- finaljid = "";
- domainpartStart = 0;
- } else {
- final String lp = jid.substring(0, atLoc);
- try {
- localpart = Config.DISABLE_STRING_PREP || safe ? lp : Stringprep.nodeprep(lp);
- } catch (final StringprepException e) {
- throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
- }
- if (localpart.isEmpty() || localpart.length() > 1023) {
- throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
- }
- domainpartStart = atLoc + 1;
- finaljid = lp + "@";
- }
-
- final String dp;
- if (slashCount > 0) {
- final String rp = jid.substring(slashLoc + 1, jid.length());
- try {
- resourcepart = Config.DISABLE_STRING_PREP || safe ? rp : Stringprep.resourceprep(rp);
- } catch (final StringprepException e) {
- throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
- }
- if (resourcepart.isEmpty() || resourcepart.length() > 1023) {
- throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
- }
- try {
- dp = IDN.toUnicode(Stringprep.nameprep(jid.substring(domainpartStart, slashLoc)), IDN.USE_STD3_ASCII_RULES);
- } catch (final StringprepException e) {
- throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
- }
- finaljid = finaljid + dp + "/" + rp;
- } else {
- resourcepart = "";
- try{
- dp = IDN.toUnicode(Stringprep.nameprep(jid.substring(domainpartStart, jid.length())), IDN.USE_STD3_ASCII_RULES);
- } catch (final StringprepException e) {
- throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
- }
- finaljid = finaljid + dp;
- }
-
- // Remove trailing "." before storing the domain part.
- if (dp.endsWith(".")) {
- try {
- domainpart = IDN.toASCII(dp.substring(0, dp.length() - 1), IDN.USE_STD3_ASCII_RULES);
- } catch (final IllegalArgumentException e) {
- throw new InvalidJidException(e);
- }
- } else {
- try {
- domainpart = IDN.toASCII(dp, IDN.USE_STD3_ASCII_RULES);
- } catch (final IllegalArgumentException e) {
- throw new InvalidJidException(e);
- }
- }
-
- // TODO: Find a proper domain validation library; validate individual parts, separators, etc.
- if (domainpart.isEmpty() || domainpart.length() > 1023) {
- throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
- }
-
- Jid.cache.put(jid, this);
-
- this.displayjid = finaljid;
+ Jid(String displayjid, String local, String domain, String resource) throws InvalidJidException {
+ this.displayjid = displayjid;
+ this.localpart = local;
+ this.domainpart = (null == domain) ? "" : domain;
+ this.resourcepart = (null == resource) ? "" : resource;
}
public Jid toBareJid() {
try {
- return resourcepart.isEmpty() ? this : fromParts(localpart, domainpart, "");
+ return resourcepart.isEmpty() ? this : JidUtil.fromParts(localpart, domainpart, "");
} catch (final InvalidJidException e) {
// This should never happen.
throw new AssertionError("Jid " + this.toString() + " invalid");
@@ -182,7 +45,7 @@ public final class Jid {
public Jid toDomainJid() {
try {
- return resourcepart.isEmpty() && localpart.isEmpty() ? this : fromString(getDomainpart());
+ return resourcepart.isEmpty() && localpart.isEmpty() ? this : JidUtil.fromString(getDomainpart());
} catch (final InvalidJidException e) {
// This should never happen.
throw new AssertionError("Jid " + this.toString() + " invalid");
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/JidUtil.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/JidUtil.java
new file mode 100644
index 00000000..433f1f4f
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jid/JidUtil.java
@@ -0,0 +1,145 @@
+package de.thedevstack.conversationsplus.xmpp.jid;
+
+import android.util.LruCache;
+
+import net.java.otr4j.session.SessionID;
+
+import java.net.IDN;
+
+import gnu.inet.encoding.Stringprep;
+import gnu.inet.encoding.StringprepException;
+
+/**
+ */
+public class JidUtil {
+ private static LruCache<String,Jid> cache = new LruCache<>(1024);
+
+ public static Jid fromSessionID(final SessionID id) throws InvalidJidException {
+ if (id.getUserID().isEmpty()) {
+ return fromString(id.getAccountID());
+ } else {
+ return fromString(id.getAccountID()+"/"+id.getUserID());
+ }
+ }
+
+ public static Jid fromString(final String jid) throws InvalidJidException {
+ return fromString(jid, false);
+ }
+
+ public static Jid fromString(final String jid, final boolean safe) throws InvalidJidException {
+ if (jid == null) throw new InvalidJidException(InvalidJidException.IS_NULL);
+
+ Jid fromCache = JidUtil.cache.get(jid);
+ if (fromCache != null) {
+ return fromCache;
+ }
+
+ // Hackish Android way to count the number of chars in a string... should work everywhere.
+ final int atCount = jid.length() - jid.replace("@", "").length();
+ final int slashCount = jid.length() - jid.replace("/", "").length();
+
+ // Throw an error if there's anything obvious wrong with the JID...
+ if (jid.isEmpty() || jid.length() > 3071) {
+ throw new InvalidJidException(InvalidJidException.INVALID_LENGTH);
+ }
+
+ // Go ahead and check if the localpart or resourcepart is empty.
+ if (jid.startsWith("@") || (jid.endsWith("@") && slashCount == 0) || jid.startsWith("/") || (jid.endsWith("/") && slashCount < 2)) {
+ throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
+ }
+
+ String finaljid;
+ String localpart;
+ String domainpart;
+ String resourcepart;
+
+ final int domainpartStart;
+ final int atLoc = jid.indexOf("@");
+ final int slashLoc = jid.indexOf("/");
+ // If there is no "@" in the JID (eg. "example.net" or "example.net/resource")
+ // or there are one or more "@" signs but they're all in the resourcepart (eg. "example.net/@/rp@"):
+ if (atCount == 0 || (atCount > 0 && slashLoc != -1 && atLoc > slashLoc)) {
+ localpart = "";
+ finaljid = "";
+ domainpartStart = 0;
+ } else {
+ final String lp = jid.substring(0, atLoc);
+ try {
+ localpart = safe ? lp : Stringprep.nodeprep(lp);
+ } catch (final StringprepException e) {
+ throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
+ }
+ if (localpart.isEmpty() || localpart.length() > 1023) {
+ throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
+ }
+ domainpartStart = atLoc + 1;
+ finaljid = lp + "@";
+ }
+
+ final String dp;
+ if (slashCount > 0) {
+ final String rp = jid.substring(slashLoc + 1, jid.length());
+ try {
+ resourcepart = safe ? rp : Stringprep.resourceprep(rp);
+ } catch (final StringprepException e) {
+ throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
+ }
+ if (resourcepart.isEmpty() || resourcepart.length() > 1023) {
+ throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
+ }
+ try {
+ dp = IDN.toUnicode(Stringprep.nameprep(jid.substring(domainpartStart, slashLoc)), IDN.USE_STD3_ASCII_RULES);
+ } catch (final StringprepException e) {
+ throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
+ }
+ finaljid = finaljid + dp + "/" + rp;
+ } else {
+ resourcepart = "";
+ try{
+ dp = IDN.toUnicode(Stringprep.nameprep(jid.substring(domainpartStart, jid.length())), IDN.USE_STD3_ASCII_RULES);
+ } catch (final StringprepException e) {
+ throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
+ }
+ finaljid = finaljid + dp;
+ }
+
+ // Remove trailing "." before storing the domain part.
+ if (dp.endsWith(".")) {
+ try {
+ domainpart = IDN.toASCII(dp.substring(0, dp.length() - 1), IDN.USE_STD3_ASCII_RULES);
+ } catch (final IllegalArgumentException e) {
+ throw new InvalidJidException(e);
+ }
+ } else {
+ try {
+ domainpart = IDN.toASCII(dp, IDN.USE_STD3_ASCII_RULES);
+ } catch (final IllegalArgumentException e) {
+ throw new InvalidJidException(e);
+ }
+ }
+
+ // TODO: Find a proper domain validation library; validate individual parts, separators, etc.
+ if (domainpart.isEmpty() || domainpart.length() > 1023) {
+ throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
+ }
+
+ Jid createdJid = new Jid(finaljid, localpart, domainpart, resourcepart);
+
+ JidUtil.cache.put(jid, createdJid);
+
+ return createdJid;
+ }
+
+ public static Jid fromParts(final String localpart, final String domainpart, final String resourcepart) throws InvalidJidException {
+ String out;
+ if (localpart == null || localpart.isEmpty()) {
+ out = domainpart;
+ } else {
+ out = localpart + "@" + domainpart;
+ }
+ if (resourcepart != null && !resourcepart.isEmpty()) {
+ out = out + "/" + resourcepart;
+ }
+ return JidUtil.fromString(out, false);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/stanzas/JinglePacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/stanzas/JinglePacket.java
index db771a0a..63e86c24 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/stanzas/JinglePacket.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/stanzas/JinglePacket.java
@@ -51,7 +51,7 @@ public class JinglePacket extends IqPacket {
}
private void build() {
- this.children.clear();
+ this.clearChildren();
this.jingle.clearChildren();
this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
if (this.content != null) {
@@ -60,7 +60,7 @@ public class JinglePacket extends IqPacket {
if (this.reason != null) {
jingle.addChild(this.reason);
}
- this.children.add(jingle);
+ this.addChild(jingle);
this.setAttribute("type", "set");
}