diff options
Diffstat (limited to 'src/main')
85 files changed, 808 insertions, 1123 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/OtrService.java b/src/main/java/de/pixart/messenger/crypto/OtrService.java index df4cd9acd..f355ac348 100644 --- a/src/main/java/de/pixart/messenger/crypto/OtrService.java +++ b/src/main/java/de/pixart/messenger/crypto/OtrService.java @@ -32,9 +32,9 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.generator.MessageGenerator; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.xmpp.chatstate.ChatState; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import de.pixart.messenger.xmpp.jid.OtrJidHelper; import de.pixart.messenger.xmpp.stanzas.MessagePacket; +import rocks.xmpp.addr.Jid; public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { @@ -104,15 +104,15 @@ 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 = OtrJidHelper.fromSessionID(id); Conversation conversation = this.mXmppConnectionService.find(this.account, jid); if (conversation != null) { conversation.smp().hint = question; conversation.smp().status = Conversation.Smp.STATUS_CONTACT_REQUESTED; mXmppConnectionService.updateConversationUi(); } - } catch (InvalidJidException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": smp in invalid session " + id.toString()); + } catch (IllegalArgumentException e) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": smp in invalid session " + id.toString()); } } @@ -184,14 +184,14 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { packet.setBody(body); MessageGenerator.addMessageHints(packet); try { - Jid jid = Jid.fromSessionID(session); + Jid jid = OtrJidHelper.fromSessionID(session); Conversation conversation = mXmppConnectionService.find(account, jid); if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) { if (mXmppConnectionService.sendChatStates()) { packet.addChild(ChatState.toElement(conversation.getOutgoingChatState())); } } - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { } @@ -230,13 +230,13 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { private void setSmpStatus(SessionID id, int status) { try { - final Jid jid = Jid.fromSessionID(id); + final Jid jid = OtrJidHelper.fromSessionID(id); Conversation conversation = this.mXmppConnectionService.find(this.account, jid); if (conversation != null) { conversation.smp().status = status; mXmppConnectionService.updateConversationUi(); } - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { } } @@ -261,7 +261,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { public void sendOtrErrorMessage(SessionID session, String errorText) { try { - Jid jid = Jid.fromSessionID(session); + Jid jid = OtrJidHelper.fromSessionID(session); Conversation conversation = mXmppConnectionService.find(account, jid); String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId(); if (id != null) { @@ -270,10 +270,10 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { packet.setFrom(account.getJid()); mXmppConnectionService.sendMessagePacket(account, packet); Log.d(Config.LOGTAG, packet.toString()); - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": unreadable OTR message in " + conversation.getName()); } - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { return; } } @@ -287,7 +287,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { public void verify(SessionID id, String fingerprint, boolean approved) { Log.d(Config.LOGTAG, "OtrService.verify(" + id.toString() + "," + fingerprint + "," + String.valueOf(approved) + ")"); try { - final Jid jid = Jid.fromSessionID(id); + final Jid jid = OtrJidHelper.fromSessionID(id); Conversation conversation = this.mXmppConnectionService.find(this.account, jid); if (conversation != null) { if (approved) { @@ -298,7 +298,7 @@ public class OtrService extends OtrCryptoEngineImpl implements OtrEngineHost { mXmppConnectionService.updateConversationUi(); mXmppConnectionService.syncRosterToDisk(conversation.getAccount()); } - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { } } diff --git a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java index cc1ee41dc..f4490ed07 100644 --- a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java +++ b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java @@ -39,9 +39,9 @@ public class PgpEngine { private static void logError(Account account, OpenPgpError error) { if (error != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": OpenKeychain error with no message"); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message"); } } @@ -207,7 +207,7 @@ public class PgpEngine { params.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, account.getPgpId()); InputStream is = new ByteArrayInputStream(status.getBytes()); final OutputStream os = new ByteArrayOutputStream(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": signing status message \"" + status + "\""); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": signing status message \"" + status + "\""); api.executeApiAsync(params, is, os, result -> { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) { case OpenPgpApi.RESULT_CODE_SUCCESS: diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java index 55cbba9db..2efdb8040 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -51,11 +51,10 @@ import de.pixart.messenger.utils.SerialSingleThreadExecutor; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnAdvancedStreamFeaturesLoaded; import de.pixart.messenger.xmpp.OnIqPacketReceived; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.PublishOptions; import de.pixart.messenger.xmpp.stanzas.IqPacket; import de.pixart.messenger.xmpp.stanzas.MessagePacket; +import rocks.xmpp.addr.Jid; public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { @@ -83,9 +82,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { private int numPublishTriesOnEmptyPep = 0; private boolean pepBroken = false; private int lastDeviceListNotificationHash = 0; - private AtomicBoolean changeAccessMode = new AtomicBoolean(false); private Set<XmppAxolotlSession> postponedSessions = new HashSet<>(); //sessions stored here will receive after mam catchup treatment + private AtomicBoolean changeAccessMode = new AtomicBoolean(false); + @Override public void onAdvancedStreamFeaturesAvailable(Account account) { if (Config.supportOmemo() @@ -93,7 +93,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { && account.getXmppConnection().getFeatures().pep()) { publishBundlesIfNeeded(true, false); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping OMEMO initialization"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": skipping OMEMO initialization"); } } @@ -101,7 +101,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { for (Jid jid : jids) { if (deviceIds.get(jid) != null) { for (Integer foreignId : this.deviceIds.get(jid)) { - SignalProtocolAddress address = new SignalProtocolAddress(jid.toPreppedString(), foreignId); + SignalProtocolAddress address = new SignalProtocolAddress(jid.toString(), foreignId); if (fetchStatusMap.getAll(address.getName()).containsValue(FetchStatus.ERROR)) { return true; } @@ -112,15 +112,15 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public void preVerifyFingerprint(Contact contact, String fingerprint) { - axolotlStore.preVerifyFingerprint(contact.getAccount(), contact.getJid().toBareJid().toPreppedString(), fingerprint); + axolotlStore.preVerifyFingerprint(contact.getAccount(), contact.getJid().asBareJid().toString(), fingerprint); } public void preVerifyFingerprint(Account account, String fingerprint) { - axolotlStore.preVerifyFingerprint(account, account.getJid().toBareJid().toPreppedString(), fingerprint); + axolotlStore.preVerifyFingerprint(account, account.getJid().asBareJid().toString(), fingerprint); } public boolean hasVerifiedKeys(String name) { - for(XmppAxolotlSession session : this.sessions.getAll(name).values()) { + for (XmppAxolotlSession session : this.sessions.getAll(name).values()) { if (session.getTrust().isVerified()) { return true; } @@ -201,10 +201,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Bundle information = CryptoHelper.extractCertificateInformation(certificate); try { final String cn = information.getString("subject_cn"); - final Jid jid = Jid.fromString(bareJid); + final Jid jid = Jid.of(bareJid); Log.d(Config.LOGTAG, "setting common name for " + jid + " to " + cn); account.getRoster().getContact(jid).setCommonName(cn); - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { //ignored } } @@ -214,13 +214,12 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } private void fillMap(SQLiteAxolotlStore store) { - List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toPreppedString()); - putDevicesForJid(account.getJid().toBareJid().toPreppedString(), deviceIds, store); + List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().asBareJid().toString()); + putDevicesForJid(account.getJid().asBareJid().toString(), deviceIds, store); for (String address : store.getKnownAddresses()) { deviceIds = store.getSubDeviceSessions(address); putDevicesForJid(address, deviceIds, store); } - } @Override @@ -247,13 +246,13 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { public void clearErrorFor(Jid jid) { synchronized (MAP_LOCK) { - Map<Integer, FetchStatus> devices = this.map.get(jid.toBareJid().toPreppedString()); + Map<Integer, FetchStatus> devices = this.map.get(jid.asBareJid().toString()); if (devices == null) { return; } for (Map.Entry<Integer, FetchStatus> entry : devices.entrySet()) { if (entry.getValue() == FetchStatus.ERROR) { - Log.d(Config.LOGTAG, "resetting error for " + jid.toBareJid() + "(" + entry.getKey() + ")"); + Log.d(Config.LOGTAG, "resetting error for " + jid.asBareJid() + "(" + entry.getKey() + ")"); entry.setValue(FetchStatus.TIMEOUT); } } @@ -262,7 +261,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public static String getLogprefix(Account account) { - return LOGPREFIX + " (" + account.getJid().toBareJid().toString() + "): "; + return LOGPREFIX + " (" + account.getJid().asBareJid().toString() + "): "; } public AxolotlService(Account account, XmppConnectionService connectionService) { @@ -287,28 +286,28 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status) { - return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toPreppedString(), status); + return axolotlStore.getContactKeysWithTrust(account.getJid().asBareJid().toString(), status); } public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status, Jid jid) { - return axolotlStore.getContactKeysWithTrust(jid.toBareJid().toPreppedString(), status); + return axolotlStore.getContactKeysWithTrust(jid.asBareJid().toString(), status); } public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status, List<Jid> jids) { Set<IdentityKey> keys = new HashSet<>(); for (Jid jid : jids) { - keys.addAll(axolotlStore.getContactKeysWithTrust(jid.toPreppedString(), status)); + keys.addAll(axolotlStore.getContactKeysWithTrust(jid.toString(), status)); } return keys; } public long getNumTrustedKeys(Jid jid) { - return axolotlStore.getContactNumTrustedKeys(jid.toBareJid().toPreppedString()); + return axolotlStore.getContactNumTrustedKeys(jid.asBareJid().toString()); } public boolean anyTargetHasNoTrustedKeys(List<Jid> jids) { for (Jid jid : jids) { - if (axolotlStore.getContactNumTrustedKeys(jid.toBareJid().toPreppedString()) == 0) { + if (axolotlStore.getContactNumTrustedKeys(jid.asBareJid().toString()) == 0) { return true; } } @@ -316,16 +315,17 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } private SignalProtocolAddress getAddressForJid(Jid jid) { - return new SignalProtocolAddress(jid.toPreppedString(), 0); + return new SignalProtocolAddress(jid.toString(), 0); } public Collection<XmppAxolotlSession> findOwnSessions() { - SignalProtocolAddress ownAddress = getAddressForJid(account.getJid().toBareJid()); + SignalProtocolAddress ownAddress = getAddressForJid(account.getJid().asBareJid()); ArrayList<XmppAxolotlSession> s = new ArrayList<>(this.sessions.getAll(ownAddress.getName()).values()); Collections.sort(s); return s; } + public Collection<XmppAxolotlSession> findSessionsForContact(Contact contact) { SignalProtocolAddress contactAddress = getAddressForJid(contact.getJid()); ArrayList<XmppAxolotlSession> s = new ArrayList<>(this.sessions.getAll(contactAddress.getName()).values()); @@ -372,12 +372,12 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public void destroy() { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": destroying old axolotl service. no longer in use"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": destroying old axolotl service. no longer in use"); mXmppConnectionService.databaseBackend.wipeAxolotlDb(account); } public AxolotlService makeNew() { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": make new axolotl service"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": make new axolotl service"); return new AxolotlService(this.account, this.mXmppConnectionService); } @@ -386,19 +386,19 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public SignalProtocolAddress getOwnAxolotlAddress() { - return new SignalProtocolAddress(account.getJid().toBareJid().toPreppedString(),getOwnDeviceId()); + return new SignalProtocolAddress(account.getJid().asBareJid().toString(), getOwnDeviceId()); } public Set<Integer> getOwnDeviceIds() { - return this.deviceIds.get(account.getJid().toBareJid()); + return this.deviceIds.get(account.getJid().asBareJid()); } public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) { final int hash = deviceIds.hashCode(); - final boolean me = jid.toBareJid().equals(account.getJid().toBareJid()); + final boolean me = jid.asBareJid().equals(account.getJid().asBareJid()); if (me) { if (hash != 0 && hash == this.lastDeviceListNotificationHash) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ignoring duplicate own device id list"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring duplicate own device id list"); return; } this.lastDeviceListNotificationHash = hash; @@ -407,10 +407,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { if (me) { deviceIds.remove(getOwnDeviceId()); } - Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toPreppedString())); + Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.asBareJid().toString())); expiredDevices.removeAll(deviceIds); for (Integer deviceId : expiredDevices) { - SignalProtocolAddress address = new SignalProtocolAddress(jid.toBareJid().toPreppedString(), deviceId); + SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId); XmppAxolotlSession session = sessions.get(address); if (session != null && session.getFingerprint() != null) { if (session.getTrust().isActive()) { @@ -420,11 +420,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } Set<Integer> newDevices = new HashSet<>(deviceIds); for (Integer deviceId : newDevices) { - SignalProtocolAddress address = new SignalProtocolAddress(jid.toBareJid().toPreppedString(), deviceId); + SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId); XmppAxolotlSession session = sessions.get(address); if (session != null && session.getFingerprint() != null) { if (!session.getTrust().isActive()) { - Log.d(Config.LOGTAG,"reactivating device with fingerprint "+session.getFingerprint()); + Log.d(Config.LOGTAG, "reactivating device with fingerprint " + session.getFingerprint()); session.setTrust(session.getTrust().toActive()); } } @@ -435,7 +435,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } needsPublishing |= this.changeAccessMode.get(); for (Integer deviceId : deviceIds) { - SignalProtocolAddress ownDeviceAddress = new SignalProtocolAddress(jid.toBareJid().toPreppedString(), deviceId); + SignalProtocolAddress ownDeviceAddress = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId); if (sessions.get(ownDeviceAddress) == null) { FetchStatus status = fetchStatusMap.get(ownDeviceAddress); if (status == null || status == FetchStatus.TIMEOUT) { @@ -474,7 +474,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... "); return; } - IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid()); + IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().asBareJid()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -483,8 +483,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } else { Element item = mXmppConnectionService.getIqParser().getItem(packet); Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": retrieved own device list: "+deviceIds); - registerDevices(account.getJid().toBareJid(),deviceIds); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retrieved own device list: " + deviceIds); + registerDevices(account.getJid().asBareJid(), deviceIds); } } }); @@ -492,18 +492,18 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { private Set<Integer> getExpiredDevices() { Set<Integer> devices = new HashSet<>(); - for(XmppAxolotlSession session : findOwnSessions()) { + for (XmppAxolotlSession session : findOwnSessions()) { if (session.getTrust().isActive()) { long diff = System.currentTimeMillis() - session.getTrust().getLastActivation(); if (diff > Config.OMEMO_AUTO_EXPIRY) { - long lastMessageDiff = System.currentTimeMillis() - mXmppConnectionService.databaseBackend.getLastTimeFingerprintUsed(account,session.getFingerprint()); - long hours = Math.round(lastMessageDiff/(1000*60.0*60.0)); + long lastMessageDiff = System.currentTimeMillis() - mXmppConnectionService.databaseBackend.getLastTimeFingerprintUsed(account, session.getFingerprint()); + long hours = Math.round(lastMessageDiff / (1000 * 60.0 * 60.0)); if (lastMessageDiff > Config.OMEMO_AUTO_EXPIRY) { devices.add(session.getRemoteAddress().getDeviceId()); session.setTrust(session.getTrust().toInactive()); - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": added own device " + session.getFingerprint() + " to list of expired devices. Last message received "+hours+" hours ago"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": added own device " + session.getFingerprint() + " to list of expired devices. Last message received " + hours + " hours ago"); } else { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": own device "+session.getFingerprint()+" was active "+hours+" hours ago"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": own device " + session.getFingerprint() + " was active " + hours + " hours ago"); } } } @@ -542,7 +542,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { public void onIqPacketReceived(Account account, IqPacket packet) { Element error = packet.getType() == IqPacket.TYPE.ERROR ? packet.findChild("error") : null; if (firstAttempt && error != null && error.hasChild("precondition-not-met", Namespace.PUBSUB_ERROR)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": precondition wasn't met for device list. pushing node configuration"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": precondition wasn't met for device list. pushing node configuration"); mXmppConnectionService.pushNodeConfiguration(account, AxolotlService.PEP_DEVICE_LIST, publishOptions, new XmppConnectionService.OnConfigurationPushed() { @Override public void onPushSucceeded() { @@ -556,8 +556,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { }); } else { if (AxolotlService.this.changeAccessMode.compareAndSet(true, false)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": done changing access mode"); - account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE,false); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": done changing access mode"); + account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE, false); mXmppConnectionService.databaseBackend.updateAccount(account); } if (packet.getType() == IqPacket.TYPE.ERROR) { @@ -617,14 +617,14 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { this.changeAccessMode.set(account.isOptionSet(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE)); } else { if (account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE, true)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server doesn’t support publish-options. setting for later access mode change"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server doesn’t support publish-options. setting for later access mode change"); mXmppConnectionService.databaseBackend.updateAccount(account); } } if (this.changeAccessMode.get()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server gained publish-options capabilities. changing access model"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server gained publish-options capabilities. changing access model"); } - IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().toBareJid(), getOwnDeviceId()); + IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().asBareJid(), getOwnDeviceId()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -753,7 +753,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { public void onIqPacketReceived(final Account account, IqPacket packet) { Element error = packet.getType() == IqPacket.TYPE.ERROR ? packet.findChild("error") : null; if (firstAttempt && error != null && error.hasChild("precondition-not-met", Namespace.PUBSUB_ERROR)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": precondition wasn't met for bundle. pushing node configuration"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": precondition wasn't met for bundle. pushing node configuration"); final String node = AxolotlService.PEP_BUNDLES + ":" + getOwnDeviceId(); mXmppConnectionService.pushNodeConfiguration(account, node, publishOptions, new XmppConnectionService.OnConfigurationPushed() { @Override @@ -820,7 +820,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { final List<Jid> jids; if (conversation.getMode() == Conversation.MODE_SINGLE) { jids = new ArrayList<>(); - jids.add(conversation.getJid().toBareJid()); + jids.add(conversation.getJid().asBareJid()); } else { jids = conversation.getMucOptions().getMembers(); } @@ -844,7 +844,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { final SignalProtocolAddress 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(Jid.of(address.getName()), address.getDeviceId()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -865,10 +865,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { 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 = Jid.of(address.getName()); Log.d(Config.LOGTAG, "setting common name for " + jid + " to " + cn); account.getRoster().getContact(jid).setCommonName(cn); - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { //ignored } finishBuildingSessionsFromPEP(address); @@ -887,7 +887,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { finishBuildingSessionsFromPEP(address); } }); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { fetchStatusMap.put(address, FetchStatus.SUCCESS); finishBuildingSessionsFromPEP(address); } @@ -896,7 +896,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { private final Set<Integer> PREVIOUSLY_REMOVED_FROM_ANNOUNCEMENT = new HashSet<>(); private void finishBuildingSessionsFromPEP(final SignalProtocolAddress address) { - SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().toBareJid().toPreppedString(), 0); + SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().asBareJid().toString(), 0); Map<Integer, FetchStatus> own = fetchStatusMap.getAll(ownAddress.getName()); Map<Integer, FetchStatus> remote = fetchStatusMap.getAll(address.getName()); if (!own.containsValue(FetchStatus.PENDING) && !remote.containsValue(FetchStatus.PENDING)) { @@ -919,7 +919,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { int id = entry.getKey(); if (entry.getValue() == FetchStatus.ERROR && PREVIOUSLY_REMOVED_FROM_ANNOUNCEMENT.add(id) && ownDeviceIds.remove(id)) { publish = true; - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error fetching own device with id " + id + ". removing from announcement"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error fetching own device with id " + id + ". removing from announcement"); } } if (publish) { @@ -951,14 +951,14 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { if (callback != null) { callbacks.add(callback); } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching device ids for " + jid + " already running. adding callback"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid + " already running. adding callback"); } else { callbacks = new ArrayList<>(); if (callback != null) { callbacks.add(callback); } this.fetchDeviceIdsMap.put(jid, callbacks); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching device ids for " + jid); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid); IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override @@ -1016,7 +1016,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { try { IqPacket bundlesPacket = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice( - Jid.fromString(address.getName()), address.getDeviceId()); + Jid.of(address.getName()), address.getDeviceId()); Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Retrieving bundle: " + bundlesPacket); mXmppConnectionService.sendIqPacket(account, bundlesPacket, new OnIqPacketReceived() { @@ -1082,7 +1082,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } } }); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Got address with invalid jid: " + address.getName()); } } @@ -1093,7 +1093,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Finding devices without session for " + jid); if (deviceIds.get(jid) != null) { for (Integer foreignId : this.deviceIds.get(jid)) { - SignalProtocolAddress address = new SignalProtocolAddress(jid.toPreppedString(), foreignId); + SignalProtocolAddress address = new SignalProtocolAddress(jid.toString(), foreignId); if (sessions.get(address) == null) { IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey(); if (identityKey != null) { @@ -1115,9 +1115,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Have no target devices in PEP!"); } } - if (deviceIds.get(account.getJid().toBareJid()) != null) { - for (Integer ownId : this.deviceIds.get(account.getJid().toBareJid())) { - SignalProtocolAddress address = new SignalProtocolAddress(account.getJid().toBareJid().toPreppedString(), ownId); + if (deviceIds.get(account.getJid().asBareJid()) != null) { + for (Integer ownId : this.deviceIds.get(account.getJid().asBareJid())) { + SignalProtocolAddress address = new SignalProtocolAddress(account.getJid().asBareJid().toString(), ownId); if (sessions.get(address) == null) { IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey(); if (identityKey != null) { @@ -1125,7 +1125,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey); sessions.put(address, session); } else { - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + account.getJid().toBareJid() + ":" + ownId); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + account.getJid().asBareJid() + ":" + ownId); if (fetchStatusMap.get(address) != FetchStatus.ERROR) { addresses.add(address); } else { @@ -1147,7 +1147,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { iterator.remove(); } } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": createSessionsIfNeeded() - jids with empty device list: " + jidsWithEmptyDeviceList); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": createSessionsIfNeeded() - jids with empty device list: " + jidsWithEmptyDeviceList); if (jidsWithEmptyDeviceList.size() > 0) { fetchDeviceIds(jidsWithEmptyDeviceList, new OnMultipleDeviceIdFetched() { @Override @@ -1200,13 +1200,13 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public boolean hasPendingKeyFetches(Account account, List<Jid> jids) { - SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().toBareJid().toPreppedString(), 0); + SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().asBareJid().toString(), 0); if (fetchStatusMap.getAll(ownAddress.getName()).containsValue(FetchStatus.PENDING)) { return true; } synchronized (this.fetchDeviceIdsMap) { for (Jid jid : jids) { - SignalProtocolAddress foreignAddress = new SignalProtocolAddress(jid.toBareJid().toPreppedString(), 0); + SignalProtocolAddress foreignAddress = new SignalProtocolAddress(jid.asBareJid().toString(), 0); if (fetchStatusMap.getAll(foreignAddress.getName()).containsValue(FetchStatus.PENDING) || this.fetchDeviceIdsMap.containsKey(jid)) { return true; } @@ -1244,7 +1244,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { return false; } sessions.addAll(findOwnSessions()); - for (XmppAxolotlSession session : sessions) { + for(XmppAxolotlSession session : sessions) { axolotlMessage.addDevice(session); } return true; @@ -1252,7 +1252,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { @Nullable public XmppAxolotlMessage encrypt(Message message) { - final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId()); + final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId()); final String content; if (message.hasFileOnRemoteHost()) { content = message.getFileParams().url.toString(); @@ -1265,6 +1265,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage()); return null; } + final boolean success; if (message.getType() == Message.TYPE_PRIVATE) { success = buildHeader(axolotlMessage, message.getTrueCounterpart()); @@ -1295,7 +1296,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { executor.execute(new Runnable() { @Override public void run() { - final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId()); + final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId()); if (buildHeader(axolotlMessage, conversation)) { onMessageCreatedCallback.run(axolotlMessage); } else { @@ -1324,7 +1325,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } private XmppAxolotlSession getReceivingSession(XmppAxolotlMessage message) { - SignalProtocolAddress senderAddress = new SignalProtocolAddress(message.getFrom().toPreppedString(), + SignalProtocolAddress senderAddress = new SignalProtocolAddress(message.getFrom().toString(), message.getSenderDeviceId()); XmppAxolotlSession session = sessions.get(senderAddress); if (session == null) { @@ -1348,7 +1349,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { postPreKeyMessageHandling(session, preKeyId, postponePreKeyMessageHandling); } } catch (CryptoFailedException e) { - Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message from "+message.getFrom()+": " + e.getMessage()); + Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message from " + message.getFrom() + ": " + e.getMessage()); } if (session.isFresh() && plaintextMessage != null) { @@ -1380,17 +1381,18 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } private void completeSession(XmppAxolotlSession session) { - final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId()); + final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId()); axolotlMessage.addDevice(session); try { - Jid jid = Jid.fromString(session.getRemoteAddress().getName()); + Jid jid = Jid.of(session.getRemoteAddress().getName()); MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage); mXmppConnectionService.sendMessagePacket(account, packet); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { throw new Error("Remote addresses are created from jid and should convert back to jid", e); } } + public XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(XmppAxolotlMessage message, final boolean postponePreKeyMessageHandling) { XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage; @@ -1402,7 +1404,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { postPreKeyMessageHandling(session, preKeyId, postponePreKeyMessageHandling); } } catch (CryptoFailedException e) { - Log.d(Config.LOGTAG,"could not decrypt keyTransport message "+e.getMessage()); + Log.d(Config.LOGTAG, "could not decrypt keyTransport message " + e.getMessage()); keyTransportMessage = null; } @@ -1420,8 +1422,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { if (session.getIdentityKey() != null) { verifySessionWithPEP(session); } else { - Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": identity key was empty after reloading for x509 verification"); + Log.e(Config.LOGTAG, account.getJid().asBareJid() + ": identity key was empty after reloading for x509 verification"); } } } -} +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java b/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java index 72a62f590..0f7823d2d 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java @@ -191,7 +191,7 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { FingerprintStatus status = getFingerprintStatus(fingerprint); if (status == null) { if (mXmppConnectionService.blindTrustBeforeVerification() && !account.getAxolotlService().hasVerifiedKeys(address.getName())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": blindly trusted " + fingerprint + " of " + address.getName()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": blindly trusted " + fingerprint + " of " + address.getName()); status = FingerprintStatus.createActiveTrusted(); } else { status = FingerprintStatus.createActiveUndecided(); diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java index ac16ccc47..603eedde8 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java @@ -22,7 +22,7 @@ import javax.crypto.spec.SecretKeySpec; import de.pixart.messenger.Config; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class XmppAxolotlMessage { public static final String CONTAINERTAG = "encrypted"; diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java index 771ff9f19..cb84ebc63 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java @@ -3,7 +3,6 @@ package de.pixart.messenger.crypto.axolotl; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import org.whispersystems.libsignal.SignalProtocolAddress; import org.whispersystems.libsignal.DuplicateMessageException; import org.whispersystems.libsignal.IdentityKey; import org.whispersystems.libsignal.InvalidKeyException; @@ -13,6 +12,7 @@ import org.whispersystems.libsignal.InvalidVersionException; import org.whispersystems.libsignal.LegacyMessageException; import org.whispersystems.libsignal.NoSessionException; import org.whispersystems.libsignal.SessionCipher; +import org.whispersystems.libsignal.SignalProtocolAddress; import org.whispersystems.libsignal.UntrustedIdentityException; import org.whispersystems.libsignal.protocol.CiphertextMessage; import org.whispersystems.libsignal.protocol.PreKeySignalMessage; diff --git a/src/main/java/de/pixart/messenger/crypto/sasl/External.java b/src/main/java/de/pixart/messenger/crypto/sasl/External.java index b80d174f0..e1b21e59e 100644 --- a/src/main/java/de/pixart/messenger/crypto/sasl/External.java +++ b/src/main/java/de/pixart/messenger/crypto/sasl/External.java @@ -25,6 +25,6 @@ public class External extends SaslMechanism { @Override public String getClientFirstMessage() { - return Base64.encodeToString(account.getJid().toBareJid().toString().getBytes(), Base64.NO_WRAP); + return Base64.encodeToString(account.getJid().asBareJid().toString().getBytes(), Base64.NO_WRAP); } } diff --git a/src/main/java/de/pixart/messenger/crypto/sasl/ScramMechanism.java b/src/main/java/de/pixart/messenger/crypto/sasl/ScramMechanism.java index 8dfffaeba..046b68fda 100644 --- a/src/main/java/de/pixart/messenger/crypto/sasl/ScramMechanism.java +++ b/src/main/java/de/pixart/messenger/crypto/sasl/ScramMechanism.java @@ -149,7 +149,7 @@ abstract class ScramMechanism extends SaslMechanism { // Map keys are "bytesToHex(JID),bytesToHex(password),bytesToHex(salt),iterations". final KeyPair keys = CACHE.get( - CryptoHelper.bytesToHex(account.getJid().toBareJid().toString().getBytes()) + "," + CryptoHelper.bytesToHex(account.getJid().asBareJid().toString().getBytes()) + "," + CryptoHelper.bytesToHex(account.getPassword().getBytes()) + "," + CryptoHelper.bytesToHex(salt.getBytes()) + "," + String.valueOf(iterationCount) diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 8b2eef3eb..4dcd028ba 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -3,6 +3,7 @@ package de.pixart.messenger.entities; import android.content.ContentValues; import android.database.Cursor; import android.os.SystemClock; +import android.util.Log; import android.util.Pair; import net.java.otr4j.crypto.OtrCryptoEngineImpl; @@ -30,8 +31,7 @@ import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Account extends AbstractEntity { @@ -287,13 +287,16 @@ public class Account extends AbstractEntity { } public static Account fromCursor(final Cursor cursor) { - Jid jid = null; + final Jid jid; try { - jid = Jid.fromParts( + String resource = cursor.getString(cursor.getColumnIndex(RESOURCE)); + jid = Jid.of( cursor.getString(cursor.getColumnIndex(USERNAME)), cursor.getString(cursor.getColumnIndex(SERVER)), - cursor.getString(cursor.getColumnIndex(RESOURCE))); - } catch (final InvalidJidException ignored) { + resource == null || resource.trim().isEmpty() ? null : resource); + } catch (final IllegalArgumentException ignored) { + Log.d(Config.LOGTAG, cursor.getString(cursor.getColumnIndex(USERNAME)) + "@" + cursor.getString(cursor.getColumnIndex(SERVER))); + throw new AssertionError(ignored); } return new Account(cursor.getString(cursor.getColumnIndex(UUID)), jid, @@ -324,13 +327,13 @@ public class Account extends AbstractEntity { } public String getUsername() { - return jid.getLocalpart(); + return jid.getLocal(); } public boolean setJid(final Jid next) { final Jid previousFull = this.jid; - final Jid prev = this.jid != null ? this.jid.toBareJid() : null; - final boolean changed = prev == null || (next != null && !prev.equals(next.toBareJid())); + final Jid prev = this.jid != null ? this.jid.asBareJid() : null; + final boolean changed = prev == null || (next != null && !prev.equals(next.asBareJid())); if (changed) { final AxolotlService oldAxolotlService = this.axolotlService; if (oldAxolotlService != null) { @@ -340,11 +343,11 @@ public class Account extends AbstractEntity { } } this.jid = next; - return next != null && next.equals(previousFull); + return next != null && !next.equals(previousFull); } public Jid getServer() { - return jid.toDomainJid(); + return Jid.ofDomain(jid.getDomain()); } public String getPassword() { @@ -419,20 +422,11 @@ public class Account extends AbstractEntity { } public String getResource() { - return jid.getResourcepart(); + return jid.getResource(); } - public boolean setResource(final String resource) { - final String oldResource = jid.getResourcepart(); - if (oldResource == null || !oldResource.equals(resource)) { - try { - jid = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), resource); - return true; - } catch (final InvalidJidException ignored) { - return true; - } - } - return false; + public void setResource(final String resource) { + this.jid = this.jid.withResource(resource); } public Jid getJid() { @@ -481,8 +475,8 @@ public class Account extends AbstractEntity { public ContentValues getContentValues() { final ContentValues values = new ContentValues(); values.put(UUID, uuid); - values.put(USERNAME, jid.getLocalpart()); - values.put(SERVER, jid.getDomainpart()); + values.put(USERNAME, jid.getLocal()); + values.put(SERVER, jid.getDomain()); values.put(PASSWORD, password); values.put(OPTIONS, options); synchronized (this.keys) { @@ -495,7 +489,7 @@ public class Account extends AbstractEntity { values.put(PORT, port); values.put(STATUS, presenceStatus.toShowString()); values.put(STATUS_MESSAGE, presenceStatusMessage); - values.put(RESOURCE, jid.getResourcepart()); + values.put(RESOURCE, jid.getResource()); return values; } @@ -625,7 +619,7 @@ public class Account extends AbstractEntity { public Bookmark getBookmark(final Jid jid) { for (final Bookmark bookmark : this.bookmarks) { - if (bookmark.getJid() != null && jid.toBareJid().equals(bookmark.getJid().toBareJid())) { + if (bookmark.getJid() != null && jid.asBareJid().equals(bookmark.getJid().asBareJid())) { return bookmark; } } @@ -659,7 +653,7 @@ public class Account extends AbstractEntity { public String getShareableUri() { List<XmppUri.Fingerprint> fingerprints = this.getFingerprints(); - String uri = "xmpp:" + this.getJid().toBareJid().toString(); + String uri = "xmpp:" + this.getJid().asBareJid().toString(); if (fingerprints.size() > 0) { return XmppUri.getFingerprintUri(uri,fingerprints,';'); } else { @@ -668,7 +662,7 @@ public class Account extends AbstractEntity { } public String getShareableLink() { List<XmppUri.Fingerprint> fingerprints = this.getFingerprints(); - String uri = Config.inviteUserURL+this.getJid().toBareJid().toString(); + String uri = Config.inviteUserURL+this.getJid().asBareJid().toString(); if (fingerprints.size() > 0) { return XmppUri.getFingerprintUri(uri,fingerprints,'&'); } else { @@ -696,11 +690,11 @@ public class Account extends AbstractEntity { public boolean isBlocked(final ListItem contact) { final Jid jid = contact.getJid(); - return jid != null && (blocklist.contains(jid.toBareJid()) || blocklist.contains(jid.toDomainJid())); + return jid != null && (blocklist.contains(jid.asBareJid()) || blocklist.contains(Jid.ofDomain(jid.getDomain()))); } public boolean isBlocked(final Jid jid) { - return jid != null && blocklist.contains(jid.toBareJid()); + return jid != null && blocklist.contains(jid.asBareJid()); } public Collection<Jid> getBlocklist() { diff --git a/src/main/java/de/pixart/messenger/entities/Blockable.java b/src/main/java/de/pixart/messenger/entities/Blockable.java index f7484df8a..e735b4a73 100644 --- a/src/main/java/de/pixart/messenger/entities/Blockable.java +++ b/src/main/java/de/pixart/messenger/entities/Blockable.java @@ -1,6 +1,6 @@ package de.pixart.messenger.entities; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public interface Blockable { boolean isBlocked(); diff --git a/src/main/java/de/pixart/messenger/entities/Bookmark.java b/src/main/java/de/pixart/messenger/entities/Bookmark.java index 8074c9430..27997e750 100644 --- a/src/main/java/de/pixart/messenger/entities/Bookmark.java +++ b/src/main/java/de/pixart/messenger/entities/Bookmark.java @@ -9,7 +9,7 @@ import java.util.Locale; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Bookmark extends Element implements ListItem { @@ -58,7 +58,7 @@ public class Bookmark extends Element implements ListItem { return getBookmarkName().trim(); } else { Jid jid = this.getJid(); - String name = jid != null ? jid.getLocalpart() : getAttribute("jid"); + String name = jid != null ? jid.getLocal() : getAttribute("jid"); return name != null ? name : ""; } } diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java index 63d8f6352..827840442 100644 --- a/src/main/java/de/pixart/messenger/entities/Contact.java +++ b/src/main/java/de/pixart/messenger/entities/Contact.java @@ -18,9 +18,8 @@ import de.pixart.messenger.Config; import de.pixart.messenger.utils.JidHelper; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; +import rocks.xmpp.addr.Jid; public class Contact implements ListItem, Blockable { public static final String TABLENAME = "contacts"; @@ -93,8 +92,8 @@ public class Contact implements ListItem, Blockable { public static Contact fromCursor(final Cursor cursor) { final Jid jid; try { - jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID)), true); - } catch (final InvalidJidException e) { + jid = Jid.of(cursor.getString(cursor.getColumnIndex(JID))); + } catch (final IllegalArgumentException e) { // TODO: Borked DB... handle this somehow? return null; } @@ -121,10 +120,10 @@ public class Contact implements ListItem, Blockable { return this.serverName; } else if (this.presenceName != null && !this.presenceName.isEmpty() && mutualPresenceSubscription()) { return this.presenceName; - } else if (jid.hasLocalpart()) { + } else if (jid.getLocal() != null) { return JidHelper.localPartOrFallback(jid); } else { - return jid.getDomainpart(); + return jid.getDomain(); } } @@ -200,7 +199,7 @@ public class Contact implements ListItem, Blockable { values.put(ACCOUNT, accountUuid); values.put(SYSTEMNAME, systemName); values.put(SERVERNAME, serverName); - values.put(JID, jid.toPreppedString()); + values.put(JID, jid.toString()); values.put(OPTIONS, subscription); values.put(SYSTEMACCOUNT, systemAccount); values.put(PHOTOURI, photoUri); @@ -453,7 +452,7 @@ public class Contact implements ListItem, Blockable { } public Jid getServer() { - return getJid().toDomainJid(); + return Jid.ofDomain(getJid().getDomain()); } public boolean setAvatar(Avatar avatar) { @@ -507,20 +506,20 @@ public class Contact implements ListItem, Blockable { @Override public boolean isDomainBlocked() { - return getAccount().isBlocked(this.getJid().toDomainJid()); + return getAccount().isBlocked(Jid.ofDomain(this.getJid().getDomain())); } @Override public Jid getBlockedJid() { if (isDomainBlocked()) { - return getJid().toDomainJid(); + return Jid.ofDomain(getJid().getDomain()); } else { return getJid(); } } public boolean isSelf() { - return account.getJid().toBareJid().equals(getJid().toBareJid()); + return account.getJid().asBareJid().equals(getJid().asBareJid()); } public void setCommonName(String cn) { diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 9a856a738..e4ec95f3b 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -28,9 +28,8 @@ import de.pixart.messenger.crypto.PgpDecryptionService; import de.pixart.messenger.crypto.axolotl.AxolotlService; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.xmpp.chatstate.ChatState; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.mam.MamReference; +import rocks.xmpp.addr.Jid; public class Conversation extends AbstractEntity implements Blockable, Comparable<Conversation> { @@ -384,7 +383,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public List<Jid> getAcceptedCryptoTargets() { if (mode == MODE_SINGLE) { - return Collections.singletonList(getJid().toBareJid()); + return Collections.singletonList(getJid().asBareJid()); } else { return getJidListAttribute(ATTRIBUTE_CRYPTO_TARGETS); } @@ -517,11 +516,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl if (generatedName != null) { return generatedName; } else { - return getJid().getUnescapedLocalpart(); + return getJid().getLocal(); } } } else if (isWithStranger()) { - return contactJid.toBareJid().toString(); + return contactJid.asBareJid().toString(); } else { return this.getContact().getDisplayName(); } @@ -583,7 +582,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl values.put(NAME, name); values.put(CONTACT, contactUuid); values.put(ACCOUNT, accountUuid); - values.put(CONTACTJID, contactJid.toPreppedString()); + values.put(CONTACTJID, contactJid.toString()); values.put(CREATED, created); values.put(STATUS, status); values.put(MODE, mode); @@ -594,8 +593,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public static Conversation fromCursor(Cursor cursor) { Jid jid; try { - jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)), true); - } catch (final InvalidJidException e) { + jid = Jid.of(cursor.getString(cursor.getColumnIndex(CONTACTJID))); + } catch (final IllegalArgumentException e) { // Borked DB.. jid = null; } @@ -626,7 +625,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl if (this.otrSession != null) { return this.otrSession; } else { - final SessionID sessionId = new SessionID(this.getJid().toBareJid().toString(), + final SessionID sessionId = new SessionID(this.getJid().asBareJid().toString(), presence, "xmpp"); this.otrSession = new SessionImpl(sessionId, getAccount().getOtrService()); @@ -907,7 +906,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public boolean setAttribute(String key, List<Jid> jids) { JSONArray array = new JSONArray(); for (Jid jid : jids) { - array.put(jid.toBareJid().toString()); + array.put(jid.asBareJid().toString()); } synchronized (this.attributes) { try { @@ -937,8 +936,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl JSONArray array = this.attributes.getJSONArray(key); for (int i = 0; i < array.length(); ++i) { try { - list.add(Jid.fromString(array.getString(i))); - } catch (InvalidJidException e) { + list.add(Jid.of(array.getString(i))); + } catch (IllegalArgumentException e) { //ignored } } @@ -1089,7 +1088,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public boolean isWithStranger() { return mode == MODE_SINGLE - && !getJid().equals(account.getJid().toDomainJid()) + && !getJid().equals(Jid.ofDomain(account.getJid().getDomain())) && !getContact().showInRoster() && sentMessagesCount() == 0; } diff --git a/src/main/java/de/pixart/messenger/entities/ListItem.java b/src/main/java/de/pixart/messenger/entities/ListItem.java index 3b27c1baa..df1ba75b0 100644 --- a/src/main/java/de/pixart/messenger/entities/ListItem.java +++ b/src/main/java/de/pixart/messenger/entities/ListItem.java @@ -4,7 +4,7 @@ import android.content.Context; import java.util.List; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public interface ListItem extends Comparable<ListItem> { String getDisplayName(); diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 859999309..501a394ad 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -23,8 +23,7 @@ import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.MimeUtils; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.XmppUri; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Message extends AbstractEntity { @@ -117,7 +116,7 @@ public class Message extends AbstractEntity { public Message(Conversation conversation, String body, int encryption, int status) { this(conversation, java.util.UUID.randomUUID().toString(), conversation.getUuid(), - conversation.getJid() == null ? null : conversation.getJid().toBareJid(), + conversation.getJid() == null ? null : conversation.getJid().asBareJid(), null, body, System.currentTimeMillis(), @@ -172,11 +171,11 @@ public class Message extends AbstractEntity { try { String value = cursor.getString(cursor.getColumnIndex(COUNTERPART)); if (value != null) { - jid = Jid.fromString(value, true); + jid = Jid.of(value); } else { jid = null; } - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { jid = null; } catch (IllegalStateException e) { return null; // message too long? @@ -185,11 +184,11 @@ public class Message extends AbstractEntity { try { String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)); if (value != null) { - trueCounterpart = Jid.fromString(value, true); + trueCounterpart = Jid.of(value); } else { trueCounterpart = null; } - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { trueCounterpart = null; } return new Message(conversation, @@ -246,12 +245,12 @@ public class Message extends AbstractEntity { if (counterpart == null) { values.putNull(COUNTERPART); } else { - values.put(COUNTERPART, counterpart.toPreppedString()); + values.put(COUNTERPART, counterpart.toString()); } if (trueCounterpart == null) { values.putNull(TRUE_COUNTERPART); } else { - values.put(TRUE_COUNTERPART, trueCounterpart.toPreppedString()); + values.put(TRUE_COUNTERPART, trueCounterpart.toString()); } values.put(BODY, body.length() > Config.MAX_STORAGE_MESSAGE_CHARS ? body.substring(0,Config.MAX_STORAGE_MESSAGE_CHARS) : body); values.put(TIME_SENT, timeSent); @@ -439,7 +438,7 @@ public class Message extends AbstractEntity { public boolean addReadByMarker(ReadByMarker readByMarker) { if (readByMarker.getRealJid() != null) { - if (readByMarker.getRealJid().toBareJid().equals(trueCounterpart)) { + if (readByMarker.getRealJid().asBareJid().equals(trueCounterpart)) { Log.d(Config.LOGTAG, "trying to add read marker by " + readByMarker.getRealJid() + " to " + body); return false; } @@ -573,7 +572,7 @@ public class Message extends AbstractEntity { ((this.axolotlFingerprint == null && message.axolotlFingerprint == null) || this.axolotlFingerprint.equals(message.getFingerprint())) && UIHelper.sameDay(message.getTimeSent(), this.getTimeSent()) && this.getReadByMarkers().equals(message.getReadByMarkers()) && - !this.conversation.getJid().toBareJid().toString().equals(Config.BUG_REPORTS) + !this.conversation.getJid().asBareJid().toString().equals(Config.BUG_REPORTS) ); } @@ -655,15 +654,15 @@ public class Message extends AbstractEntity { public boolean fixCounterpart() { Presences presences = conversation.getContact().getPresences(); - if (counterpart != null && presences.has(counterpart.getResourcepart())) { + if (counterpart != null && presences.has(counterpart.getResource())) { return true; } else if (presences.size() >= 1) { try { - counterpart = Jid.fromParts(conversation.getJid().getLocalpart(), - conversation.getJid().getDomainpart(), + counterpart = Jid.of(conversation.getJid().getLocal(), + conversation.getJid().getDomain(), presences.toResourceArray()[0]); return true; - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { counterpart = null; return false; } diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index c1dca783c..25d059c93 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -15,9 +15,8 @@ import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.forms.Data; import de.pixart.messenger.xmpp.forms.Field; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; +import rocks.xmpp.addr.Jid; @SuppressLint("DefaultLocale") public class MucOptions { @@ -179,11 +178,11 @@ public class MucOptions { } public String getName() { - return fullJid == null ? null : fullJid.getResourcepart(); + return fullJid == null ? null : fullJid.getResource(); } public void setRealJid(Jid jid) { - this.realJid = jid != null ? jid.toBareJid() : null; + this.realJid = jid != null ? jid.asBareJid() : null; } public Role getRole() { @@ -319,7 +318,7 @@ public class MucOptions { } public boolean realJidMatchesAccount() { - return realJid != null && realJid.equals(options.account.getJid().toBareJid()); + return realJid != null && realJid.equals(options.account.getJid().asBareJid()); } @Override @@ -448,7 +447,7 @@ public class MucOptions { break; } } - boolean self = user.realJid != null && user.realJid.equals(account.getJid().toBareJid()); + boolean self = user.realJid != null && user.realJid.equals(account.getJid().asBareJid()); if (membersOnly() && nonanonymous() && user.affiliation.ranks(Affiliation.MEMBER) @@ -536,7 +535,7 @@ public class MucOptions { public User findUser(ReadByMarker readByMarker) { if (readByMarker.getRealJid() != null) { - User user = findUserByRealJid(readByMarker.getRealJid().toBareJid()); + User user = findUserByRealJid(readByMarker.getRealJid().asBareJid()); if (user == null) { user = new User(this, readByMarker.getFullJid()); user.setRealJid(readByMarker.getRealJid()); @@ -550,7 +549,7 @@ public class MucOptions { } public boolean isContactInRoom(Contact contact) { - return findUserByRealJid(contact.getJid().toBareJid()) != null; + return findUserByRealJid(contact.getJid().asBareJid()) != null; } public boolean isUserInRoom(Jid jid) { @@ -606,7 +605,7 @@ public class MucOptions { public List<User> getUsers(int max) { ArrayList<User> subset = new ArrayList<>(); HashSet<Jid> jids = new HashSet<>(); - jids.add(account.getJid().toBareJid()); + jids.add(account.getJid().asBareJid()); synchronized (users) { for(User user : users) { if (user.getRealJid() == null || jids.add(user.getRealJid())) { @@ -632,7 +631,7 @@ public class MucOptions { && !conversation.getBookmark().getNick().trim().isEmpty()) { return conversation.getBookmark().getNick().trim(); } else if (!conversation.getJid().isBareJid()) { - return conversation.getJid().getResourcepart(); + return conversation.getJid().getResource(); } else { return JidHelper.localPartOrFallback(account.getJid()); } @@ -768,15 +767,15 @@ public class MucOptions { public Jid createJoinJid(String nick) { try { - return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick); - } catch (final InvalidJidException e) { + return Jid.of(this.conversation.getJid().asBareJid().toString() + "/" + nick); + } catch (final IllegalArgumentException e) { return null; } } public Jid getTrueCounterpart(Jid jid) { if (jid.equals(getSelf().getFullJid())) { - return account.getJid().toBareJid(); + return account.getJid().asBareJid(); } User user = findUserByFullJid(jid); return user == null ? null : user.realJid; diff --git a/src/main/java/de/pixart/messenger/entities/ReadByMarker.java b/src/main/java/de/pixart/messenger/entities/ReadByMarker.java index 3162c26c6..ec2d1aa73 100644 --- a/src/main/java/de/pixart/messenger/entities/ReadByMarker.java +++ b/src/main/java/de/pixart/messenger/entities/ReadByMarker.java @@ -8,8 +8,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ReadByMarker { @@ -52,14 +51,14 @@ public class ReadByMarker { JSONObject jsonObject = new JSONObject(); if (fullJid != null) { try { - jsonObject.put("fullJid", fullJid.toPreppedString()); + jsonObject.put("fullJid", fullJid.toString()); } catch (JSONException e) { //ignore } } if (realJid != null) { try { - jsonObject.put("realJid", realJid.toPreppedString()); + jsonObject.put("realJid", realJid.toString()); } catch (JSONException e) { //ignore } @@ -82,7 +81,7 @@ public class ReadByMarker { public static ReadByMarker from(Jid fullJid, Jid realJid) { final ReadByMarker marker = new ReadByMarker(); marker.fullJid = fullJid; - marker.realJid = realJid == null ? null : realJid.toBareJid(); + marker.realJid = realJid == null ? null : realJid.asBareJid(); return marker; } @@ -111,13 +110,13 @@ public class ReadByMarker { public static ReadByMarker fromJson(JSONObject jsonObject) { ReadByMarker marker = new ReadByMarker(); try { - marker.fullJid = Jid.fromString(jsonObject.getString("fullJid"), true); - } catch (JSONException | InvalidJidException e) { + marker.fullJid = Jid.of(jsonObject.getString("fullJid")); + } catch (JSONException | IllegalArgumentException e) { marker.fullJid = null; } try { - marker.realJid = Jid.fromString(jsonObject.getString("realJid"), true); - } catch (JSONException | InvalidJidException e) { + marker.realJid = Jid.of(jsonObject.getString("realJid")); + } catch (JSONException | IllegalArgumentException e) { marker.realJid = null; } return marker; @@ -142,7 +141,7 @@ public class ReadByMarker { public static boolean contains(ReadByMarker needle, Set<ReadByMarker> readByMarkers) { for(ReadByMarker marker : readByMarkers) { if (marker.realJid != null && needle.realJid != null) { - if (marker.realJid.toBareJid().equals(needle.realJid.toBareJid())) { + if (marker.realJid.asBareJid().equals(needle.realJid.asBareJid())) { return true; } } else if (marker.fullJid != null && needle.fullJid != null) { diff --git a/src/main/java/de/pixart/messenger/entities/ReceiptRequest.java b/src/main/java/de/pixart/messenger/entities/ReceiptRequest.java index 440f13d6f..1b7065d29 100644 --- a/src/main/java/de/pixart/messenger/entities/ReceiptRequest.java +++ b/src/main/java/de/pixart/messenger/entities/ReceiptRequest.java @@ -29,7 +29,7 @@ package de.pixart.messenger.entities; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ReceiptRequest { @@ -43,7 +43,7 @@ public class ReceiptRequest { if (jid == null) { throw new IllegalArgumentException("jid must not be null"); } - this.jid = jid.toBareJid(); + this.jid = jid.asBareJid(); this.id = id; } diff --git a/src/main/java/de/pixart/messenger/entities/Roster.java b/src/main/java/de/pixart/messenger/entities/Roster.java index bdb7265f3..97ad41114 100644 --- a/src/main/java/de/pixart/messenger/entities/Roster.java +++ b/src/main/java/de/pixart/messenger/entities/Roster.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Roster { final Account account; @@ -21,7 +21,7 @@ public class Roster { return null; } synchronized (this.contacts) { - Contact contact = contacts.get(jid.toBareJid()); + Contact contact = contacts.get(jid.asBareJid()); if (contact != null && contact.showInRoster()) { return contact; } else { @@ -32,13 +32,13 @@ public class Roster { public Contact getContact(final Jid jid) { synchronized (this.contacts) { - if (!contacts.containsKey(jid.toBareJid())) { - Contact contact = new Contact(jid.toBareJid()); + if (!contacts.containsKey(jid.asBareJid())) { + Contact contact = new Contact(jid.asBareJid()); contact.setAccount(account); - contacts.put(contact.getJid().toBareJid(), contact); + contacts.put(contact.getJid().asBareJid(), contact); return contact; } - return contacts.get(jid.toBareJid()); + return contacts.get(jid.asBareJid()); } } @@ -78,7 +78,7 @@ public class Roster { contact.setAccount(account); contact.setOption(Contact.Options.IN_ROSTER); synchronized (this.contacts) { - contacts.put(contact.getJid().toBareJid(), contact); + contacts.put(contact.getJid().asBareJid(), contact); } } diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index 234ddc3b4..a8f7d2e0c 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -31,9 +31,9 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.forms.Data; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class IqGenerator extends AbstractGenerator { @@ -285,7 +285,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) { final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); final Element block = iq.addChild("block", Namespace.BLOCKING); - final Element item = block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); + final Element item = block.addChild("item").setAttribute("jid", jid.asBareJid().toString()); if (reportSpam) { item.addChild("report", "urn:xmpp:reporting:0").addChild("spam"); } @@ -296,7 +296,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket generateSetUnblockRequest(final Jid jid) { final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); final Element block = iq.addChild("unblock", Namespace.BLOCKING); - block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); + block.addChild("item").setAttribute("jid", jid.asBareJid().toString()); return iq; } @@ -305,7 +305,7 @@ public class IqGenerator extends AbstractGenerator { packet.setTo(account.getServer()); final Element query = packet.addChild("query", Namespace.REGISTER); final Jid jid = account.getJid(); - query.addChild("username").setContent(jid.getLocalpart()); + query.addChild("username").setContent(jid.getLocal()); query.addChild("password").setContent(newPassword); return packet; } @@ -318,7 +318,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) { IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(conference.getJid().toBareJid()); + packet.setTo(conference.getJid().asBareJid()); packet.setFrom(conference.getAccount().getJid()); Element query = packet.query("http://jabber.org/protocol/muc#admin"); for (Jid jid : jids) { @@ -331,7 +331,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket changeRole(Conversation conference, String nick, String role) { IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(conference.getJid().toBareJid()); + packet.setTo(conference.getJid().asBareJid()); packet.setFrom(conference.getAccount().getJid()); Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item"); item.setAttribute("nick", nick); @@ -341,11 +341,11 @@ public class IqGenerator extends AbstractGenerator { public IqPacket destroyConference(Conversation conference) { IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(conference.getJid().toBareJid()); + packet.setTo(conference.getJid().asBareJid()); packet.setFrom(conference.getAccount().getJid()); final Element query = packet.addChild("query", "http://jabber.org/protocol/muc#owner"); final Element destroy = query.addChild("destroy"); - destroy.setAttribute("jid", conference.getJid().toBareJid().toString()); + destroy.setAttribute("jid", conference.getJid().asBareJid().toString()); Log.d(Config.LOGTAG, "Destroy: " + packet.toString()); return packet; } @@ -379,7 +379,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().toBareJid()); + register.setFrom(account.getJid().asBareJid()); register.setTo(account.getServer()); register.setId(id); Element query = register.query("jabber:iq:register"); @@ -418,7 +418,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket queryAffiliation(Conversation conversation, String affiliation) { IqPacket packet = new IqPacket(IqPacket.TYPE.GET); - packet.setTo(conversation.getJid().toBareJid()); + packet.setTo(conversation.getJid().asBareJid()); packet.query("http://jabber.org/protocol/muc#admin").addChild("item").setAttribute("affiliation", affiliation); return packet; } diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java index cc641a3b8..0a113b420 100644 --- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java @@ -20,8 +20,8 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.chatstate.ChatState; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.MessagePacket; +import rocks.xmpp.addr.Jid; public class MessageGenerator extends AbstractGenerator { public static final String OTR_FALLBACK_MESSAGE = "I would like to start a private (OTR encrypted) conversation but your client doesn’t seem to support that"; @@ -51,7 +51,7 @@ public class MessageGenerator extends AbstractGenerator { packet.addChild("request", "urn:xmpp:receipts"); } } else { - packet.setTo(message.getCounterpart().toBareJid()); + packet.setTo(message.getCounterpart().asBareJid()); packet.setType(MessagePacket.TYPE_GROUPCHAT); } if (conversation.isSingleOrPrivateAndNonAnonymous() && message.getType() != Message.TYPE_PRIVATE) { @@ -171,7 +171,7 @@ public class MessageGenerator extends AbstractGenerator { final Account account = conversation.getAccount(); MessagePacket packet = new MessagePacket(); packet.setType(conversation.getMode() == Conversation.MODE_MULTI ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT); - packet.setTo(conversation.getJid().toBareJid()); + packet.setTo(conversation.getJid().asBareJid()); packet.setFrom(account.getJid()); packet.addChild(ChatState.toElement(conversation.getOutgoingChatState())); packet.addChild("no-store", "urn:xmpp:hints"); @@ -182,12 +182,12 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket confirm(final Account account, final Jid to, final String id, final Jid counterpart, final boolean groupChat) { MessagePacket packet = new MessagePacket(); packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT); - packet.setTo(groupChat ? to.toBareJid() : to); + packet.setTo(groupChat ? to.asBareJid() : to); packet.setFrom(account.getJid()); Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0"); displayed.setAttribute("id", id); if (groupChat && counterpart != null) { - displayed.setAttribute("sender", counterpart.toPreppedString()); + displayed.setAttribute("sender", counterpart.toString()); } packet.addChild("store", "urn:xmpp:hints"); return packet; @@ -196,11 +196,11 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket conferenceSubject(Conversation conversation, String subject) { MessagePacket packet = new MessagePacket(); packet.setType(MessagePacket.TYPE_GROUPCHAT); - packet.setTo(conversation.getJid().toBareJid()); + packet.setTo(conversation.getJid().asBareJid()); Element subjectChild = new Element("subject"); subjectChild.setContent(subject); packet.addChild(subjectChild); - packet.setFrom(conversation.getAccount().getJid().toBareJid()); + packet.setFrom(conversation.getAccount().getJid().asBareJid()); return packet; } @@ -210,7 +210,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(contact); packet.setFrom(conversation.getAccount().getJid()); Element x = packet.addChild("x", "jabber:x:conference"); - x.setAttribute("jid", conversation.getJid().toBareJid().toString()); + x.setAttribute("jid", conversation.getJid().asBareJid().toString()); String password = conversation.getMucOptions().getPassword(); if (password != null) { x.setAttribute("password", password); @@ -220,12 +220,12 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket invite(Conversation conversation, Jid contact) { MessagePacket packet = new MessagePacket(); - packet.setTo(conversation.getJid().toBareJid()); + packet.setTo(conversation.getJid().asBareJid()); packet.setFrom(conversation.getAccount().getJid()); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user"); Element invite = new Element("invite"); - invite.setAttribute("to", contact.toBareJid().toString()); + invite.setAttribute("to", contact.asBareJid().toString()); x.addChild(invite); packet.addChild(x); return packet; diff --git a/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java b/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java index 9bbf2191d..b66f6b184 100644 --- a/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/PresenceGenerator.java @@ -18,7 +18,7 @@ public class PresenceGenerator extends AbstractGenerator { PresencePacket packet = new PresencePacket(); packet.setAttribute("type", type); packet.setTo(contact.getJid()); - packet.setFrom(contact.getAccount().getJid().toBareJid()); + packet.setFrom(contact.getAccount().getJid().asBareJid()); return packet; } diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 8a1d37a3f..7dd74fb15 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -29,8 +29,8 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class HttpUploadConnection implements Transferable { @@ -121,7 +121,7 @@ public class HttpUploadConnection implements Transferable { try { pair = AbstractConnectionManager.createInputStream(file, true); } catch (FileNotFoundException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not find file to upload - " + e.getMessage()); fail(e.getMessage()); return; } @@ -220,7 +220,7 @@ public class HttpUploadConnection implements Transferable { mXmppConnectionService.getFileBackend().updateFileParams(message, mGetUrl); mXmppConnectionService.getFileBackend().updateMediaScanner(file); message.setTransferable(null); - message.setCounterpart(message.getConversation().getJid().toBareJid()); + message.setCounterpart(message.getConversation().getJid().asBareJid()); mXmppConnectionService.resendMessage(message, delayed); } else { Log.d(Config.LOGTAG, "http upload failed because response code was " + code); diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java index 283aee7af..50204cb7b 100644 --- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java +++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java @@ -10,9 +10,8 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.AbstractStanza; +import rocks.xmpp.addr.Jid; public abstract class AbstractParser { @@ -38,7 +37,7 @@ public abstract class AbstractParser { for (Element child : element.getChildren()) { if ("delay".equals(child.getName()) && "urn:xmpp:delay".equals(child.getNamespace())) { final Jid f = to == null ? null : child.getAttributeAsJid("from"); - if (f != null && (to.toBareJid().equals(f) || to.getDomainpart().equals(f.toString()))) { + if (f != null && (to.asBareJid().equals(f) || to.getDomain().equals(f.toString()))) { continue; } final String stamp = child.getAttribute("stamp"); @@ -85,7 +84,7 @@ public abstract class AbstractParser { protected void updateLastseen(final Account account, final Jid from) { final Contact contact = account.getRoster().getContact(from); - contact.setLastResource(from.isBareJid() ? "" : from.getResourcepart()); + contact.setLastResource(from.isBareJid() ? "" : from.getResource()); } protected String avatarData(Element items) { @@ -101,15 +100,15 @@ public abstract class AbstractParser { } public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) { - final String local = conference.getJid().getLocalpart(); - final String domain = conference.getJid().getDomainpart(); + final String local = conference.getJid().getLocal(); + final String domain = conference.getJid().getDomain(); String affiliation = item.getAttribute("affiliation"); String role = item.getAttribute("role"); String nick = item.getAttribute("nick"); if (nick != null && fullJid == null) { try { - fullJid = Jid.fromParts(local, domain, nick); - } catch (InvalidJidException e) { + fullJid = Jid.of(local, domain, nick); + } catch (IllegalArgumentException e) { fullJid = null; } } diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java index 22dccdd2c..999137a02 100644 --- a/src/main/java/de/pixart/messenger/parser/IqParser.java +++ b/src/main/java/de/pixart/messenger/parser/IqParser.java @@ -31,8 +31,8 @@ import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnIqPacketReceived; import de.pixart.messenger.xmpp.OnUpdateBlocklist; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class IqParser extends AbstractParser implements OnIqPacketReceived { @@ -70,7 +70,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM); if ((both != bothPre) && both) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": gained mutual presence subscription with " + contact.getJid()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": gained mutual presence subscription with " + contact.getJid()); AxolotlService axolotlService = account.getAxolotlService(); if (axolotlService != null) { axolotlService.clearErrorsInFetchStatusMap(contact.getJid()); diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index e352d0771..77d7b71d6 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -40,9 +40,9 @@ import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnMessagePacketReceived; import de.pixart.messenger.xmpp.chatstate.ChatState; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; import de.pixart.messenger.xmpp.stanzas.MessagePacket; +import rocks.xmpp.addr.Jid; public class MessageParser extends AbstractParser implements OnMessagePacketReceived { @@ -57,7 +57,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (state != null && c != null) { final Account account = c.getAccount(); Jid from = packet.getFrom(); - if (from.toBareJid().equals(account.getJid().toBareJid())) { + if (from.asBareJid().equals(account.getJid().asBareJid())) { c.setOutgoingChatState(state); if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) { mXmppConnectionService.markRead(c); @@ -85,7 +85,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (from.isBareJid()) { presence = ""; } else { - presence = from.getResourcepart(); + presence = from.getResource(); } if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) { conversation.endOtrIfNeeded(); @@ -120,7 +120,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return null; } if (clientMightSendHtml(conversation.getAccount(), from)) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": received OTR message from bad behaving client. escaping HTML…"); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": received OTR message from bad behaving client. escaping HTML…"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { body = Html.fromHtml(body, Html.FROM_HTML_MODE_LEGACY).toString(); } else { @@ -141,7 +141,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } private static boolean clientMightSendHtml(Account account, Jid from) { - String resource = from.getResourcepart(); + String resource = from.getResource(); if (resource == null) { return false; } @@ -168,9 +168,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final AxolotlService service = conversation.getAccount().getAxolotlService(); final XmppAxolotlMessage xmppAxolotlMessage; try { - xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid()); + xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.asBareJid()); } catch (Exception e) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": invalid omemo message received " + e.getMessage()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": invalid omemo message received " + e.getMessage()); return null; } if (xmppAxolotlMessage.hasPayload()) { @@ -182,7 +182,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return finishedMessage; } } else { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": received OMEMO key transport message"); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": received OMEMO key transport message"); service.processReceivingKeyTransportMessage(xmppAxolotlMessage, postpone); } return null; @@ -238,11 +238,11 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final Jid by; final boolean safeToExtract; if (isTypeGroupChat) { - by = conversation.getJid().toBareJid(); + by = conversation.getJid().asBareJid(); safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS); } else { Account account = conversation.getAccount(); - by = account.getJid().toBareJid(); + by = account.getJid().asBareJid(); safeToExtract = account.getXmppConnection().getFeatures().stanzaIds(); } return safeToExtract ? extractStanzaId(packet, by) : null; @@ -265,9 +265,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if ("urn:xmpp:avatar:metadata".equals(node)) { Avatar avatar = Avatar.parseMetadata(items); if (avatar != null) { - avatar.owner = from.toBareJid(); + avatar.owner = from.asBareJid(); if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) { - if (account.getJid().toBareJid().equals(from)) { + if (account.getJid().asBareJid().equals(from)) { if (account.setAvatar(avatar.getFilename())) { mXmppConnectionService.databaseBackend.updateAccount(account); } @@ -311,7 +311,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece Jid from = packet.getFrom(); if (from != null) { Message message = mXmppConnectionService.markMessage(account, - from.toBareJid(), + from.asBareJid(), packet.getId(), Message.STATUS_SEND_FAILED, extractErrorMessage(packet)); @@ -355,7 +355,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece serverMsgId = result.getAttribute("id"); query.incrementMessageCount(); } else if (query != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": received mam result from invalid sender"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received mam result from invalid sender"); return; } else if (original.fromServer(account)) { Pair<MessagePacket, Long> f; @@ -404,7 +404,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT; if (query != null && !query.muc() && isTypeGroupChat) { - Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": received groupchat (" + from + ") message on regular MAM request. skipping"); + Log.e(Config.LOGTAG, account.getJid().asBareJid() + ": received groupchat (" + from + ") message on regular MAM request. skipping"); return; } boolean isProperlyAddressed = (to != null) && (!to.isBareJid() || account.countPresences() == 0); @@ -412,7 +412,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece boolean selfAddressed; if (packet.fromAccount(account)) { status = Message.STATUS_SEND; - selfAddressed = to == null || account.getJid().toBareJid().equals(to.toBareJid()); + selfAddressed = to == null || account.getJid().asBareJid().equals(to.asBareJid()); if (selfAddressed) { counterpart = from; } else { @@ -430,7 +430,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if ((body != null || pgpEncrypted != null || (axolotlEncrypted != null && axolotlEncrypted.hasChild("payload")) || oobUrl != null) && !isMucStatusMessage) { - final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query, false); + final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), isTypeGroupChat, false, query, false); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; if (serverMsgId == null) { serverMsgId = extractStanzaId(packet, isTypeGroupChat, conversation); @@ -469,7 +469,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return; } } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ignoring OTR message from " + from + " isForwarded=" + Boolean.toString(isForwarded) + ", isProperlyAddressed=" + Boolean.valueOf(isProperlyAddressed)); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring OTR message from " + from + " isForwarded=" + Boolean.toString(isForwarded) + ", isProperlyAddressed=" + Boolean.valueOf(isProperlyAddressed)); message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); } } else if (pgpEncrypted != null && Config.supportOpenPgp()) { @@ -488,7 +488,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } message = parseAxolotlChat(axolotlEncrypted, origin, conversation, status, query != null); if (message == null) { - if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet)) { + if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.asBareJid()), isTypeGroupChat, packet)) { mXmppConnectionService.updateConversationUi(); } if (query != null && status == Message.STATUS_SEND && remoteMsgId != null) { @@ -496,7 +496,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (previouslySent != null && previouslySent.getServerMsgId() == null && serverMsgId != null) { previouslySent.setServerMsgId(serverMsgId); mXmppConnectionService.databaseBackend.updateMessage(previouslySent); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": encountered previously sent OMEMO message without serverId. updating..."); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": encountered previously sent OMEMO message without serverId. updating..."); } } return; @@ -536,7 +536,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else { trueCounterpart = fallback; } - if (trueCounterpart != null && trueCounterpart.toBareJid().equals(account.getJid().toBareJid())) { + if (trueCounterpart != null && trueCounterpart.asBareJid().equals(account.getJid().asBareJid())) { status = isTypeGroupChat ? Message.STATUS_SEND_RECEIVED : Message.STATUS_SEND; } message.setStatus(status); @@ -574,7 +574,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (replacedMessage.getStatus() == Message.STATUS_RECEIVED) { replacedMessage.markUnread(); } - extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet); + extractChatState(mXmppConnectionService.find(account, counterpart.asBareJid()), isTypeGroupChat, packet); mXmppConnectionService.updateMessage(replacedMessage, uuid); mXmppConnectionService.getNotificationService().updateNotification(false); if (mXmppConnectionService.confirmMessages() @@ -592,14 +592,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } return; } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": received message correction but verification didn't check out"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received message correction but verification didn't check out"); } } } long deletionDate = mXmppConnectionService.getAutomaticMessageDeletionDate(); if (deletionDate != 0 && message.getTimeSent() < deletionDate) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping message from " + message.getCounterpart().toString() + " because it was sent prior to our deletion date"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": skipping message from " + message.getCounterpart().toString() + " because it was sent prior to our deletion date"); return; } @@ -651,7 +651,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if (query == null) { - extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet); + extractChatState(mXmppConnectionService.find(account, counterpart.asBareJid()), isTypeGroupChat, packet); mXmppConnectionService.updateConversationUi(); } @@ -667,7 +667,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (message.getStatus() == Message.STATUS_RECEIVED && conversation.getOtrSession() != null && !conversation.getOtrSession().getSessionID().getUserID() - .equals(message.getCounterpart().getResourcepart())) { + .equals(message.getCounterpart().getResource())) { conversation.endOtrIfNeeded(); } @@ -683,7 +683,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } } else if (!packet.hasChild("body")) { //no body - final Conversation conversation = mXmppConnectionService.find(account, from.toBareJid()); + final Conversation conversation = mXmppConnectionService.find(account, from.asBareJid()); if (axolotlEncrypted != null) { Jid origin; if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { @@ -699,15 +699,15 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece origin = from; } try { - final XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlEncrypted, origin.toBareJid()); + final XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlEncrypted, origin.asBareJid()); account.getAxolotlService().processReceivingKeyTransportMessage(xmppAxolotlMessage, query != null); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": omemo key transport message received from " + origin); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": omemo key transport message received from " + origin); } catch (Exception e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid omemo key transport message received " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": invalid omemo key transport message received " + e.getMessage()); return; } } - if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet)) { + if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.asBareJid()), isTypeGroupChat, packet)) { mXmppConnectionService.updateConversationUi(); } if (isTypeGroupChat) { @@ -743,7 +743,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } else if ("item".equals(child.getName())) { MucOptions.User user = AbstractParser.parseItem(conversation, child); - Log.d(Config.LOGTAG, account.getJid() + ": changing affiliation for " + user.getRealJid() + " to " + user.getAffiliation() + " in " + conversation.getJid().toBareJid()); + Log.d(Config.LOGTAG, account.getJid() + ": changing affiliation for " + user.getRealJid() + " to " + user.getAffiliation() + " in " + conversation.getJid().asBareJid()); if (!user.realJidMatchesAccount()) { boolean isNew = conversation.getMucOptions().updateUser(user); mXmppConnectionService.getAvatarService().clear(conversation); @@ -754,7 +754,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece Jid jid = user.getRealJid(); List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets(); if (cryptoTargets.remove(user.getRealJid())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName()); conversation.setAcceptedCryptoTargets(cryptoTargets); mXmppConnectionService.updateConversation(conversation); } @@ -783,7 +783,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece query.pendingReceiptRequests.remove(new ReceiptRequest(packet.getTo(), id)); } } else { - mXmppConnectionService.markMessage(account, from.toBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED); + mXmppConnectionService.markMessage(account, from.asBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED); } } Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0"); @@ -793,13 +793,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (packet.fromAccount(account) && !selfAddressed) { dismissNotification(account, counterpart, query); } else if (isTypeGroupChat) { - Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); + Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid()); if (conversation != null && id != null && sender != null) { Message message = conversation.findMessageWithRemoteId(id, sender); if (message != null) { final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); final Jid trueJid = getTrueCounterpart((query != null && query.safeToExtractTrueCounterpart()) ? mucUserElement : null, fallback); - final boolean trueJidMatchesAccount = account.getJid().toBareJid().equals(trueJid == null ? null : trueJid.toBareJid()); + final boolean trueJidMatchesAccount = account.getJid().asBareJid().equals(trueJid == null ? null : trueJid.asBareJid()); if (trueJidMatchesAccount || conversation.getMucOptions().isSelf(counterpart)) { if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections mXmppConnectionService.markRead(conversation); @@ -807,16 +807,16 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else if (!counterpart.isBareJid() && trueJid != null){ ReadByMarker readByMarker = ReadByMarker.from(counterpart, trueJid); if (message.addReadByMarker(readByMarker)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": added read by (" + readByMarker.getRealJid() + ") to message '" + message.getBody() + "'"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": added read by (" + readByMarker.getRealJid() + ") to message '" + message.getBody() + "'"); mXmppConnectionService.updateMessage(message); - mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED); + mXmppConnectionService.markMessage(account, from.asBareJid(), id, Message.STATUS_SEND_DISPLAYED); } } } } } else { - final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED); + final Message displayedMessage = mXmppConnectionService.markMessage(account, from.asBareJid(), id, Message.STATUS_SEND_DISPLAYED); Message message = displayedMessage == null ? null : displayedMessage.prev(); while (message != null && message.getStatus() == Message.STATUS_SEND_RECEIVED @@ -845,7 +845,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } private void dismissNotification(Account account, Jid counterpart, MessageArchiveService.Query query) { - Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); + Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid()); if (conversation != null && (query == null || query.isCatchup())) { mXmppConnectionService.markRead(conversation); //TODO only mark messages read that are older than timestamp } @@ -886,7 +886,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece private void activateGracePeriod(Account account) { long duration = mXmppConnectionService.getLongPreference("grace_period_length", R.integer.grace_period) * 1000; - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": activating grace period till " + TIME_FORMAT.format(new Date(System.currentTimeMillis() + duration))); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": activating grace period till " + TIME_FORMAT.format(new Date(System.currentTimeMillis() + duration))); account.activateGracePeriod(duration); } } diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java index abe5a2271..8ce9dfbf7 100644 --- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java +++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java @@ -20,9 +20,9 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnPresencePacketReceived; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; import de.pixart.messenger.xmpp.stanzas.PresencePacket; +import rocks.xmpp.addr.Jid; public class PresenceParser extends AbstractParser implements OnPresencePacketReceived { @@ -32,7 +32,7 @@ public class PresenceParser extends AbstractParser implements } public void parseConferencePresence(PresencePacket packet, Account account) { - final Conversation conversation = packet.getFrom() == null ? null : mXmppConnectionService.find(account, packet.getFrom().toBareJid()); + final Conversation conversation = packet.getFrom() == null ? null : mXmppConnectionService.find(account, packet.getFrom().asBareJid()); if (conversation != null) { final MucOptions mucOptions = conversation.getMucOptions(); boolean before = mucOptions.online(); @@ -85,9 +85,9 @@ public class PresenceParser extends AbstractParser implements axolotlService.fetchDeviceIds(user.getRealJid()); } if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) { - Log.d(Config.LOGTAG, mucOptions.getAccount().getJid().toBareJid() + Log.d(Config.LOGTAG, mucOptions.getAccount().getJid().asBareJid() + ": room '" - + mucOptions.getConversation().getJid().toBareJid() + + mucOptions.getConversation().getJid().asBareJid() + "' created. pushing default configuration"); mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(), IqGenerator.defaultRoomConfiguration(), @@ -213,15 +213,15 @@ public class PresenceParser extends AbstractParser implements final String type = packet.getAttribute("type"); final Contact contact = account.getRoster().getContact(from); if (type == null) { - final String resource = from.isBareJid() ? "" : from.getResourcepart(); + final String resource = from.isBareJid() ? "" : from.getResource(); if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) { mXmppConnectionService.getAvatarService().clear(contact); } Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) { - avatar.owner = from.toBareJid(); + avatar.owner = from.asBareJid(); if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) { - if (avatar.owner.equals(account.getJid().toBareJid())) { + if (avatar.owner.equals(account.getJid().asBareJid())) { account.setAvatar(avatar.getFilename()); mXmppConnectionService.databaseBackend.updateAccount(account); mXmppConnectionService.getAvatarService().clear(account); @@ -280,7 +280,7 @@ public class PresenceParser extends AbstractParser implements if (from.isBareJid()) { contact.clearPresences(); } else { - contact.removePresence(from.getResourcepart()); + contact.removePresence(from.getResource()); } mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false); } else if (type.equals("subscribe")) { @@ -290,7 +290,7 @@ public class PresenceParser extends AbstractParser implements } else { contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); final Conversation conversation = mXmppConnectionService.findOrCreateConversation( - account, contact.getJid().toBareJid(), false, false); + account, contact.getJid().asBareJid(), false, false); final String statusMessage = packet.findChildContent("status"); if (statusMessage != null && !statusMessage.isEmpty() diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 1a6129a49..4a25a3af5 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -50,9 +50,8 @@ import de.pixart.messenger.entities.ServiceDiscoveryResult; import de.pixart.messenger.services.ShortcutService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.Resolver; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.mam.MamReference; +import rocks.xmpp.addr.Jid; public class DatabaseBackend extends SQLiteOpenHelper { @@ -316,7 +315,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { continue; } int ownDeviceId = Integer.valueOf(ownDeviceIdString); - SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().toBareJid().toPreppedString(), ownDeviceId); + SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().asBareJid().toString(), ownDeviceId); deleteSession(db, account, ownAddress); IdentityKeyPair identityKeyPair = loadOwnIdentityKeyPair(db, account); if (identityKeyPair != null) { @@ -331,7 +330,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { + SQLiteAxolotlStore.FINGERPRINT + " = ? ", selectionArgs); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not load own identity key pair"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not load own identity key pair"); } } } @@ -507,10 +506,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { String newJid; try { - newJid = Jid.fromString( - cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID)) - ).toPreppedString(); - } catch (InvalidJidException ignored) { + newJid = Jid.of(cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID))).toString(); + } catch (IllegalArgumentException ignored) { Log.e(Config.LOGTAG, "Failed to migrate Conversation CONTACTJID " + cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID)) + ": " + ignored + ". Skipping..."); @@ -532,10 +529,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { String newJid; try { - newJid = Jid.fromString( - cursor.getString(cursor.getColumnIndex(Contact.JID)) - ).toPreppedString(); - } catch (InvalidJidException ignored) { + newJid = Jid.of(cursor.getString(cursor.getColumnIndex(Contact.JID))).toString(); + } catch (IllegalArgumentException ignored) { Log.e(Config.LOGTAG, "Failed to migrate Contact JID " + cursor.getString(cursor.getColumnIndex(Contact.JID)) + ": " + ignored + ". Skipping..."); @@ -559,12 +554,12 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { String newServer; try { - newServer = Jid.fromParts( + newServer = Jid.of( cursor.getString(cursor.getColumnIndex(Account.USERNAME)), cursor.getString(cursor.getColumnIndex(Account.SERVER)), - "mobile" - ).getDomainpart(); - } catch (InvalidJidException ignored) { + null + ).getDomain(); + } catch (IllegalArgumentException ignored) { Log.e(Config.LOGTAG, "Failed to migrate Account SERVER " + cursor.getString(cursor.getColumnIndex(Account.SERVER)) + ": " + ignored + ". Skipping..."); @@ -761,8 +756,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { public Conversation findConversation(final Account account, final Jid contactJid) { SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = {account.getUuid(), - contactJid.toBareJid().toPreppedString() + "/%", - contactJid.toBareJid().toPreppedString() + contactJid.asBareJid().toString() + "/%", + contactJid.asBareJid().toString() }; Cursor cursor = db.query(Conversation.TABLENAME, null, Conversation.ACCOUNT + "=? AND (" + Conversation.CONTACTJID @@ -796,7 +791,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { Cursor cursor = db.query(Account.TABLENAME, columns, null, null, null, null, null); try { while (cursor.moveToNext()) { - jids.add(Jid.fromParts(cursor.getString(0), cursor.getString(1), null)); + jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null)); } return jids; } catch (Exception e) { @@ -874,7 +869,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.insert(Contact.TABLENAME, null, contact.getContentValues()); } else { String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?"; - String[] whereArgs = {account.getUuid(), contact.getJid().toPreppedString()}; + String[] whereArgs = {account.getUuid(), contact.getJid().toString()}; db.delete(Contact.TABLENAME, where, whereArgs); } } @@ -1267,7 +1262,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { } private IdentityKeyPair loadOwnIdentityKeyPair(SQLiteDatabase db, Account account) { - String name = account.getJid().toBareJid().toPreppedString(); + String name = account.getJid().asBareJid().toString(); IdentityKeyPair identityKeyPair = null; Cursor cursor = getIdentityKeyCursor(db, account, name, true); if (cursor.getCount() != 0) { @@ -1275,7 +1270,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { try { identityKeyPair = new IdentityKeyPair(Base64.decode(cursor.getString(cursor.getColumnIndex(SQLiteAxolotlStore.KEY)), Base64.DEFAULT)); } catch (InvalidKeyException e) { - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().toBareJid() + ", address: " + name); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().asBareJid() + ", address: " + name); } } cursor.close(); @@ -1300,10 +1295,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (key != null) { identityKeys.add(new IdentityKey(Base64.decode(key, Base64.DEFAULT), 0)); } else { - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Missing key (possibly preverified) in database for account" + account.getJid().toBareJid() + ", address: " + name); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Missing key (possibly preverified) in database for account" + account.getJid().asBareJid() + ", address: " + name); } } catch (InvalidKeyException e) { - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().toBareJid() + ", address: " + name); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().asBareJid() + ", address: " + name); } } cursor.close(); @@ -1439,7 +1434,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public void storeOwnIdentityKeyPair(Account account, IdentityKeyPair identityKeyPair) { - storeIdentityKey(account, account.getJid().toBareJid().toPreppedString(), true, CryptoHelper.bytesToHex(identityKeyPair.getPublicKey().serialize()), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), FingerprintStatus.createActiveVerified(false)); + storeIdentityKey(account, account.getJid().asBareJid().toString(), true, CryptoHelper.bytesToHex(identityKeyPair.getPublicKey().serialize()), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), FingerprintStatus.createActiveVerified(false)); } public void recreateAxolotlDb(SQLiteDatabase db) { @@ -1483,7 +1478,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { ArrayList<ShortcutService.FrequentContact> contacts = new ArrayList<>(); while (cursor.moveToNext()) { try { - contacts.add(new ShortcutService.FrequentContact(cursor.getString(0), Jid.fromString(cursor.getString(1)))); + contacts.add(new ShortcutService.FrequentContact(cursor.getString(0), Jid.of(cursor.getString(1)))); } catch (Exception e) { Log.d(Config.LOGTAG, e.getMessage()); } diff --git a/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java b/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java index ff10acf0c..58cb5eaa4 100644 --- a/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java +++ b/src/main/java/de/pixart/messenger/services/AbstractEmojiService.java @@ -5,7 +5,6 @@ import android.support.text.emoji.EmojiCompat; import android.util.Log; import de.pixart.messenger.Config; -import de.pixart.messenger.utils.Emoticons; public abstract class AbstractEmojiService { diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index dac42c63d..4e3ed756b 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -30,7 +30,7 @@ import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.OnAdvancedStreamFeaturesLoaded; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class AvatarService implements OnAdvancedStreamFeaturesLoaded { @@ -72,7 +72,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } } if (avatar == null) { - avatar = get(contact.getDisplayName(), contact.getJid().toBareJid().toString(), size, cachedOnly); + avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, cachedOnly); } this.mXmppConnectionService.getBitmapCache().put(KEY, avatar); return avatar; @@ -119,7 +119,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { if (contact != null) { avatar = get(contact, size, cachedOnly); } else { - String seed = user.getRealJid() != null ? user.getRealJid().toBareJid().toString() : null; + String seed = user.getRealJid() != null ? user.getRealJid().asBareJid().toString() : null; avatar = get(user.getName(), seed, size, cachedOnly); } } @@ -145,7 +145,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { this.sizes.add(size); } } - return PREFIX_CONTACT + "_" + contact.getAccount().getJid().toBareJid() + "_" + return PREFIX_CONTACT + "_" + contact.getAccount().getJid().asBareJid() + "_" + contact.getJid() + "_" + String.valueOf(size); } @@ -155,7 +155,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { this.sizes.add(size); } } - return PREFIX_CONTACT + "_" + user.getAccount().getJid().toBareJid() + "_" + return PREFIX_CONTACT + "_" + user.getAccount().getJid().asBareJid() + "_" + user.getFullJid() + "_" + String.valueOf(size); } @@ -171,11 +171,11 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { if (bookmark.getConversation() != null) { return get(bookmark.getConversation(), size, cachedOnly); } else { - String seed = bookmark.getJid() != null ? bookmark.getJid().toBareJid().toString() : null; + String seed = bookmark.getJid() != null ? bookmark.getJid().asBareJid().toString() : null; return get(bookmark.getDisplayName(), seed, size, cachedOnly); } } else { - String seed = item.getJid() != null ? item.getJid().toBareJid().toString() : null; + String seed = item.getJid() != null ? item.getJid().asBareJid().toString() : null; return get(item.getDisplayName(), seed, size, cachedOnly); } } @@ -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().toBareJid().toString(), size); + bitmap = getImpl(c.getName(), c.getJid().asBareJid().toString(), size); } else { bitmap = getImpl(users, size); } @@ -298,9 +298,9 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { for (MucOptions.User user : users) { builder.append("\0"); - builder.append(user.getRealJid() == null ? "" : user.getRealJid().toBareJid().toPreppedString()); + builder.append(user.getRealJid() == null ? "" : user.getRealJid().asBareJid().toString()); builder.append("\0"); - builder.append(user.getFullJid() == null ? "" : user.getFullJid().toPreppedString()); + builder.append(user.getFullJid() == null ? "" : user.getFullJid().toString()); } final String key = builder.toString(); synchronized (this.conversationDependentKeys) { @@ -328,7 +328,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size); if (avatar == null) { - avatar = get(account.getJid().toBareJid().toString(), null, size, false); + avatar = get(account.getJid().asBareJid().toString(), null, size, false); } mXmppConnectionService.getBitmapCache().put(KEY, avatar); return avatar; @@ -357,7 +357,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { return get(c, size, cachedOnly); } Jid tcp = message.getTrueCounterpart(); - String seed = tcp != null ? tcp.toBareJid().toString() : null; + String seed = tcp != null ? tcp.asBareJid().toString() : null; return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly); } else { return get(conversation.getAccount(), size, cachedOnly); @@ -472,10 +472,10 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } } if (contact != null) { - String seed = contact.getJid().toBareJid().toString(); + String seed = contact.getJid().asBareJid().toString(); drawTile(canvas, contact.getDisplayName(), seed, left, top, right, bottom); } else { - String seed = user.getRealJid() == null ? null : user.getRealJid().toBareJid().toString(); + String seed = user.getRealJid() == null ? null : user.getRealJid().asBareJid().toString(); drawTile(canvas, user.getName(), seed, left, top, right, bottom); } return true; @@ -491,7 +491,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } } } - String name = account.getJid().toBareJid().toString(); + String name = account.getJid().asBareJid().toString(); return drawTile(canvas, name, name, left, top, right, bottom); } @@ -536,7 +536,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { public void onAdvancedStreamFeaturesAvailable(Account account) { XmppConnection.Features features = account.getXmppConnection().getFeatures(); if (features.pep() && !features.pepPersistent()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has pep but is not persistent"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has pep but is not persistent"); if (account.getAvatar() != null) { mXmppConnectionService.republishAvatarIfNeeded(account); } diff --git a/src/main/java/de/pixart/messenger/services/BarcodeProvider.java b/src/main/java/de/pixart/messenger/services/BarcodeProvider.java index f32082e1a..cf8ed5457 100644 --- a/src/main/java/de/pixart/messenger/services/BarcodeProvider.java +++ b/src/main/java/de/pixart/messenger/services/BarcodeProvider.java @@ -31,7 +31,7 @@ import java.util.Hashtable; import de.pixart.messenger.Config; import de.pixart.messenger.entities.Account; import de.pixart.messenger.utils.CryptoHelper; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class BarcodeProvider extends ContentProvider implements ServiceConnection { @@ -98,7 +98,7 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio if (connectAndWait()) { Log.d(Config.LOGTAG, "connected to background service"); try { - Account account = mXmppConnectionService.findAccountByJid(Jid.fromString(jid)); + Account account = mXmppConnectionService.findAccountByJid(Jid.of(jid)); if (account != null) { String shareableUri = account.getShareableUri(); String hash = CryptoHelper.getFingerprint(shareableUri); @@ -166,7 +166,7 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio public static Uri getUriForAccount(Context context, Account account) { final String packageId = context.getPackageName(); - return Uri.parse("content://" + packageId + AUTHORITY + "/" + account.getJid().toBareJid() + ".png"); + return Uri.parse("content://" + packageId + AUTHORITY + "/" + account.getJid().asBareJid() + ".png"); } public static Bitmap create2dBarcodeBitmap(String input, int size) { diff --git a/src/main/java/de/pixart/messenger/services/ExportLogsService.java b/src/main/java/de/pixart/messenger/services/ExportLogsService.java index 5411d4e0f..12a211e54 100644 --- a/src/main/java/de/pixart/messenger/services/ExportLogsService.java +++ b/src/main/java/de/pixart/messenger/services/ExportLogsService.java @@ -36,7 +36,7 @@ import de.pixart.messenger.entities.Message; import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.utils.EncryptDecryptFile; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.SettingsActivity.USE_MULTI_ACCOUNTS; @@ -117,7 +117,7 @@ public class ExportLogsService extends Service { Jid accountJid = resolveAccountUuid(conversation.getAccountUuid()); Jid contactJid = conversation.getJid(); - File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.toBareJid().toString())); + File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.asBareJid().toString())); dir.mkdirs(); BufferedWriter bw = null; @@ -129,7 +129,7 @@ public class ExportLogsService extends Service { String date = simpleDateFormat.format(new Date(message.getTimeSent())); if (bw == null) { bw = new BufferedWriter(new FileWriter( - new File(dir, contactJid.toBareJid().toString() + ".txt"))); + new File(dir, contactJid.asBareJid().toString() + ".txt"))); } String jid = null; switch (message.getStatus()) { @@ -139,7 +139,7 @@ public class ExportLogsService extends Service { case Message.STATUS_SEND: case Message.STATUS_SEND_RECEIVED: case Message.STATUS_SEND_DISPLAYED: - jid = accountJid.toBareJid().toString(); + jid = accountJid.asBareJid().toString(); break; } if (jid != null) { diff --git a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java index 05e1f2918..7158c3b1f 100644 --- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java +++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java @@ -17,9 +17,9 @@ import de.pixart.messenger.generator.AbstractGenerator; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnAdvancedStreamFeaturesLoaded; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.mam.MamReference; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { @@ -164,7 +164,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { private void execute(final Query query) { final Account account = query.getAccount(); if (account.getStatus() == Account.State.ONLINE) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": running mam query " + query.toString()); IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query); this.mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> { Element fin = p.findChild("fin", Namespace.MAM); @@ -180,7 +180,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } else if (p.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) { //do nothing } else { - Log.d(Config.LOGTAG, a.getJid().toBareJid().toString() + ": error executing mam: " + p.toString()); + Log.d(Config.LOGTAG, a.getJid().asBareJid().toString() + ": error executing mam: " + p.toString()); finalizeQuery(query, true); } }); @@ -277,7 +277,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } done = done || (query.getActualMessageCount() == 0 && !query.isCatchup()); this.finalizeQuery(query, done); - Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done) + " count=" + count); + Log.d(Config.LOGTAG, query.getAccount().getJid().asBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done) + " count=" + count); if (query.isCatchup() && query.getActualMessageCount() > 0) { mXmppConnectionService.getNotificationService().finishBacklog(true,query.getAccount()); } @@ -312,7 +312,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } private void kill(Query query) { - Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": killing mam query prematurely"); + Log.d(Config.LOGTAG, query.getAccount().getJid().asBareJid() + ": killing mam query prematurely"); query.callback = null; this.finalizeQuery(query, false); if (query.isCatchup() && query.getActualMessageCount() > 0) { @@ -323,7 +323,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { private void processPostponed(Query query) { query.account.getAxolotlService().processPostponed(); - Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": found " + query.pendingReceiptRequests.size() + " pending receipt requests"); + Log.d(Config.LOGTAG, query.getAccount().getJid().asBareJid() + ": found " + query.pendingReceiptRequests.size() + " pending receipt requests"); Iterator<ReceiptRequest> iterator = query.pendingReceiptRequests.iterator(); while (iterator.hasNext()) { ReceiptRequest rr = iterator.next(); @@ -440,7 +440,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } public Jid getWith() { - return conversation == null ? null : conversation.getJid().toBareJid(); + return conversation == null ? null : conversation.getJid().asBareJid(); } public boolean muc() { @@ -505,7 +505,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { if (muc()) { return getWith().equals(from); } else { - return (from == null) || account.getJid().toBareJid().equals(from.toBareJid()); + return (from == null) || account.getJid().asBareJid().equals(from.asBareJid()); } } diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 27ff6d538..4354f77b0 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -163,7 +163,7 @@ public class NotificationService { } } } - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": backlog message count="+count); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": backlog message count="+count); return count; } @@ -197,12 +197,12 @@ public class NotificationService { private void pushNow(final Message message) { mXmppConnectionService.updateUnreadCountBadge(); if (!notify(message)) { - Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().toBareJid() + ": suppressing notification because turned off"); + Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing notification because turned off"); return; } final boolean isScreenOn = mXmppConnectionService.isInteractive(); if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { - Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().toBareJid() + ": suppressing notification because conversation is open"); + Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing notification because conversation is open"); mXmppConnectionService.vibrate(); return; } @@ -811,7 +811,7 @@ public class NotificationService { return; } else if (errors.size() == 1) { mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account)); - mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString()); + mBuilder.setContentText(errors.get(0).getJid().asBareJid().toString()); } else { mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts)); mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix)); @@ -827,7 +827,7 @@ public class NotificationService { if (errors.size() == 1) { Intent intent = new Intent(mXmppConnectionService, EditAccountActivity.class); Account mAccount = mXmppConnectionService.getAccounts().get(0); - intent.putExtra("jid", mAccount.getJid().toBareJid().toString()); + intent.putExtra("jid", mAccount.getJid().asBareJid().toString()); intent.putExtra("init", false); mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService, 145, diff --git a/src/main/java/de/pixart/messenger/services/ShortcutService.java b/src/main/java/de/pixart/messenger/services/ShortcutService.java index 56345c663..c5d73d5b1 100644 --- a/src/main/java/de/pixart/messenger/services/ShortcutService.java +++ b/src/main/java/de/pixart/messenger/services/ShortcutService.java @@ -18,7 +18,7 @@ import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.ui.StartConversationActivity; import de.pixart.messenger.utils.ReplacingSerialSingleThreadExecutor; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ShortcutService { private final XmppConnectionService xmppConnectionService; @@ -108,14 +108,14 @@ public class ShortcutService { } private static String getShortcutId(Contact contact) { - return contact.getAccount().getJid().toBareJid().toPreppedString() + "#" + contact.getJid().toBareJid().toPreppedString(); + return contact.getAccount().getJid().asBareJid().toString() + "#" + contact.getJid().asBareJid().toString(); } private Intent getShortcutIntent(Contact contact) { Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class); intent.setAction(Intent.ACTION_VIEW); - intent.setData(Uri.parse("xmpp:" + contact.getJid().toBareJid().toString())); - intent.putExtra("account", contact.getAccount().getJid().toBareJid().toString()); + intent.setData(Uri.parse("xmpp:" + contact.getJid().asBareJid().toString())); + intent.putExtra("account", contact.getAccount().getJid().asBareJid().toString()); return intent; } diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 85ad64206..730215cdd 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -134,8 +134,7 @@ import de.pixart.messenger.xmpp.Patches; import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.forms.Data; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import de.pixart.messenger.xmpp.jid.OtrJidHelper; import de.pixart.messenger.xmpp.jingle.JingleConnectionManager; import de.pixart.messenger.xmpp.jingle.OnJinglePacketReceived; import de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket; @@ -145,6 +144,7 @@ import de.pixart.messenger.xmpp.stanzas.IqPacket; import de.pixart.messenger.xmpp.stanzas.MessagePacket; import de.pixart.messenger.xmpp.stanzas.PresencePacket; import me.leolin.shortcutbadger.ShortcutBadger; +import rocks.xmpp.addr.Jid; public class XmppConnectionService extends Service { @@ -205,7 +205,7 @@ public class XmppConnectionService extends Service { Element error = packet.findChild("error"); String text = error != null ? error.findChildContent("text") : null; if (text != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": received iq error - " + text); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received iq error - " + text); } } } @@ -296,7 +296,7 @@ public class XmppConnectionService extends Service { synchronized (mInProgressAvatarFetches) { for (Iterator<String> iterator = mInProgressAvatarFetches.iterator(); iterator.hasNext(); ) { final String KEY = iterator.next(); - if (KEY.startsWith(account.getJid().toBareJid() + "_")) { + if (KEY.startsWith(account.getJid().asBareJid() + "_")) { iterator.remove(); } } @@ -313,7 +313,7 @@ public class XmppConnectionService extends Service { if (flexible && catchup) { sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, acc.getJid().toBareJid() + ": successfully purged offline messages"); + Log.d(Config.LOGTAG, acc.getJid().asBareJid() + ": successfully purged offline messages"); } }); } @@ -339,8 +339,8 @@ public class XmppConnectionService extends Service { } if (account.getStatus() == Account.State.ONLINE) { synchronized (mLowPingTimeoutMode) { - if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": leaving low ping timeout mode"); + if (mLowPingTimeoutMode.remove(account.getJid().asBareJid())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": leaving low ping timeout mode"); } } if (account.setShowErrorNotification(true)) { @@ -349,10 +349,10 @@ public class XmppConnectionService extends Service { mMessageArchiveService.executePendingQueries(account); if (connection != null && connection.getFeatures().csi()) { if (checkListeners()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " sending csi//inactive"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " sending csi//inactive"); connection.sendInactive(); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " sending csi//active"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " sending csi//active"); connection.sendActive(); } } @@ -361,7 +361,7 @@ public class XmppConnectionService extends Service { if (conversation.getAccount() == account && !account.pendingConferenceJoins.contains(conversation)) { if (!conversation.startOtrIfNeeded()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); } checkDeletedFiles(conversation); sendUnsentMessages(conversation); @@ -380,7 +380,7 @@ public class XmppConnectionService extends Service { } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) { resetSendingToWaiting(account); if (account.isEnabled() && isInLowPingTimeoutMode(account)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": went into offline state during low ping mode. reconnecting now"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": went into offline state during low ping mode. reconnecting now"); reconnectAccount(account, true, false); } else { int timeToReconnect = mRandom.nextInt(10) + 2; @@ -395,11 +395,11 @@ public class XmppConnectionService extends Service { final int next = connection.getTimeToNextAttempt(); final boolean lowPingTimeoutMode = isInLowPingTimeoutMode(account); if (next <= 0) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error connecting account. reconnecting now. lowPingTimeout=" + Boolean.toString(lowPingTimeoutMode)); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. reconnecting now. lowPingTimeout=" + Boolean.toString(lowPingTimeoutMode)); reconnectAccount(account, true, false); } else { final int attempt = connection.getAttempt() + 1; - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + Boolean.toString(lowPingTimeoutMode)); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error connecting account. try again in " + next + "s for the " + attempt + " time. lowPingTimeout=" + Boolean.toString(lowPingTimeoutMode)); scheduleWakeUpCall(next, account.getUuid().hashCode()); } } @@ -410,7 +410,7 @@ public class XmppConnectionService extends Service { private boolean isInLowPingTimeoutMode(Account account) { synchronized (mLowPingTimeoutMode) { - return mLowPingTimeoutMode.contains(account.getJid().toBareJid()); + return mLowPingTimeoutMode.contains(account.getJid().asBareJid()); } } @@ -433,7 +433,7 @@ public class XmppConnectionService extends Service { public final CountDownLatch restoredFromDatabaseLatch = new CountDownLatch(1); private static String generateFetchKey(Account account, final Avatar avatar) { - return account.getJid().toBareJid() + "_" + avatar.owner + "_" + avatar.sha1sum; + return account.getJid().asBareJid() + "_" + avatar.owner + "_" + avatar.sha1sum; } public boolean areMessagesInitialized() { @@ -525,7 +525,7 @@ public class XmppConnectionService extends Service { if ("never".equals(compressPictures) || ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri)) || (mimeType != null && mimeType.endsWith("/gif"))) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": not compressing picture. sending as file"); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": not compressing picture. sending as file"); attachFileToConversation(conversation, uri, mimeType, callback); return; } @@ -715,7 +715,7 @@ public class XmppConnectionService extends Service { } final boolean lowTimeout = isInLowPingTimeoutMode(account); account.getXmppConnection().sendPing(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ", lowTimeout=" + Boolean.toString(lowTimeout) + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " send ping (action=" + action + ", lowTimeout=" + Boolean.toString(lowTimeout) + ")"); scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode()); } } @@ -753,11 +753,11 @@ public class XmppConnectionService extends Service { long lastSent = account.getXmppConnection().getLastPingSent(); long pingInterval = isUiAction ? Config.PING_MIN_INTERVAL * 1000 : Config.PING_MAX_INTERVAL * 1000; long msToNextPing = (Math.max(lastReceived, lastSent) + pingInterval) - SystemClock.elapsedRealtime(); - int pingTimeout = mLowPingTimeoutMode.contains(account.getJid().toBareJid()) ? Config.LOW_PING_TIMEOUT * 1000 : Config.PING_TIMEOUT * 1000; + int pingTimeout = mLowPingTimeoutMode.contains(account.getJid().asBareJid()) ? Config.LOW_PING_TIMEOUT * 1000 : Config.PING_TIMEOUT * 1000; long pingTimeoutIn = (lastSent + pingTimeout) - SystemClock.elapsedRealtime(); if (lastSent > lastReceived) { if (pingTimeoutIn < 0) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ping timeout"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ping timeout"); this.reconnectAccount(account, true, interactive); } else { int secs = (int) (pingTimeoutIn / 1000); @@ -767,15 +767,15 @@ public class XmppConnectionService extends Service { pingCandidates.add(account); if (isAccountPushed) { pingNow = true; - if (mLowPingTimeoutMode.add(account.getJid().toBareJid())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": entering low ping timeout mode"); + if (mLowPingTimeoutMode.add(account.getJid().asBareJid())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": entering low ping timeout mode"); } } else if (msToNextPing <= 0) { pingNow = true; } else { this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode()); - if (mLowPingTimeoutMode.remove(account.getJid().toBareJid())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": leaving low ping timeout mode"); + if (mLowPingTimeoutMode.remove(account.getJid().asBareJid())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": leaving low ping timeout mode"); } } @@ -983,7 +983,7 @@ public class XmppConnectionService extends Service { private void dismissErrorNotifications() { for (final Account account : this.accounts) { if (account.hasErrorStatus()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": dismissing error notification"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": dismissing error notification"); if (account.setShowErrorNotification(false)) { databaseBackend.updateAccount(account); } @@ -1359,8 +1359,8 @@ public class XmppConnectionService extends Service { SessionImpl otrSession = conversation.getOtrSession(); if (otrSession != null && otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { try { - message.setCounterpart(Jid.fromSessionID(otrSession.getSessionID())); - } catch (InvalidJidException e) { + message.setCounterpart(OtrJidHelper.fromSessionID(otrSession.getSessionID())); + } catch (IllegalArgumentException e) { break; } if (message.needsUploading()) { @@ -1370,13 +1370,13 @@ public class XmppConnectionService extends Service { } } else if (otrSession == null) { if (message.fixCounterpart()) { - conversation.startOtrSession(message.getCounterpart().getResourcepart(), true); + conversation.startOtrSession(message.getCounterpart().getResource(), true); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fix counterpart for OTR message to contact " + message.getCounterpart()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not fix counterpart for OTR message to contact " + message.getCounterpart()); break; } } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " OTR session with " + message.getContact() + " is in wrong state: " + otrSession.getSessionStatus().toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " OTR session with " + message.getContact() + " is in wrong state: " + otrSession.getSessionStatus().toString()); } break; case Message.ENCRYPTION_AXOLOTL: @@ -1431,8 +1431,8 @@ public class XmppConnectionService extends Service { break; case Message.ENCRYPTION_OTR: if (!conversation.hasValidOtrSession() && message.getCounterpart() != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": create otr session without starting for " + message.getContact().getJid()); - conversation.startOtrSession(message.getCounterpart().getResourcepart(), false); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": create otr session without starting for " + message.getContact().getJid()); + conversation.startOtrSession(message.getCounterpart().getResource(), false); } break; case Message.ENCRYPTION_AXOLOTL: @@ -1508,10 +1508,10 @@ public class XmppConnectionService extends Service { public void fetchRosterFromServer(final Account account) { final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET); if (!"".equals(account.getRosterVersion())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching roster version " + account.getRosterVersion()); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching roster"); } iqPacket.query(Namespace.ROSTER).setAttribute("ver", account.getRosterVersion()); sendIqPacket(account, iqPacket, mIqParser); @@ -1550,7 +1550,7 @@ public class XmppConnectionService extends Service { } account.setBookmarks(new CopyOnWriteArrayList<>(bookmarks.values())); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not fetch bookmarks"); } } }; @@ -1558,7 +1558,7 @@ public class XmppConnectionService extends Service { } public void pushBookmarks(Account account) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": pushing bookmarks"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": pushing bookmarks"); IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET); Element query = iqPacket.query("jabber:iq:private"); Element storage = query.addChild("storage", "storage:bookmarks"); @@ -1648,8 +1648,8 @@ public class XmppConnectionService extends Service { for (Bundle phoneContact : phoneContacts) { Jid jid; try { - jid = Jid.fromString(phoneContact.getString("jid")); - } catch (final InvalidJidException e) { + jid = Jid.of(phoneContact.getString("jid")); + } catch (final IllegalArgumentException e) { continue; } final Contact contact = account.getRoster().getContact(jid); @@ -1817,7 +1817,7 @@ public class XmppConnectionService extends Service { } for (final Conversation conversation : haystack) { if ((account == null || conversation.getAccount() == account) - && (conversation.getJid().toBareJid().equals(jid.toBareJid()))) { + && (conversation.getJid().asBareJid().equals(jid.asBareJid()))) { return conversation; } } @@ -1861,7 +1861,7 @@ public class XmppConnectionService extends Service { conversation.setContactJid(jid); } else { conversation.setMode(Conversation.MODE_SINGLE); - conversation.setContactJid(jid.toBareJid()); + conversation.setContactJid(jid.asBareJid()); } databaseBackend.updateConversation(conversation); loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true,false); @@ -1871,13 +1871,13 @@ public class XmppConnectionService extends Service { if (contact != null) { conversationName = contact.getDisplayName(); } else { - conversationName = jid.getLocalpart(); + conversationName = jid.getLocal(); } if (muc) { conversation = new Conversation(conversationName, account, jid, Conversation.MODE_MULTI); } else { - conversation = new Conversation(conversationName, account, jid.toBareJid(), + conversation = new Conversation(conversationName, account, jid.asBareJid(), Conversation.MODE_SINGLE); } this.databaseBackend.createConversation(conversation); @@ -1935,7 +1935,7 @@ public class XmppConnectionService extends Service { conversation.setContactJid(jid); } else { conversation.setMode(Conversation.MODE_SINGLE); - conversation.setContactJid(jid.toBareJid()); + conversation.setContactJid(jid.asBareJid()); } databaseBackend.updateConversation(conversation); loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true,false); @@ -1945,13 +1945,13 @@ public class XmppConnectionService extends Service { if (contact != null) { conversationName = contact.getDisplayName(); } else { - conversationName = jid.getLocalpart(); + conversationName = jid.getLocal(); } if (muc) { conversation = new Conversation(conversationName, account, jid, Conversation.MODE_MULTI); } else { - conversation = new Conversation(conversationName, account, jid.toBareJid(), + conversation = new Conversation(conversationName, account, jid.asBareJid(), Conversation.MODE_SINGLE); } this.databaseBackend.createConversation(conversation); @@ -2041,7 +2041,7 @@ public class XmppConnectionService extends Service { callback.onAccountCreated(account); if (Config.X509_VERIFICATION) { try { - getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA"); + getMemorizingTrustManager().getNonInteractive(account.getJid().getDomain()).checkClientTrusted(chain, "RSA"); } catch (CertificateException e) { callback.informUser(R.string.certificate_chain_is_not_trusted); } @@ -2057,16 +2057,16 @@ public class XmppConnectionService extends Service { } public void updateKeyInAccount(final Account account, final String alias) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": update key in account " + alias); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": update key in account " + alias); try { X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " loaded certificate chain"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " loaded certificate chain"); Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); if (info == null) { showErrorToastInUi(R.string.certificate_does_not_contain_jid); return; } - if (account.getJid().toBareJid().equals(info.first)) { + if (account.getJid().asBareJid().equals(info.first)) { account.setPrivateKeyAlias(alias); account.setDisplayName(info.second); databaseBackend.updateAccount(account); @@ -2133,7 +2133,7 @@ public class XmppConnectionService extends Service { } final Runnable runnable = () -> { if (!databaseBackend.deleteAccount(account)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": unable to delete account"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to delete account"); } }; mDatabaseWriterExecutor.execute(runnable); @@ -2444,7 +2444,7 @@ public class XmppConnectionService extends Service { Account account = conversation.getAccount(); final MucOptions mucOptions = conversation.getMucOptions(); final Jid joinJid = mucOptions.getSelf().getFullJid(); - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": joining conversation " + joinJid.toString()); PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous() || onConferenceJoined != null); packet.setTo(joinJid); Element x = packet.addChild("x", "http://jabber.org/protocol/muc"); @@ -2536,7 +2536,7 @@ public class XmppConnectionService extends Service { } } else { success = false; - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().asBareJid()); } ++i; if (i >= affiliations.length) { @@ -2548,7 +2548,7 @@ public class XmppConnectionService extends Service { Jid jid = iterator.next(); if (!members.contains(jid)) { iterator.remove(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName()); changed = true; } } @@ -2557,7 +2557,7 @@ public class XmppConnectionService extends Service { updateConversation(conversation); } } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": retrieved members for " + conversation.getJid().asBareJid() + ": " + conversation.getMucOptions().getMembers()); getAvatarService().clear(conversation); updateMucRosterUi(); updateConversationUi(); @@ -2567,7 +2567,7 @@ public class XmppConnectionService extends Service { for (String affiliation : affiliations) { sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback); } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching members for " + conversation.getName()); } public void providePasswordForMuc(Conversation conversation, String password) { @@ -2603,8 +2603,8 @@ public class XmppConnectionService extends Service { } Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && !full.getResourcepart().equals(bookmark.getNick())) { - bookmark.setNick(full.getResourcepart()); + if (bookmark != null && !full.getResource().equals(bookmark.getNick())) { + bookmark.setNick(full.getResource()); pushBookmarks(bookmark.getAccount()); } } @@ -2670,7 +2670,7 @@ public class XmppConnectionService extends Service { if (bookmark != null) { bookmark.setConversation(null); } - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": leaving muc " + conversation.getJid()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": leaving muc " + conversation.getJid()); } else { account.pendingConferenceLeaves.add(conversation); } @@ -2699,7 +2699,7 @@ public class XmppConnectionService extends Service { final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": creating adhoc conference with " + jids.toString()); if (account.getStatus() == Account.State.ONLINE) { try { String server = findConferenceServer(account); @@ -2709,7 +2709,7 @@ public class XmppConnectionService extends Service { } return false; } - final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null); + final Jid jid = Jid.of(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null); final Conversation conversation = findOrCreateConversation(account, jid, true, false, true); joinMuc(conversation, new OnConferenceJoined() { @Override @@ -2724,7 +2724,7 @@ public class XmppConnectionService extends Service { invite(conversation, invite); } if (account.countPresences() > 1) { - directInvite(conversation, account.getJid().toBareJid()); + directInvite(conversation, account.getJid().asBareJid()); } saveConversationAsBookmark(conversation, subject); if (callback != null) { @@ -2743,7 +2743,7 @@ public class XmppConnectionService extends Service { } }); return true; - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { if (callback != null) { callback.error(R.string.conference_creation_failed, null); } @@ -2763,7 +2763,7 @@ public class XmppConnectionService extends Service { public void fetchConferenceConfiguration(final Conversation conversation, final OnConferenceConfigurationFetched callback) { IqPacket request = new IqPacket(IqPacket.TYPE.GET); - request.setTo(conversation.getJid().toBareJid()); + request.setTo(conversation.getJid().asBareJid()); request.query("http://jabber.org/protocol/disco#info"); sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() { @Override @@ -2787,7 +2787,7 @@ public class XmppConnectionService extends Service { if (callback != null) { callback.onConferenceConfigurationFetched(conversation); } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetched muc configuration for " + conversation.getJid().toBareJid() + " - " + features.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetched muc configuration for " + conversation.getJid().asBareJid() + " - " + features.toString()); updateConversationUi(); } else if (packet.getType() == IqPacket.TYPE.ERROR) { if (callback != null) { @@ -2799,7 +2799,7 @@ public class XmppConnectionService extends Service { } public void pushNodeConfiguration(Account account, final String node, final Bundle options, final OnConfigurationPushed callback) { - pushNodeConfiguration(account, account.getJid().toBareJid(), node, options, callback); + pushNodeConfiguration(account, account.getJid().asBareJid(), node, options, callback); } public void pushNodeConfiguration(Account account, final Jid jid, final String node, final Bundle options, final OnConfigurationPushed callback) { @@ -2835,7 +2835,7 @@ public class XmppConnectionService extends Service { public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConfigurationPushed callback) { IqPacket request = new IqPacket(IqPacket.TYPE.GET); - request.setTo(conversation.getJid().toBareJid()); + request.setTo(conversation.getJid().asBareJid()); request.query("http://jabber.org/protocol/muc#owner"); sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() { @Override @@ -2844,7 +2844,7 @@ public class XmppConnectionService extends Service { Data data = Data.parse(packet.query().findChild("x", Namespace.DATA)); data.submit(options); IqPacket set = new IqPacket(IqPacket.TYPE.SET); - set.setTo(conversation.getJid().toBareJid()); + set.setTo(conversation.getJid().asBareJid()); set.query("http://jabber.org/protocol/muc#owner").addChild(data); sendIqPacket(account, set, new OnIqPacketReceived() { @Override @@ -2881,7 +2881,7 @@ public class XmppConnectionService extends Service { } public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) { - final Jid jid = user.toBareJid(); + final Jid jid = user.asBareJid(); IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString()); sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() { @Override @@ -2963,7 +2963,7 @@ public class XmppConnectionService extends Service { leaveMuc(conversation, true); } else { if (conversation.endOtrIfNeeded()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ended otr session with " + conversation.getJid()); } @@ -3014,7 +3014,7 @@ public class XmppConnectionService extends Service { final Account account = conversation.getAccount(); final Session otrSession = conversation.getOtrSession(); Log.d(Config.LOGTAG, - account.getJid().toBareJid() + " otr session established with " + account.getJid().asBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID()); conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() { @@ -3023,8 +3023,8 @@ public class XmppConnectionService extends Service { public void onMessageFound(Message message) { SessionID id = otrSession.getSessionID(); try { - message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID())); - } catch (InvalidJidException e) { + message.setCounterpart(Jid.of(id.getAccountID() + "/" + id.getUserID())); + } catch (IllegalArgumentException e) { return; } if (message.needsUploading()) { @@ -3125,7 +3125,7 @@ public class XmppConnectionService extends Service { getAvatarService().clear(account); databaseBackend.updateAccount(account); } - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": published avatar "+(avatar.size/1024)+"KiB"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": published avatar "+(avatar.size/1024)+"KiB"); if (callback != null) { callback.success(avatar); } @@ -3138,7 +3138,7 @@ public class XmppConnectionService extends Service { }); } else { Element error = result.findChild("error"); - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": server rejected avatar "+(avatar.size/1024)+"KiB "+(error!=null?error.toString():"")); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server rejected avatar "+(avatar.size/1024)+"KiB "+(error!=null?error.toString():"")); if (callback != null) { callback.error(R.string.error_publish_avatar_server_reject, avatar); } @@ -3149,7 +3149,7 @@ public class XmppConnectionService extends Service { public void republishAvatarIfNeeded(Account account) { if (account.getAxolotlService().isPepBroken()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping republication of avatar because pep is broken"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": skipping republication of avatar because pep is broken"); return; } IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null); @@ -3180,10 +3180,10 @@ public class XmppConnectionService extends Service { if (serverAvatar == null && account.getAvatar() != null) { Avatar avatar = fileBackend.getStoredPepAvatar(account.getAvatar()); if (avatar != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": avatar on server was null. republishing"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar on server was null. republishing"); publishAvatar(account, fileBackend.getStoredPepAvatar(account.getAvatar()), null); } else { - Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": error rereading avatar"); + Log.e(Config.LOGTAG, account.getJid().asBareJid() + ": error rereading avatar"); } } } @@ -3222,13 +3222,13 @@ public class XmppConnectionService extends Service { synchronized (mInProgressAvatarFetches) { mInProgressAvatarFetches.remove(generateFetchKey(account, avatar)); } - final String ERROR = account.getJid().toBareJid() + final String ERROR = account.getJid().asBareJid() + ": fetching avatar for " + avatar.owner + " failed "; if (result.getType() == IqPacket.TYPE.RESULT) { avatar.image = mIqParser.avatarData(result); if (avatar.image != null) { if (getFileBackend().save(avatar)) { - if (account.getJid().toBareJid().equals(avatar.owner)) { + if (account.getJid().asBareJid().equals(avatar.owner)) { if (account.setAvatar(avatar.getFilename())) { databaseBackend.updateAccount(account); } @@ -3246,7 +3246,7 @@ public class XmppConnectionService extends Service { if (callback != null) { callback.success(avatar); } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": successfully fetched pep avatar for " + avatar.owner); return; } @@ -3285,11 +3285,11 @@ public class XmppConnectionService extends Service { if (image != null) { avatar.image = image; if (getFileBackend().save(avatar)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": successfully fetched vCard avatar for " + avatar.owner); if (avatar.owner.isBareJid()) { - if (account.getJid().toBareJid().equals(avatar.owner) && account.getAvatar() == null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": had no avatar. replacing with vcard"); + if (account.getJid().asBareJid().equals(avatar.owner) && account.getAvatar() == null) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": had no avatar. replacing with vcard"); account.setAvatar(avatar.getFilename()); databaseBackend.updateAccount(account); getAvatarService().clear(account); @@ -3302,7 +3302,7 @@ public class XmppConnectionService extends Service { } updateConversationUi(); } else { - Conversation conversation = find(account, avatar.owner.toBareJid()); + Conversation conversation = find(account, avatar.owner.asBareJid()); if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { MucOptions.User user = conversation.getMucOptions().findUserByFullJid(avatar.owner); if (user != null) { @@ -3334,7 +3334,7 @@ public class XmppConnectionService extends Service { if (items != null) { Avatar avatar = Avatar.parseMetadata(items); if (avatar != null) { - avatar.owner = account.getJid().toBareJid(); + avatar.owner = account.getJid().asBareJid(); if (fileBackend.isAvatarCached(avatar)) { if (account.setAvatar(avatar.getFilename())) { databaseBackend.updateAccount(account); @@ -3420,7 +3420,7 @@ public class XmppConnectionService extends Service { } public void invite(Conversation conversation, Jid contact) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": inviting " + contact + " to " + conversation.getJid().toBareJid()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": inviting " + contact + " to " + conversation.getJid().asBareJid()); MessagePacket packet = mMessageGenerator.invite(conversation, contact); sendMessagePacket(conversation.getAccount(), packet); } @@ -3431,7 +3431,7 @@ public class XmppConnectionService extends Service { } public void resetSendingToWaiting(Account account) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": reset 'sending' messages to 'waiting'"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": reset 'sending' messages to 'waiting'"); for (Conversation conversation : getConversations()) { if (conversation.getAccount() == account) { conversation.findUnsentTextMessages(new Conversation.OnMessageFound() { @@ -3454,7 +3454,7 @@ public class XmppConnectionService extends Service { return null; } for (Conversation conversation : getConversations()) { - if (conversation.getJid().toBareJid().equals(recipient) && conversation.getAccount() == account) { + if (conversation.getJid().asBareJid().equals(recipient) && conversation.getAccount() == account) { final Message message = conversation.findSentMessageWithUuidOrRemoteId(uuid); if (message != null) { markMessage(message, status, errorMessage); @@ -3630,7 +3630,7 @@ public class XmppConnectionService extends Service { public Account findAccountByJid(final Jid accountJid) { for (Account account : this.accounts) { - if (account.getJid().toBareJid().equals(accountJid.toBareJid())) { + if (account.getJid().asBareJid().equals(accountJid.asBareJid())) { return account; } } @@ -3701,7 +3701,7 @@ public class XmppConnectionService extends Service { && markable != null && (markable.trusted() || isPrivateAndNonAnonymousMuc) && markable.getRemoteMsgId() != null) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Account account = conversation.getAccount(); final Jid to = markable.getCounterpart(); final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI; @@ -3787,7 +3787,7 @@ public class XmppConnectionService extends Service { } for (Bookmark bookmark : account.getBookmarks()) { final Jid jid = bookmark.getJid(); - final String s = jid == null ? null : jid.getDomainpart(); + final String s = jid == null ? null : jid.getDomain(); if (s != null && !mucServers.contains(s)) { mucServers.add(s); } @@ -3873,7 +3873,7 @@ public class XmppConnectionService extends Service { } private void sendOfflinePresence(final Account account) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending offline presence"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending offline presence"); sendPresencePacket(account, mPresenceGenerator.sendOfflinePresence(account)); } @@ -3905,7 +3905,7 @@ public class XmppConnectionService extends Service { ArrayList<Contact> contacts = new ArrayList<>(); for (Account account : getAccounts()) { if ((account.isEnabled() || accountJid != null) - && (accountJid == null || accountJid.equals(account.getJid().toBareJid().toString()))) { + && (accountJid == null || accountJid.equals(account.getJid().asBareJid().toString()))) { Contact contact = account.getRoster().getContactFromRoster(jid); if (contact != null) { contacts.add(contact); @@ -3917,7 +3917,7 @@ public class XmppConnectionService extends Service { public Conversation findFirstMuc(Jid jid) { for (Conversation conversation : getConversations()) { - if (conversation.getAccount().isEnabled() && conversation.getJid().toBareJid().equals(jid.toBareJid()) && conversation.getMode() == Conversation.MODE_MULTI) { + if (conversation.getAccount().isEnabled() && conversation.getJid().asBareJid().equals(jid.asBareJid()) && conversation.getMode() == Conversation.MODE_MULTI) { return conversation; } } @@ -4004,17 +4004,17 @@ public class XmppConnectionService extends Service { public boolean removeBlockedConversations(final Account account, final Jid blockedJid) { boolean removed = false; synchronized (this.conversations) { - boolean domainJid = blockedJid.isDomainJid(); + boolean domainJid = blockedJid.getLocal() == null; for (Conversation conversation : this.conversations) { - boolean jidMatches = (domainJid && blockedJid.getDomainpart().equals(conversation.getJid().getDomainpart())) - || blockedJid.equals(conversation.getJid().toBareJid()); + boolean jidMatches = (domainJid && blockedJid.getDomain().equals(conversation.getJid().getDomain())) + || blockedJid.equals(conversation.getJid().asBareJid()); if (conversation.getAccount() == account && conversation.getMode() == Conversation.MODE_SINGLE && jidMatches) { this.conversations.remove(conversation); markRead(conversation); conversation.setStatus(Conversation.STATUS_ARCHIVED); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": archiving conversation " + conversation.getJid().toBareJid() + " because jid was blocked"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": archiving conversation " + conversation.getJid().asBareJid() + " because jid was blocked"); updateConversation(conversation); removed = true; } @@ -4046,7 +4046,7 @@ public class XmppConnectionService extends Service { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.ERROR) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not publish nick"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not publish nick"); } } }); @@ -4077,7 +4077,7 @@ public class XmppConnectionService extends Service { IqPacket request = new IqPacket(IqPacket.TYPE.GET); request.setTo(jid); request.query("http://jabber.org/protocol/disco#info"); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": making disco request for " + key.second + " to " + jid); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": making disco request for " + key.second + " to " + jid); sendIqPacket(account, request, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket discoPacket) { @@ -4087,7 +4087,7 @@ public class XmppConnectionService extends Service { databaseBackend.insertDiscoveryResult(disco); injectServiceDiscorveryResult(account.getRoster(), presence.getHash(), presence.getVer(), disco); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco.getVer()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco.getVer()); } } account.inProgressDiscoFetches.remove(key); @@ -4163,9 +4163,9 @@ public class XmppConnectionService extends Service { public void saveConversationAsBookmark(Conversation conversation, String name) { Account account = conversation.getAccount(); - Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid()); + Bookmark bookmark = new Bookmark(account, conversation.getJid().asBareJid()); if (!conversation.getJid().isBareJid()) { - bookmark.setNick(conversation.getJid().getResourcepart()); + bookmark.setNick(conversation.getJid().getResource()); } if (name != null && !name.trim().isEmpty()) { bookmark.setBookmarkName(name.trim()); diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java index 0a27274fd..981b29c41 100644 --- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java +++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java @@ -1,8 +1,8 @@ package de.pixart.messenger.ui; -import android.support.v7.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.support.v7.app.AlertDialog; import android.text.SpannableString; import android.text.Spanned; import android.text.style.TypefaceSpan; @@ -16,6 +16,7 @@ import android.widget.Toast; import de.pixart.messenger.R; import de.pixart.messenger.entities.Blockable; import de.pixart.messenger.entities.Conversation; +import rocks.xmpp.addr.Jid; public final class BlockContactDialog { public static void show(final XmppActivity xmppActivity, final Blockable blockable) { @@ -32,14 +33,14 @@ public final class BlockContactDialog { String value; SpannableString spannable; - if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) { + if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(Jid.ofDomain(blockable.getJid().getDomain()))) { builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain); - value = blockable.getJid().toDomainJid().toString(); + value = Jid.ofDomain(blockable.getJid().getDomain()).toString(); spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value)); } else { int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact; builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction); - value = blockable.getJid().toBareJid().toString(); + value = blockable.getJid().asBareJid().toString(); spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value)); } int start = spannable.toString().indexOf(value); diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java index 22641375a..84d2ab24b 100644 --- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java +++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java @@ -16,7 +16,7 @@ import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.xmpp.OnUpdateBlocklist; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist { private List<String> mKnownHosts = new ArrayList<>(); @@ -86,7 +86,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem EnterJidDialog dialog = new EnterJidDialog( this, mKnownHosts, null, getString(R.string.block_jabber_id), getString(R.string.block), - null, account.getJid().toBareJid().toString(), true, xmppConnectionService.multipleAccounts() + null, account.getJid().asBareJid().toString(), true, xmppConnectionService.multipleAccounts() ); dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java index f2d25d377..4450c8759 100644 --- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java @@ -29,7 +29,7 @@ import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.ListItem; import de.pixart.messenger.entities.MucOptions; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ChooseContactActivity extends AbstractSearchableListItemActivity { private List<String> mActivatedAccounts = new ArrayList<>(); @@ -123,7 +123,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity { data.putExtra("contact", mListItem.getJid().toString()); String account = request.getStringExtra(EXTRA_ACCOUNT); if (account == null && mListItem instanceof Contact) { - account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString(); + account = ((Contact) mListItem).getAccount().getJid().asBareJid().toString(); } data.putExtra(EXTRA_ACCOUNT, account); data.putExtra("conversation", @@ -172,7 +172,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity { if (account.getStatus() != Account.State.DISABLED) { for (final Contact contact : account.getRoster().getContacts()) { if (contact.showInRoster() && - !filterContacts.contains(contact.getJid().toBareJid().toString()) + !filterContacts.contains(contact.getJid().asBareJid().toString()) && contact.match(this, needle)) { getListItems().add(contact); } @@ -242,9 +242,9 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity { for (Account account : xmppConnectionService.getAccounts()) { if (account.getStatus() != Account.State.DISABLED) { if (Config.DOMAIN_LOCK != null) { - this.mActivatedAccounts.add(account.getJid().getLocalpart()); + this.mActivatedAccounts.add(account.getJid().getLocal()); } else { - this.mActivatedAccounts.add(account.getJid().toBareJid().toString()); + this.mActivatedAccounts.add(account.getJid().asBareJid().toString()); } } } @@ -258,17 +258,17 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity { for (MucOptions.User user : conversation.getMucOptions().getUsers(false)) { Jid jid = user.getRealJid(); if (jid != null) { - contacts.add(jid.toBareJid().toString()); + contacts.add(jid.asBareJid().toString()); } } } else { - contacts.add(conversation.getJid().toBareJid().toString()); + contacts.add(conversation.getJid().asBareJid().toString()); } intent.putExtra("filter_contacts", contacts.toArray(new String[contacts.size()])); intent.putExtra("conversation", conversation.getUuid()); intent.putExtra("multiple", true); intent.putExtra("show_enter_jid", true); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); return intent; } } diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index b51bb6329..e82c321d6 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -54,7 +54,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnConversationUpdate; import de.pixart.messenger.services.XmppConnectionService.OnMucRosterUpdate; import de.pixart.messenger.utils.TimeframeUtils; import de.pixart.messenger.utils.UIHelper; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed { public static final String ACTION_VIEW_MUC = "view_muc"; @@ -374,9 +374,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers protected String getShareableUri(boolean http) { if (mConversation != null) { if (http) { - return Config.inviteMUCURL + mConversation.getJid().toBareJid(); + return Config.inviteMUCURL + mConversation.getJid().asBareJid(); } else { - return "xmpp:" + mConversation.getJid().toBareJid() + "?join"; + return "xmpp:" + mConversation.getJid().asBareJid() + "?join"; } } else { return null; @@ -424,7 +424,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (contact != null && contact.showInRoster()) { name = contact.getDisplayName(); } else if (user.getRealJid() != null){ - name = user.getRealJid().toBareJid().toString(); + name = user.getRealJid().asBareJid().toString(); } else { name = user.getName(); } @@ -556,7 +556,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers protected void startConversation(User user) { if (user.getRealJid() != null) { - Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(), user.getRealJid().toBareJid(), false, true); + Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(), user.getRealJid().asBareJid(), false, true); switchToConversation(conversation); } } @@ -598,9 +598,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers final User self = mucOptions.getSelf(); String account; if (Config.DOMAIN_LOCK != null) { - account = mConversation.getAccount().getJid().getLocalpart(); + account = mConversation.getAccount().getJid().getLocal(); } else { - account = mConversation.getAccount().getJid().toBareJid().toString(); + account = mConversation.getAccount().getJid().asBareJid().toString(); } if (getSupportActionBar() != null) { final ActionBar ab = getSupportActionBar(); @@ -625,7 +625,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); setTitle(mConversation.getName()); - mFullJid.setText(mConversation.getJid().toBareJid().toString()); + mFullJid.setText(mConversation.getJid().asBareJid().toString()); mYourNick.setText(mucOptions.getActualNick()); TextView mRoleAffiliaton = findViewById(R.id.muc_role); if (mucOptions.online()) { @@ -753,7 +753,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public void onAffiliationChangeFailed(Jid jid, int resId) { - displayToast(getString(resId, jid.toBareJid().toString())); + displayToast(getString(resId, jid.asBareJid().toString())); } @Override @@ -813,7 +813,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers imageView.setImageBitmap(bm); imageView.setBackgroundColor(0x00000000); } else { - String seed = user.getRealJid() != null ? user.getRealJid().toBareJid().toString() : null; + String seed = user.getRealJid() != null ? user.getRealJid().asBareJid().toString() : null; imageView.setBackgroundColor(UIHelper.getColorForName(seed == null ? user.getName() : seed)); imageView.setImageDrawable(null); final BitmapWorkerTask task = new BitmapWorkerTask(imageView); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 635c5c7d6..18a3e8adc 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -51,8 +51,7 @@ import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated { public static final String ACTION_VIEW_CONTACT = "view_contact"; @@ -232,7 +231,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp protected String getShareableUri(boolean http) { final String prefix = http ? Config.inviteUserURL : "xmpp:"; if (contact != null) { - return prefix + contact.getJid().toBareJid().toString(); + return prefix + contact.getJid().asBareJid().toString(); } else { return ""; } @@ -244,12 +243,12 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo", false); if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) { try { - this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT)); - } catch (final InvalidJidException ignored) { + this.accountJid = Jid.of(getIntent().getExtras().getString(EXTRA_ACCOUNT)); + } catch (final IllegalArgumentException ignored) { } try { - this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact")); - } catch (final InvalidJidException ignored) { + this.contactJid = Jid.of(getIntent().getExtras().getString("contact")); + } catch (final IllegalArgumentException ignored) { } } this.messageFingerprint = getIntent().getStringExtra("fingerprint"); @@ -390,7 +389,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp invalidateOptionsMenu(); setTitle(contact.getDisplayName()); - if (contact.getServer().toString().toLowerCase().equals(accountJid.getDomainpart().toLowerCase())) { + if (contact.getServer().toString().toLowerCase().equals(accountJid.getDomain().toLowerCase())) { binding.contactDisplayName.setText(contact.getDisplayName()); } else { binding.contactDisplayName.setText(contact.getDisplayJid()); @@ -518,9 +517,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } String account; if (Config.DOMAIN_LOCK != null) { - account = contact.getAccount().getJid().getLocalpart(); + account = contact.getAccount().getJid().getLocal(); } else { - account = contact.getAccount().getJid().toBareJid().toString(); + account = contact.getAccount().getJid().asBareJid().toString(); } binding.detailsAccount.setText(getString(R.string.using_account, account)); binding.detailsContactBadge.setImageBitmap(avatarService().get(contact, getPixel(Config.AVATAR_SIZE))); @@ -679,7 +678,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp @Override protected void processFingerprintVerification(XmppUri uri) { - if (contact != null && contact.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { + if (contact != null && contact.getJid().asBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { if (xmppConnectionService.verifyFingerprints(contact, uri.getFingerprints())) { Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show(); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index adfbde7c7..be7fdbc28 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -234,7 +234,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation Intent intent; if (pendingAccount != null) { intent = new Intent(this, EditAccountActivity.class); - intent.putExtra("jid", pendingAccount.getJid().toBareJid().toString()); + intent.putExtra("jid", pendingAccount.getJid().asBareJid().toString()); } else { if (xmppConnectionService.getAccounts().size() == 0) { if (Config.X509_VERIFICATION) { @@ -784,8 +784,8 @@ public class ConversationActivity extends XmppActivity implements OnConversation public boolean onMenuItemClick(MenuItem menuItem) { Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class); intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); - intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString()); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); + intent.putExtra("contact", conversation.getContact().getJid().asBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); switch (menuItem.getItemId()) { case R.id.scan_fingerprint: intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 9425a4eb5..41047b785 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -111,8 +111,7 @@ import de.pixart.messenger.utils.StylingHelper; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.chatstate.ChatState; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT; import static de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION; @@ -369,8 +368,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void onClick(View view) { Intent intent = new Intent(activity, VerifyOTRActivity.class); intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); - intent.putExtra(VerifyOTRActivity.EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); + intent.putExtra(VerifyOTRActivity.EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION); startActivity(intent); } @@ -920,7 +919,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke contacts[i] = targets.get(i).toString(); } intent.putExtra("contacts", contacts); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); intent.putExtra("choice", attachmentChoice); intent.putExtra("conversation", conversation.getUuid()); startActivityForResult(intent, requestCode); @@ -938,10 +937,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } else if (multi && conversation.getNextCounterpart() != null) { this.binding.textinput.setHint(getString( R.string.send_private_message_to, - conversation.getNextCounterpart().getResourcepart())); + conversation.getNextCounterpart().getResource())); showMessageHint(getString( R.string.send_private_message_to, - conversation.getNextCounterpart().getResourcepart())); + conversation.getNextCounterpart().getResource())); } else if (multi && !conversation.getMucOptions().participating()) { this.binding.textinput.setHint(R.string.you_are_not_participating); hideMessageHint(); @@ -1126,9 +1125,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Jid user = message.getCounterpart(); if (user != null && !user.isBareJid()) { if (!message.getConversation().getMucOptions().isUserInRoom(user)) { - Toast.makeText(activity, getActivity().getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, getActivity().getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show(); } - highlightInConference(user.getResourcepart()); + highlightInConference(user.getResource()); } return; } else { @@ -1147,7 +1146,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } Account account = message.getConversation().getAccount(); Intent intent = new Intent(activity, EditAccountActivity.class); - intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("jid", account.getJid().asBareJid().toString()); String fingerprint; if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { @@ -1171,7 +1170,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (mucOptions.isUserInRoom(user)) { privateMessageWith(user); } else { - Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show(); } } } @@ -2127,9 +2126,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (pm) { Jid jid = conversation.getJid(); try { - Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick); + Jid next = Jid.of(jid.getLocal(), jid.getDomain(), nick); privateMessageWith(next); - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { //do nothing } } else { @@ -2146,7 +2145,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private boolean showBlockSubmenu(View view) { final Jid jid = conversation.getJid(); - if (jid.isDomainJid()) { + if (jid.getLocal() == null) { BlockContactDialog.show(activity, conversation); } else { PopupMenu popupMenu = new PopupMenu(getActivity(), view); @@ -2155,7 +2154,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Blockable blockable; switch (menuItem.getItemId()) { case R.id.block_domain: - blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid()); + blockable = conversation.getAccount().getRoster().getContact(Jid.ofDomain(jid.getDomain())); break; default: blockable = conversation; @@ -2247,7 +2246,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected()) || Config.supportOtr()))) { - if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) { + if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomain())) { hideSnackbar(); } else { showSnackbar(R.string.conversation_unencrypted_hint, R.string.ok, mHideUnencryptionHint, null); @@ -2256,7 +2255,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke (conversation.getNextEncryption() == Message.ENCRYPTION_NONE && ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected())))) { - if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) { + if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomain())) { Log.d(Config.LOGTAG, "Don't show unencrypted warning because " + conversation.getJid().toString() + " is on exception list"); hideSnackbar(); } else { diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 036ddabab..acbf89211 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -74,9 +74,8 @@ import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.XmppConnection.Features; import de.pixart.messenger.xmpp.forms.Data; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.pep.Avatar; +import rocks.xmpp.addr.Jid; public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched { @@ -181,11 +180,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat final Jid jid; try { if (mUsernameMode) { - jid = Jid.fromParts(binding.accountJid.getText().toString(), getUserModeDomain(), null); + jid = Jid.of(binding.accountJid.getText().toString(), getUserModeDomain(), null); } else { - jid = Jid.fromString(binding.accountJid.getText().toString()); + jid = Jid.of(binding.accountJid.getText().toString()); } - } catch (final InvalidJidException e) { + } catch (final IllegalArgumentException e) { if (mUsernameMode) { mAccountJidLayout.setError(getString(R.string.invalid_username)); } else { @@ -223,7 +222,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } - if (jid.isDomainJid()) { + if (jid.getLocal() == null) { if (mUsernameMode) { mAccountJidLayout.setError(getString(R.string.invalid_username)); } else { @@ -263,7 +262,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat binding.accountJid.requestFocus(); return; } - mAccount = new Account(jid.toBareJid(), password); + mAccount = new Account(jid.asBareJid(), password); mAccount.setPort(numericPort); mAccount.setHostname(hostname); mAccount.setOption(Account.OPTION_USETLS, true); @@ -406,7 +405,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat public void onClick(final View view) { if (mAccount != null) { final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); - intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().asBareJid().toString()); startActivity(intent); } } @@ -425,7 +424,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } else { intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); - intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().asBareJid().toString()); intent.putExtra("setup", true); } if (wasFirstAccount) { @@ -460,7 +459,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat protected void processFingerprintVerification(XmppUri uri, boolean showWarningToast) { - if (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { + if (mAccount != null && mAccount.getJid().asBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) { Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); } @@ -527,9 +526,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat protected boolean jidEdited() { final String unmodified; if (mUsernameMode) { - unmodified = this.mAccount.getJid().getLocalpart(); + unmodified = this.mAccount.getJid().getLocal(); } else { - unmodified = this.mAccount.getJid().toBareJid().toString(); + unmodified = this.mAccount.getJid().asBareJid().toString(); } return !unmodified.equals(this.binding.accountJid.getText().toString()); } @@ -696,8 +695,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat recreate(); } else if (getIntent() != null) { try { - this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid")); - } catch (final InvalidJidException | NullPointerException ignored) { + this.jidToEdit = Jid.of(getIntent().getStringExtra("jid")); + } catch (final IllegalArgumentException | NullPointerException ignored) { this.jidToEdit = null; } if (jidToEdit != null && getIntent().getData() != null) { @@ -749,7 +748,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat @Override public void onSaveInstanceState(final Bundle savedInstanceState) { if (mAccount != null) { - savedInstanceState.putString("account", mAccount.getJid().toBareJid().toString()); + savedInstanceState.putString("account", mAccount.getJid().asBareJid().toString()); savedInstanceState.putBoolean("initMode", mInitMode); savedInstanceState.putBoolean("showMoreTable", mMoreTable.getVisibility() == View.VISIBLE); } @@ -760,10 +759,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat boolean init = true; if (mSavedInstanceAccount != null) { try { - this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(mSavedInstanceAccount)); + this.mAccount = xmppConnectionService.findAccountByJid(Jid.of(mSavedInstanceAccount)); this.mInitMode = mSavedInstanceInit; init = false; - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { this.mAccount = null; } @@ -809,7 +808,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private String getUserModeDomain() { if (mAccount != null) { - return mAccount.getJid().getDomainpart(); + return mAccount.getJid().getDomain(); } else { return Config.DOMAIN_LOCK; } @@ -995,9 +994,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (init) { this.binding.accountJid.getEditableText().clear(); if (mUsernameMode) { - this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocalpart()); + this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocal()); } else { - this.binding.accountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString()); + this.binding.accountJid.getEditableText().append(this.mAccount.getJid().asBareJid().toString()); } this.mPassword.getEditableText().clear(); this.mPassword.getEditableText().append(this.mAccount.getPassword()); diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java index 2f3315d22..713279422 100644 --- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java +++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java @@ -16,8 +16,7 @@ import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.ui.adapter.KnownHostsAdapter; import de.pixart.messenger.ui.util.DelayedHintHelper; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class EnterJidDialog { public interface OnEnterJidDialogPositiveListener { @@ -95,17 +94,17 @@ public class EnterJidDialog { } try { if (Config.DOMAIN_LOCK != null) { - accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null); + accountJid = Jid.of((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null); } else { - accountJid = Jid.fromString((String) spinner.getSelectedItem()); + accountJid = Jid.of((String) spinner.getSelectedItem()); } - } catch (final InvalidJidException e) { + } catch (final IllegalArgumentException e) { return; } final Jid contactJid; try { - contactJid = Jid.fromString(jid.getText().toString()); - } catch (final InvalidJidException e) { + contactJid = Jid.of(jid.getText().toString()); + } catch (final IllegalArgumentException e) { jid.setError(context.getString(R.string.invalid_jid)); return; } diff --git a/src/main/java/de/pixart/messenger/ui/LocationActivity.java b/src/main/java/de/pixart/messenger/ui/LocationActivity.java index 04bd03584..ccf28bdf2 100644 --- a/src/main/java/de/pixart/messenger/ui/LocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/LocationActivity.java @@ -1,6 +1,5 @@ package de.pixart.messenger.ui; -import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; diff --git a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java index 7f4531b41..91c527ca1 100644 --- a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java @@ -16,8 +16,7 @@ import java.security.SecureRandom; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class MagicCreateActivity extends XmppActivity implements TextWatcher { @@ -66,7 +65,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { } else { mUsername.setError(null); try { - Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); Account account = xmppConnectionService.findAccountByJid(jid); if (account == null) { account = new Account(jid, createPassword()); @@ -76,13 +75,13 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { xmppConnectionService.createAccount(account); } Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class); - intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("init", true); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show(); WelcomeActivity.addInviteUri(intent, getIntent()); startActivity(intent); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { mUsername.setError(getString(R.string.invalid_username)); mUsername.requestFocus(); } @@ -114,9 +113,9 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { if (s.toString().trim().length() > 0) { try { mFullJidDisplay.setVisibility(View.VISIBLE); - Jid jid = Jid.fromParts(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString())); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { mFullJidDisplay.setVisibility(View.INVISIBLE); } diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index 253dccd1c..9513c2fca 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -1,12 +1,12 @@ package de.pixart.messenger.ui; -import android.support.v7.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.Bundle; import android.security.KeyChain; import android.security.KeyChainAliasCallback; import android.support.v7.app.ActionBar; +import android.support.v7.app.AlertDialog; import android.util.Pair; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -32,8 +32,7 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.ui.adapter.AccountAdapter; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate, KeyChainAliasCallback, XmppConnectionService.OnAccountCreated { @@ -80,8 +79,8 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT); if (jid != null) { try { - this.selectedAccountJid = Jid.fromString(jid); - } catch (InvalidJidException e) { + this.selectedAccountJid = Jid.of(jid); + } catch (IllegalArgumentException e) { this.selectedAccountJid = null; } } @@ -113,7 +112,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda @Override public void onSaveInstanceState(final Bundle savedInstanceState) { if (selectedAccount != null) { - savedInstanceState.putString(STATE_SELECTED_ACCOUNT, selectedAccount.getJid().toBareJid().toString()); + savedInstanceState.putString(STATE_SELECTED_ACCOUNT, selectedAccount.getJid().asBareJid().toString()); } super.onSaveInstanceState(savedInstanceState); } @@ -132,7 +131,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(false); menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false); } - menu.setHeaderTitle(this.selectedAccount.getJid().toBareJid().toString()); + menu.setHeaderTitle(this.selectedAccount.getJid().asBareJid().toString()); } @Override @@ -362,7 +361,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda @Override public void onAccountCreated(Account account) { Intent intent = new Intent(this, EditAccountActivity.class); - intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("init", true); startActivity(intent); } diff --git a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java index 850188a2c..338647be8 100644 --- a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java +++ b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java @@ -3,7 +3,6 @@ package de.pixart.messenger.ui; import android.content.Intent; import android.databinding.DataBindingUtil; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.view.ContextMenu; import android.view.MenuItem; diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index fc50ce444..da6373250 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -38,8 +38,7 @@ import de.pixart.messenger.services.ExportLogsService; import de.pixart.messenger.services.MemorizingTrustManager; import de.pixart.messenger.ui.util.Color; import de.pixart.messenger.utils.TimeframeUtils; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener { @@ -314,7 +313,7 @@ public class SettingsActivity extends XmppActivity implements final List<CharSequence> accounts = new ArrayList<>(); for (Account account : xmppConnectionService.getAccounts()) { if (account.isEnabled()) { - accounts.add(account.getJid().toBareJid().toString()); + accounts.add(account.getJid().asBareJid().toString()); } } final boolean[] checkedItems = new boolean[accounts.size()]; @@ -334,12 +333,12 @@ public class SettingsActivity extends XmppActivity implements for (int i = 0; i < checkedItems.length; ++i) { if (checkedItems[i]) { try { - Jid jid = Jid.fromString(accounts.get(i).toString()); + Jid jid = Jid.of(accounts.get(i).toString()); Account account = xmppConnectionService.findAccountByJid(jid); if (account != null) { account.getAxolotlService().regenerateKeys(true); } - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { // } } diff --git a/src/main/java/de/pixart/messenger/ui/ShareViaAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ShareViaAccountActivity.java index 509cd63f4..74892ed93 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareViaAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareViaAccountActivity.java @@ -14,8 +14,7 @@ import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.ui.adapter.AccountAdapter; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ShareViaAccountActivity extends XmppActivity { public static final String EXTRA_CONTACT = "contact"; @@ -57,11 +56,11 @@ public class ShareViaAccountActivity extends XmppActivity { final String body = getIntent().getStringExtra(EXTRA_BODY); try { - final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT)); + final Jid contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT)); final Conversation conversation = xmppConnectionService.findOrCreateConversation( account, contact, false, false); switchToConversation(conversation, body, false); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { // ignore error } @@ -88,11 +87,11 @@ public class ShareViaAccountActivity extends XmppActivity { final Account account = xmppConnectionService.getAccounts().get(0); try { - final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT)); + final Jid contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT)); final Conversation conversation = xmppConnectionService.findOrCreateConversation( account, contact, false, false); switchToConversation(conversation, body, false); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { // ignore error } diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index cbd2ca0eb..864653052 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -28,8 +28,7 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.adapter.ConversationAdapter; import de.pixart.messenger.ui.util.PresenceSelector; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; import static java.lang.String.format; @@ -295,8 +294,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } else { Account account; try { - account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account)); - } catch (final InvalidJidException e) { + account = xmppConnectionService.findAccountByJid(Jid.of(share.account)); + } catch (final IllegalArgumentException e) { account = null; } if (account == null) { @@ -305,8 +304,8 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer try { conversation = xmppConnectionService - .findOrCreateConversation(account, Jid.fromString(share.contact), false, true); - } catch (final InvalidJidException e) { + .findOrCreateConversation(account, Jid.of(share.contact), false, true); + } catch (final IllegalArgumentException e) { return; } } diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 16931f994..7be9c090a 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -74,8 +74,7 @@ import de.pixart.messenger.ui.util.DelayedHintHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; @@ -264,6 +263,18 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU this.binding = DataBindingUtil.setContentView(this, R.layout.activity_start_conversation); this.binding.fab.setOnClickListener((v) -> { if (getSupportActionBar().getSelectedNavigationIndex() == 0) { + String searchString = mSearchEditText != null ? mSearchEditText.getText().toString() : null; + if (searchString != null && !searchString.trim().isEmpty()) { + try { + Jid jid = Jid.of(searchString); + if (jid.getLocal() != null && jid.isBareJid() && jid.getDomain().contains(".")) { + showCreateContactDialog(jid.toString(), null); + return; + } + } catch (IllegalArgumentException ignored) { + //ignore and fall through + } + } showCreateContactDialog(null, null); } else { showCreateConferenceDialog(); @@ -353,7 +364,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU Bookmark bookmark = (Bookmark) conferences.get(position); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); - shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().toBareJid().toString() + "?join"); + shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toString() + "?join"); shareIntent.setType("text/plain"); try { startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); @@ -510,8 +521,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } final Jid conferenceJid; try { - conferenceJid = Jid.fromString(jid.getText().toString()); - } catch (final InvalidJidException e) { + conferenceJid = Jid.of(jid.getText().toString()); + } catch (final IllegalArgumentException e) { jid.setError(getString(R.string.invalid_jid)); return; } @@ -520,9 +531,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU if (account.hasBookmarkFor(conferenceJid)) { jid.setError(getString(R.string.bookmark_already_exists)); } else { - final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid()); + final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))); - String nick = conferenceJid.getResourcepart(); + String nick = conferenceJid.getResource(); if (nick != null && !nick.isEmpty()) { bookmark.setNick(nick); } @@ -571,7 +582,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU intent.putExtra("multiple", true); intent.putExtra("show_enter_jid", true); intent.putExtra("subject", subject.getText().toString()); - intent.putExtra(EXTRA_ACCOUNT, account.getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, account.getJid().asBareJid().toString()); intent.putExtra(ChooseContactActivity.EXTRA_TITLE_RES_ID, R.string.choose_participants); startActivityForResult(intent, REQUEST_CREATE_CONFERENCE); }); @@ -587,11 +598,11 @@ 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 = Jid.of((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null); } else { - jid = Jid.fromString((String) spinner.getSelectedItem()); + jid = Jid.of((String) spinner.getSelectedItem()); } - } catch (final InvalidJidException e) { + } catch (final IllegalArgumentException e) { return null; } return xmppConnectionService.findAccountByJid(jid); @@ -686,14 +697,14 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU String[] toAdd = intent.getStringArrayExtra("contacts"); for (String item : toAdd) { try { - jids.add(Jid.fromString(item)); - } catch (InvalidJidException e) { + jids.add(Jid.of(item)); + } catch (IllegalArgumentException e) { //ignored } } } else { try { - jids.add(Jid.fromString(intent.getStringExtra("contact"))); + jids.add(Jid.of(intent.getStringExtra("contact"))); } catch (Exception e) { //ignored } @@ -769,9 +780,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU for (Account account : xmppConnectionService.getAccounts()) { if (account.getStatus() != Account.State.DISABLED) { if (Config.DOMAIN_LOCK != null) { - this.mActivatedAccounts.add(account.getJid().getLocalpart()); + this.mActivatedAccounts.add(account.getJid().getLocal()); } else { - this.mActivatedAccounts.add(account.getJid().toBareJid().toString()); + this.mActivatedAccounts.add(account.getJid().asBareJid().toString()); } } } @@ -839,7 +850,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU switchToConversation(muc, invite.getBody(), false); return true; } else { - showJoinConferenceDialog(invite.getJid().toBareJid().toString()); + showJoinConferenceDialog(invite.getJid().asBareJid().toString()); return false; } } else if (contacts.size() == 0) { @@ -880,7 +891,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null); final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source); TextView warning = view.findViewById(R.id.warning); - String jid = contact.getJid().toBareJid().toString(); + String jid = contact.getJid().asBareJid().toString(); SpannableString spannable = new SpannableString(getString(R.string.verifying_omemo_keys_trusted_source, jid, contact.getDisplayName())); int start = spannable.toString().indexOf(jid); if (start >= 0) { diff --git a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java index 5641fc171..3f97b12f9 100644 --- a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java +++ b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java @@ -33,8 +33,7 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdated { private List<Jid> contactJids; @@ -80,8 +79,8 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat this.contactJids = new ArrayList<>(); for(String jid : getIntent().getStringArrayExtra("contacts")) { try { - this.contactJids.add(Jid.fromString(jid)); - } catch (InvalidJidException e) { + this.contactJids.add(Jid.of(jid)); + } catch (IllegalArgumentException e) { e.printStackTrace(); } } @@ -226,7 +225,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat showCameraToast(); } - binding.ownKeysTitle.setText(mAccount.getJid().toBareJid().toString()); + binding.ownKeysTitle.setText(mAccount.getJid().asBareJid().toString()); binding.ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE); binding.foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE); if(hasPendingKeyFetches()) { diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index f62454510..f9b5ef164 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -1,7 +1,6 @@ package de.pixart.messenger.ui; import android.Manifest; -import android.support.v7.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; @@ -17,6 +16,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.PowerManager; import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AlertDialog; import android.util.Log; import android.widget.TextView; import android.widget.Toast; diff --git a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java index 47355ecba..dea4f3194 100644 --- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java @@ -16,7 +16,7 @@ import java.util.List; import de.pixart.messenger.R; import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.utils.XmppUri; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class UriHandlerActivity extends AppCompatActivity { @@ -102,7 +102,7 @@ public class UriHandlerActivity extends AppCompatActivity { } else if (accounts.contains(xmppUri.getJid())) { intent = new Intent(getApplicationContext(), EditAccountActivity.class); intent.setAction(Intent.ACTION_VIEW); - intent.putExtra("jid", xmppUri.getJid().toBareJid().toString()); + intent.putExtra("jid", xmppUri.getJid().asBareJid().toString()); intent.setData(uri); } else if (xmppUri.isJidValid()) { intent = new Intent(getApplicationContext(), StartConversationActivity.class); diff --git a/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java b/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java index 83518fcda..2bdbbae97 100644 --- a/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java +++ b/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java @@ -23,8 +23,7 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.XmppUri; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class VerifyOTRActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { @@ -197,11 +196,11 @@ 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, Jid.of(intent.getExtras().getString("contact"))); if (this.mConversation == null) { return false; } - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { return false; } this.mode = intent.getIntExtra("mode", MODE_MANUAL_VERIFICATION); diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index 26a4c0899..07c6e1ff7 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -1,7 +1,6 @@ package de.pixart.messenger.ui; import android.Manifest; -import android.support.v7.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; @@ -12,6 +11,7 @@ import android.database.sqlite.SQLiteException; import android.os.Build; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; @@ -118,7 +118,7 @@ public class WelcomeActivity extends XmppActivity { List<Account> accounts = xmppConnectionService.getAccounts(); Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class); if (accounts.size() == 1) { - intent.putExtra("jid", accounts.get(0).getJid().toBareJid().toString()); + intent.putExtra("jid", accounts.get(0).getJid().asBareJid().toString()); intent.putExtra("init", true); } else if (accounts.size() >= 1) { intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class); diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index ba03663f3..3e95af5ed 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -78,8 +78,7 @@ import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.ExceptionHelper; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.OnUpdateBlocklist; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public abstract class XmppActivity extends AppCompatActivity { @@ -387,7 +386,7 @@ public abstract class XmppActivity extends AppCompatActivity { if (xmppConnectionService.getAccounts().size() == 1 && !xmppConnectionService.multipleAccounts()) { final Intent intent = new Intent(getApplicationContext(), EditAccountActivity.class); Account mAccount = xmppConnectionService.getAccounts().get(0); - intent.putExtra("jid", mAccount.getJid().toBareJid().toString()); + intent.putExtra("jid", mAccount.getJid().asBareJid().toString()); intent.putExtra("init", false); startActivity(intent); } else { @@ -521,7 +520,7 @@ public abstract class XmppActivity extends AppCompatActivity { public void switchToContactDetails(Contact contact, String messageFingerprint) { Intent intent = new Intent(this, ContactDetailsActivity.class); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); - intent.putExtra(EXTRA_ACCOUNT, contact.getAccount().getJid().toBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, contact.getAccount().getJid().asBareJid().toString()); intent.putExtra("contact", contact.getJid().toString()); intent.putExtra("fingerprint", messageFingerprint); startActivity(intent); @@ -533,7 +532,7 @@ public abstract class XmppActivity extends AppCompatActivity { public void switchToAccount(Account account, boolean init) { Intent intent = new Intent(this, EditAccountActivity.class); - intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("init", init); if (init) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); @@ -806,8 +805,8 @@ public abstract class XmppActivity extends AppCompatActivity { SessionID id = conversation.getOtrSession().getSessionID(); Jid jid; try { - jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID()); - } catch (InvalidJidException e) { + jid = Jid.of(id.getAccountID() + "/" + id.getUserID()); + } catch (IllegalArgumentException e) { jid = null; } conversation.setNextCounterpart(jid); @@ -831,8 +830,8 @@ public abstract class XmppActivity extends AppCompatActivity { } else if (presences.size() == 1) { String presence = presences.toResourceArray()[0]; try { - conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence)); - } catch (InvalidJidException e) { + conversation.setNextCounterpart(Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), presence)); + } catch (IllegalArgumentException e) { conversation.setNextCounterpart(null); } listener.onPresenceSelected(); @@ -882,9 +881,9 @@ public abstract class XmppActivity extends AppCompatActivity { builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.ok, (dialog, which) -> { try { - Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]); + Jid next = Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), resourceArray[selectedResource.get()]); conversation.setNextCounterpart(next); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { conversation.setNextCounterpart(null); } listener.onPresenceSelected(); @@ -952,8 +951,8 @@ public abstract class XmppActivity extends AppCompatActivity { private void inviteUser() { Account mAccount = xmppConnectionService.getAccounts().get(0); - String user = mAccount.getJid().getLocalpart().toString(); - String domain = mAccount.getJid().getDomainpart().toString(); + String user = mAccount.getJid().getLocal().toString(); + String domain = mAccount.getJid().getDomain().toString(); String inviteURL = Config.inviteUserURL + user + "/" + domain; String inviteText = getString(R.string.InviteText, user); Intent intent = new Intent(android.content.Intent.ACTION_SEND); @@ -1040,8 +1039,8 @@ public abstract class XmppActivity extends AppCompatActivity { protected Account extractAccount(Intent intent) { String jid = intent != null ? intent.getStringExtra(EXTRA_ACCOUNT) : null; try { - return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null; - } catch (InvalidJidException e) { + return jid != null ? xmppConnectionService.findAccountByJid(Jid.of(jid)) : null; + } catch (IllegalArgumentException e) { return null; } } @@ -1100,12 +1099,12 @@ public abstract class XmppActivity extends AppCompatActivity { if (data.getBooleanExtra("multiple", false)) { String[] toAdd = data.getStringArrayExtra("contacts"); for (String item : toAdd) { - invite.jids.add(Jid.fromString(item)); + invite.jids.add(Jid.of(item)); } } else { - invite.jids.add(Jid.fromString(data.getStringExtra("contact"))); + invite.jids.add(Jid.of(data.getStringExtra("contact"))); } - } catch (final InvalidJidException ignored) { + } catch (final IllegalArgumentException ignored) { return null; } return invite; @@ -1123,7 +1122,7 @@ public abstract class XmppActivity extends AppCompatActivity { } return false; } else { - jids.add(conversation.getJid().toBareJid()); + jids.add(conversation.getJid().asBareJid()); return service.createAdhocConference(conversation.getAccount(), null, jids, activity.adhocCallback); } } diff --git a/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java index 81a3017a8..a7c20eb0e 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java @@ -43,9 +43,9 @@ public class AccountAdapter extends ArrayAdapter<Account> { } TextView jid = view.findViewById(R.id.account_jid); if (Config.DOMAIN_LOCK != null) { - jid.setText(account.getJid().getLocalpart()); + jid.setText(account.getJid().getLocal()); } else { - jid.setText(account.getJid().toBareJid().toString()); + jid.setText(account.getJid().asBareJid().toString()); } TextView statusView = view.findViewById(R.id.account_status); ImageView imageView = view.findViewById(R.id.account_image); @@ -99,7 +99,7 @@ public class AccountAdapter extends ArrayAdapter<Account> { imageView.setImageBitmap(bm); imageView.setBackgroundColor(0x00000000); } else { - imageView.setBackgroundColor(UIHelper.getColorForName(account.getJid().toBareJid().toString())); + imageView.setBackgroundColor(UIHelper.getColorForName(account.getJid().asBareJid().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/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java index 16ad8f6a0..ad1f9df7b 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java @@ -85,7 +85,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { viewHolder.name.setText(EmojiWrapper.transform(conversation.getName())); } else { - viewHolder.name.setText(conversation.getJid().toBareJid().toString()); + viewHolder.name.setText(conversation.getJid().asBareJid().toString()); } Message message = conversation.getLatestMessage(); diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java index 2df1e5b0f..f25e6e51d 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/ListItemAdapter.java @@ -164,7 +164,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> { imageView.setImageBitmap(bm); imageView.setBackgroundColor(0x00000000); } else { - String seed = item.getJid() != null ? item.getJid().toBareJid().toString() : item.getDisplayName(); + String seed = item.getJid() != null ? item.getJid().asBareJid().toString() : item.getDisplayName(); imageView.setBackgroundColor(UIHelper.getColorForName(seed)); imageView.setImageDrawable(null); final BitmapWorkerTask task = new BitmapWorkerTask(imageView); diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 9f09531e1..d243e60bd 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -576,7 +576,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } else { final String to; if (message.getCounterpart() != null) { - to = message.getCounterpart().getResourcepart(); + to = message.getCounterpart().getResource(); } else { to = ""; } diff --git a/src/main/java/de/pixart/messenger/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/de/pixart/messenger/ui/forms/FormJidSingleFieldWrapper.java index b6aeaf344..b011cc77b 100644 --- a/src/main/java/de/pixart/messenger/ui/forms/FormJidSingleFieldWrapper.java +++ b/src/main/java/de/pixart/messenger/ui/forms/FormJidSingleFieldWrapper.java @@ -7,8 +7,7 @@ import java.util.List; import de.pixart.messenger.R; import de.pixart.messenger.xmpp.forms.Field; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { @@ -23,8 +22,8 @@ public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { String value = getValue(); if (!value.isEmpty()) { try { - Jid.fromString(value); - } catch (InvalidJidException e) { + Jid.of(value); + } catch (IllegalArgumentException e) { editText.setError(context.getString(R.string.invalid_jid)); editText.requestFocus(); return false; diff --git a/src/main/java/de/pixart/messenger/ui/util/PresenceSelector.java b/src/main/java/de/pixart/messenger/ui/util/PresenceSelector.java index bc72cd889..ce6ff84e7 100644 --- a/src/main/java/de/pixart/messenger/ui/util/PresenceSelector.java +++ b/src/main/java/de/pixart/messenger/ui/util/PresenceSelector.java @@ -43,8 +43,7 @@ import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.Presences; import de.pixart.messenger.utils.CryptoHelper; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class PresenceSelector { @@ -89,9 +88,9 @@ public class PresenceSelector { builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.ok, (dialog, which) -> { try { - Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]); + Jid next = Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), resourceArray[selectedResource.get()]); conversation.setNextCounterpart(next); - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { conversation.setNextCounterpart(null); } listener.onPresenceSelected(); diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java index c203aa930..f75201b78 100644 --- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java @@ -31,8 +31,7 @@ import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Message; import de.pixart.messenger.http.AesGcmURLStreamHandler; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public final class CryptoHelper { public static final String FILETRANSFER = "?FILETRANSFERv1:"; @@ -148,7 +147,7 @@ public final class CryptoHelper { } } - public static Pair<Jid, String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, InvalidJidException, CertificateParsingException { + public static Pair<Jid, String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, IllegalArgumentException, CertificateParsingException { Collection<List<?>> alternativeNames = certificate.getSubjectAlternativeNames(); List<String> emails = new ArrayList<>(); if (alternativeNames != null) { @@ -165,14 +164,14 @@ public final class CryptoHelper { } String name = x500name.getRDNs(BCStyle.CN).length > 0 ? IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()) : null; if (emails.size() >= 1) { - return new Pair<>(Jid.fromString(emails.get(0)), name); + return new Pair<>(Jid.of(emails.get(0)), name); } else if (name != null) { try { - Jid jid = Jid.fromString(name); - if (jid.isBareJid() && !jid.isDomainJid()) { + Jid jid = Jid.of(name); + if (jid.isBareJid() && jid.getLocal() != null) { return new Pair<>(jid, null); } - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { return null; } } @@ -224,7 +223,7 @@ public final class CryptoHelper { } public static String getAccountFingerprint(Account account) { - return getFingerprint(account.getJid().toBareJid().toString()); + return getFingerprint(account.getJid().asBareJid().toString()); } public static String getFingerprint(String value) { diff --git a/src/main/java/de/pixart/messenger/utils/ExceptionHelper.java b/src/main/java/de/pixart/messenger/utils/ExceptionHelper.java index b1d4da78b..b1799d490 100644 --- a/src/main/java/de/pixart/messenger/utils/ExceptionHelper.java +++ b/src/main/java/de/pixart/messenger/utils/ExceptionHelper.java @@ -28,8 +28,7 @@ import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.Message; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.XmppActivity; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class ExceptionHelper { private static final String FILENAME = "stacktrace.txt"; @@ -101,14 +100,14 @@ public class ExceptionHelper { public void onClick(DialogInterface dialog, int which) { Log.d(Config.LOGTAG, "using account=" - + finalAccount.getJid().toBareJid() + + finalAccount.getJid().asBareJid() + " to send in stack trace"); Conversation conversation = null; try { conversation = service.findOrCreateConversation(finalAccount, - Jid.fromString(Config.BUG_REPORTS), false, true); - } catch (final InvalidJidException ignored) { + Jid.of(Config.BUG_REPORTS), false, true); + } catch (final IllegalArgumentException ignored) { } Message message = new Message(conversation, report .toString(), Message.ENCRYPTION_NONE); diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java index de8fe4dbd..f9a0b8db8 100644 --- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java @@ -79,7 +79,7 @@ public class GeoHelper { locationPluginIntent.putExtra("longitude", longitude); if (message.getStatus() != Message.STATUS_RECEIVED) { locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString()); - locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocalpart()); + locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocal()); } else { Contact contact = message.getContact(); if (contact != null) { diff --git a/src/main/java/de/pixart/messenger/utils/JidHelper.java b/src/main/java/de/pixart/messenger/utils/JidHelper.java index 625b56a58..a569c5960 100644 --- a/src/main/java/de/pixart/messenger/utils/JidHelper.java +++ b/src/main/java/de/pixart/messenger/utils/JidHelper.java @@ -34,19 +34,19 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class JidHelper { private static List<String> LOCALPART_BLACKLIST = Arrays.asList("xmpp", "jabber", "me"); public static String localPartOrFallback(Jid jid) { - if (LOCALPART_BLACKLIST.contains(jid.getLocalpart().toLowerCase(Locale.ENGLISH))) { - final String domain = jid.getDomainpart(); + if (LOCALPART_BLACKLIST.contains(jid.getLocal().toLowerCase(Locale.ENGLISH))) { + final String domain = jid.getDomain(); final int index = domain.lastIndexOf('.'); return index > 1 ? domain.substring(0, index) : domain; } else { - return jid.getUnescapedLocalpart(); + return jid.getLocal(); } } diff --git a/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java b/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java index 5ef8d2d25..18219c93e 100644 --- a/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java +++ b/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java @@ -5,18 +5,17 @@ import java.util.List; import java.util.Set; import de.pixart.messenger.entities.Conversation; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class NickValidityChecker { private static boolean check(final Conversation conversation, final String nick) { Jid room = conversation.getJid(); try { - Jid full = Jid.fromParts(room.getLocalpart(), room.getDomainpart(), nick); + Jid full = Jid.of(room.getLocal(), room.getDomain(), nick); return conversation.hasMessageWithCounterpart(full) || conversation.getMucOptions().findUserByFullJid(full) != null; - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { return false; } } diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index f42d6b73e..92efe4d26 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -4,10 +4,7 @@ import android.content.Context; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.util.Pair; -import android.widget.PopupMenu; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.math.BigInteger; import java.security.MessageDigest; import java.util.Arrays; @@ -26,7 +23,7 @@ import de.pixart.messenger.entities.Message; import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.Transferable; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class UIHelper { @@ -474,7 +471,7 @@ public class UIHelper { return conversation.getMucOptions().getSelf().getName(); } else { final Jid jid = conversation.getAccount().getJid(); - return jid.hasLocalpart() ? jid.getLocalpart() : jid.toDomainJid().toString(); + return jid.getLocal() != null ? jid.getLocal() : Jid.ofDomain(jid.getDomain()).toString(); } } } @@ -507,7 +504,7 @@ public class UIHelper { if (counterpart == null) { return ""; } else if (!counterpart.isBareJid()) { - return counterpart.getResourcepart().trim(); + return counterpart.getResource().trim(); } else { return counterpart.toString().trim(); } diff --git a/src/main/java/de/pixart/messenger/utils/XmppUri.java b/src/main/java/de/pixart/messenger/utils/XmppUri.java index 0600986c7..fec5ff039 100644 --- a/src/main/java/de/pixart/messenger/utils/XmppUri.java +++ b/src/main/java/de/pixart/messenger/utils/XmppUri.java @@ -8,8 +8,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class XmppUri { @@ -31,8 +30,8 @@ public class XmppUri { parse(Uri.parse(uri)); } catch (IllegalArgumentException e) { try { - jid = Jid.fromString(uri).toBareJid().toString(); - } catch (InvalidJidException e2) { + jid = Jid.of(uri).asBareJid().toString(); + } catch (IllegalArgumentException e2) { jid = null; } } @@ -65,7 +64,7 @@ public class XmppUri { if (segments.size() >= 2 && segments.get(1).contains("@")) { // sample : https://conversations.im/i/foo@bar.com try { - jid = Jid.fromString(segments.get(1)).toString(); + jid = Jid.of(segments.get(1)).toString(); } catch (Exception e) { jid = null; } @@ -107,8 +106,8 @@ public class XmppUri { } } else { try { - jid = Jid.fromString(uri.toString()).toBareJid().toString(); - } catch (final InvalidJidException ignored) { + jid = Jid.of(uri.toString()).asBareJid().toString(); + } catch (final IllegalArgumentException ignored) { jid = null; } } @@ -183,17 +182,17 @@ public class XmppUri { public Jid getJid() { try { - return this.jid == null ? null : Jid.fromString(this.jid.toLowerCase()); - } catch (InvalidJidException e) { + return this.jid == null ? null : Jid.of(this.jid.toLowerCase()); + } catch (IllegalArgumentException e) { return null; } } public boolean isJidValid() { try { - Jid.fromString(jid); + Jid.of(jid); return true; - } catch (InvalidJidException e) { + } catch (IllegalArgumentException e) { return false; } } diff --git a/src/main/java/de/pixart/messenger/xml/Element.java b/src/main/java/de/pixart/messenger/xml/Element.java index 13f5125ed..5ceb19c66 100644 --- a/src/main/java/de/pixart/messenger/xml/Element.java +++ b/src/main/java/de/pixart/messenger/xml/Element.java @@ -11,8 +11,7 @@ import java.util.Locale; import de.pixart.messenger.Config; import de.pixart.messenger.utils.XmlHelper; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Element { private final String name; @@ -152,8 +151,8 @@ public class Element { final String jid = this.getAttribute(name); if (jid != null && !jid.isEmpty()) { try { - return Jid.fromString(jid); - } catch (final InvalidJidException e) { + return Jid.of(jid); + } catch (final IllegalArgumentException e) { Log.e(Config.LOGTAG, "could not parse jid " + jid); return null; } diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 154627afe..9d8dd48ee 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -84,8 +84,6 @@ import de.pixart.messenger.xml.TagWriter; import de.pixart.messenger.xml.XmlReader; import de.pixart.messenger.xmpp.forms.Data; import de.pixart.messenger.xmpp.forms.Field; -import de.pixart.messenger.xmpp.jid.InvalidJidException; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.jingle.OnJinglePacketReceived; import de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket; import de.pixart.messenger.xmpp.stanzas.AbstractAcknowledgeableStanza; @@ -99,6 +97,7 @@ import de.pixart.messenger.xmpp.stanzas.streammgmt.AckPacket; import de.pixart.messenger.xmpp.stanzas.streammgmt.EnablePacket; import de.pixart.messenger.xmpp.stanzas.streammgmt.RequestPacket; import de.pixart.messenger.xmpp.stanzas.streammgmt.ResumePacket; +import rocks.xmpp.addr.Jid; public class XmppConnection implements Runnable { @@ -184,7 +183,7 @@ public class XmppConnection implements Runnable { public XmppConnection(final Account account, final XmppConnectionService service) { this.account = account; - final String tag = account.getJid().toBareJid().toPreppedString(); + final String tag = account.getJid().asBareJid().toString(); mXmppConnectionService = service; } @@ -192,7 +191,7 @@ public class XmppConnection implements Runnable { synchronized (this) { this.mThread = Thread.currentThread(); if (this.mThread.isInterrupted()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": not changing status to " + nextStatus + " because thread was interrupted"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": not changing status to " + nextStatus + " because thread was interrupted"); return; } if (account.getStatus() != nextStatus) { @@ -235,7 +234,7 @@ public class XmppConnection implements Runnable { if (mXmppConnectionService.areMessagesInitialized()) { mXmppConnectionService.resetSendingToWaiting(account); } - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting"); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": connecting"); features.encryptionEnabled = false; inSmacksSession = false; isBound = false; @@ -252,7 +251,7 @@ public class XmppConnection implements Runnable { Integer Port = XMPP_Port[new Random().nextInt(XMPP_Port.length)]; localSocket = new Socket(); try { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": connect to " + Config.XMPP_IP + ":" + Port); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": connect to " + Config.XMPP_IP + ":" + Port); localSocket.connect(new InetSocketAddress(Config.XMPP_IP, Port), Config.SOCKET_TIMEOUT * 1000); } catch (IOException e) { throw new UnknownHostException(); @@ -260,7 +259,7 @@ public class XmppConnection implements Runnable { try { startXmpp(localSocket); } catch (InterruptedException e) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": thread was interrupted before beginning stream"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": thread was interrupted before beginning stream"); return; } catch (Exception e) { throw new IOException(e.getMessage()); @@ -273,12 +272,12 @@ public class XmppConnection implements Runnable { destination = account.getHostname(); this.verifiedHostname = destination; } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": connect to " + destination + " via Tor"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": connect to " + destination + " via Tor"); localSocket = SocksSocketFactory.createSocketOverTor(destination, account.getPort()); try { startXmpp(localSocket); } catch (InterruptedException e) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": thread was interrupted before beginning stream"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": thread was interrupted before beginning stream"); return; } catch (Exception e) { throw new IOException(e.getMessage()); @@ -296,9 +295,9 @@ public class XmppConnection implements Runnable { localSocket = tlsFactoryVerifier.factory.createSocket(); localSocket.connect(address, Config.SOCKET_TIMEOUT * 1000); final SSLSession session = ((SSLSocket) localSocket).getSession(); - final String domain = account.getJid().getDomainpart(); + final String domain = account.getJid().getDomain(); if (!tlsFactoryVerifier.verifier.verify(domain, this.verifiedHostname, session)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS certificate verification failed"); throw new StateChangingException(Account.State.TLS_ERROR); } } catch (KeyManagementException e) { @@ -314,7 +313,7 @@ public class XmppConnection implements Runnable { try { startXmpp(localSocket); } catch (InterruptedException e) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": thread was interrupted before beginning stream"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": thread was interrupted before beginning stream"); return; } catch (Exception e) { throw new IOException(e.getMessage()); @@ -329,20 +328,20 @@ public class XmppConnection implements Runnable { try { startXmpp(localSocket); } catch (InterruptedException e) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": thread was interrupted before beginning stream"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": thread was interrupted before beginning stream"); return; } catch (Exception e) { throw new IOException(e.getMessage()); } } else { - final String domain = account.getJid().getDomainpart(); - List<Resolver.Result> results = Resolver.resolve(account.getJid().getDomainpart()); + final String domain = account.getJid().getDomain(); + List<Resolver.Result> results = Resolver.resolve(account.getJid().getDomain()); Resolver.Result storedBackupResult; if (!Thread.currentThread().isInterrupted()) { storedBackupResult = mXmppConnectionService.databaseBackend.findResolverResult(domain); if (storedBackupResult != null && !results.contains(storedBackupResult)) { results.add(storedBackupResult); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": loaded backup resolver result from db: " + storedBackupResult); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": loaded backup resolver result from db: " + storedBackupResult); } } else { storedBackupResult = null; @@ -350,7 +349,7 @@ public class XmppConnection implements Runnable { for (Iterator<Resolver.Result> iterator = results.iterator(); iterator.hasNext(); ) { final Resolver.Result result = iterator.next(); if (Thread.currentThread().isInterrupted()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": Thread was interrupted"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": Thread was interrupted"); return; } try { @@ -360,12 +359,12 @@ public class XmppConnection implements Runnable { final InetSocketAddress addr; if (result.getIp() != null) { addr = new InetSocketAddress(result.getIp(), result.getPort()); - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": using values from dns " + result.getHostname().toString() + "/" + result.getIp().getHostAddress() + ":" + result.getPort() + " tls: " + features.encryptionEnabled); } else { addr = new InetSocketAddress(IDN.toASCII(result.getHostname().toString()), result.getPort()); - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": using values from dns " + result.getHostname().toString() + ":" + result.getPort() + " tls: " + features.encryptionEnabled); } @@ -382,13 +381,13 @@ public class XmppConnection implements Runnable { } SSLSocketHelper.setSecurity((SSLSocket) localSocket); - SSLSocketHelper.setSNIHost(tlsFactoryVerifier.factory, (SSLSocket) localSocket, account.getServer().getDomainpart()); + SSLSocketHelper.setSNIHost(tlsFactoryVerifier.factory, (SSLSocket) localSocket, account.getServer().getDomain()); SSLSocketHelper.setAlpnProtocol(tlsFactoryVerifier.factory, (SSLSocket) localSocket, "xmpp-client"); localSocket.connect(addr, Config.SOCKET_TIMEOUT * 1000); - if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomainpart(), verifiedHostname, ((SSLSocket) localSocket).getSession())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed"); + if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomain(), 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); } @@ -406,10 +405,10 @@ public class XmppConnection implements Runnable { } catch (final StateChangingException e) { throw e; } catch (InterruptedException e) { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": thread was interrupted before beginning stream"); + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": thread was interrupted before beginning stream"); return; } catch (final Throwable e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage() + "(" + e.getClass().getName() + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": " + e.getMessage() + "(" + e.getClass().getName() + ")"); if (!iterator.hasNext()) { throw new UnknownHostException(); } @@ -428,14 +427,14 @@ public class XmppConnection implements Runnable { } catch (final SocksSocketFactory.SocksProxyNotFoundException e) { this.changeStatus(Account.State.TOR_NOT_AVAILABLE); } catch (final IOException | XmlPullParserException | NoSuchAlgorithmException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": " + e.getMessage()); this.changeStatus(Account.State.OFFLINE); this.attempt = Math.max(0, this.attempt - 1); } finally { if (!Thread.currentThread().isInterrupted()) { forceCloseSocket(); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": not force closing socket because thread was interrupted"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": not force closing socket because thread was interrupted"); } } } @@ -472,7 +471,7 @@ public class XmppConnection implements Runnable { } else { keyManager = null; } - String domain = account.getJid().getDomainpart(); + String domain = account.getJid().getDomain(); sc.init(keyManager, new X509TrustManager[]{mInteractive ? trustManager.getInteractive(domain) : trustManager.getNonInteractive(domain)}, mXmppConnectionService.getRNG()); final SSLSocketFactory factory = sc.getSocketFactory(); final DomainHostnameVerifier verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier(), mInteractive); @@ -483,7 +482,7 @@ public class XmppConnection implements Runnable { public void run() { synchronized (this) { if (Thread.currentThread().isInterrupted()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": aborting connect because thread was interrupted"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": aborting connect because thread was interrupted"); return; } forceCloseSocket(); @@ -510,7 +509,7 @@ public class XmppConnection implements Runnable { Log.e(Config.LOGTAG, String.valueOf(e)); throw new StateChangingException(Account.State.UNAUTHORIZED); } - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": logged in"); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": logged in"); account.setKey(Account.PINNED_MECHANISM_KEY, String.valueOf(saslMechanism.getPriority())); tagReader.reset(); @@ -560,11 +559,11 @@ public class XmppConnection implements Runnable { final Element enabled = tagReader.readElement(nextTag); if ("true".equals(enabled.getAttribute("resume"))) { this.streamId = enabled.getAttribute("id"); - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": stream management(" + smVersion + ") enabled (resumable)"); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": stream management(" + smVersion + ") enabled"); } this.stanzasReceived = 0; @@ -583,11 +582,11 @@ public class XmppConnection implements Runnable { synchronized (this.mStanzaQueue) { final int serverCount = Integer.parseInt(h); if (serverCount < stanzasSent) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": session resumed with lost packages"); stanzasSent = serverCount; } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": session resumed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": session resumed"); } acknowledgeStanzaUpTo(serverCount); for (int i = 0; i < this.mStanzaQueue.size(); ++i) { @@ -600,7 +599,7 @@ public class XmppConnection implements Runnable { if (packet instanceof MessagePacket) { MessagePacket message = (MessagePacket) packet; mXmppConnectionService.markMessage(account, - message.getTo().toBareJid(), + message.getTo().asBareJid(), message.getId(), Message.STATUS_UNSEND); } @@ -608,12 +607,12 @@ public class XmppConnection implements Runnable { } } catch (final NumberFormatException ignored) { } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": online with resource " + account.getResource()); changeStatus(Account.State.ONLINE); } else if (nextTag.isStart("r")) { tagReader.readElement(nextTag); if (Config.EXTENDED_SM_LOGGING) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": acknowledging stanza #" + this.stanzasReceived); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": acknowledging stanza #" + this.stanzasReceived); } final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); tagWriter.writeStanzaAsync(ack); @@ -622,7 +621,7 @@ public class XmppConnection implements Runnable { synchronized (NotificationService.CATCHUP_LOCK) { if (mWaitingForSmCatchup.compareAndSet(true, false)) { int count = mSmCatchupMessageCounter.get(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": SM catchup complete (" + count + ")"); accountUiNeedsRefresh = true; if (count > 0) { mXmppConnectionService.getNotificationService().finishBacklog(true, account); @@ -640,18 +639,18 @@ public class XmppConnection implements Runnable { acknowledgeStanzaUpTo(serverSequence); } } catch (NumberFormatException | NullPointerException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server send ack without sequence number"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server send ack without sequence number"); } } else if (nextTag.isStart("failed")) { Element failed = tagReader.readElement(nextTag); try { final int serverCount = Integer.parseInt(failed.getAttribute("h")); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": resumption failed but server acknowledged stanza #" + serverCount); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resumption failed but server acknowledged stanza #" + serverCount); synchronized (this.mStanzaQueue) { acknowledgeStanzaUpTo(serverCount); } } catch (NumberFormatException | NullPointerException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": resumption failed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resumption failed"); } resetStreamId(); sendBindRequest(); @@ -676,7 +675,7 @@ public class XmppConnection implements Runnable { for (int i = 0; i < mStanzaQueue.size(); ++i) { if (serverCount >= mStanzaQueue.keyAt(i)) { if (Config.EXTENDED_SM_LOGGING) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server acknowledged stanza #" + mStanzaQueue.keyAt(i)); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server acknowledged stanza #" + mStanzaQueue.keyAt(i)); } AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i); if (stanza instanceof MessagePacket && acknowledgedListener != null) { @@ -735,7 +734,7 @@ public class XmppConnection implements Runnable { if (inSmacksSession) { ++stanzasReceived; } else if (features.sm()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": not counting stanza(" + element.getClass().getSimpleName() + "). Not in smacks session."); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": not counting stanza(" + element.getClass().getSimpleName() + "). Not in smacks session."); } lastPacketReceived = SystemClock.elapsedRealtime(); if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) { @@ -766,14 +765,14 @@ public class XmppConnection implements Runnable { callback = packetCallbackDuple.second; packetCallbacks.remove(packet.getId()); } else { - Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet"); + Log.e(Config.LOGTAG, account.getJid().asBareJid().toString() + ": ignoring spoofed iq packet"); } } else { if (packet.getFrom() != null && packet.getFrom().equals(packetCallbackDuple.first.getTo())) { callback = packetCallbackDuple.second; packetCallbacks.remove(packet.getId()); } else { - Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet"); + Log.e(Config.LOGTAG, account.getJid().asBareJid().toString() + ": ignoring spoofed iq packet"); } } } else if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) { @@ -824,14 +823,14 @@ public class XmppConnection implements Runnable { SSLSocketHelper.setSecurity(sslSocket); - if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomainpart(), this.verifiedHostname, sslSocket.getSession())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed"); + if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomain(), this.verifiedHostname, sslSocket.getSession())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS certificate verification failed"); throw new StateChangingException(Account.State.TLS_ERROR); } tagReader.setInputStream(sslSocket.getInputStream()); tagWriter.setOutputStream(sslSocket.getOutputStream()); sendStartStream(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS connection established"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS connection established"); features.encryptionEnabled = true; final Tag tag = tagReader.readTag(); if (tag != null && tag.isStart("stream")) { @@ -841,7 +840,7 @@ public class XmppConnection implements Runnable { } sslSocket.close(); } catch (final NoSuchAlgorithmException | KeyManagementException e1) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": TLS certificate verification failed"); throw new StateChangingException(Account.State.TLS_ERROR); } } @@ -864,7 +863,7 @@ public class XmppConnection implements Runnable { authenticate(); } else if (this.streamFeatures.hasChild("sm", "urn:xmpp:sm:" + smVersion) && streamId != null) { if (Config.EXTENDED_SM_LOGGING) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": resuming after stanza #" + stanzasReceived); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resuming after stanza #" + stanzasReceived); } final ResumePacket resume = new ResumePacket(this.streamId, stanzasReceived, smVersion); this.mSmCatchupMessageCounter.set(0); @@ -889,7 +888,7 @@ public class XmppConnection implements Runnable { saslMechanism = new ScramSha256(tagWriter, account, mXmppConnectionService.getRNG()); } else if (mechanisms.contains("SCRAM-SHA-1")) { saslMechanism = new ScramSha1(tagWriter, account, mXmppConnectionService.getRNG()); - } else if (mechanisms.contains("PLAIN") && !account.getJid().getDomainpart().equals("nimbuzz.com")) { + } else if (mechanisms.contains("PLAIN") && !account.getJid().getDomain().equals("nimbuzz.com")) { saslMechanism = new Plain(tagWriter, account); } else if (mechanisms.contains("DIGEST-MD5")) { saslMechanism = new DigestMd5(tagWriter, account, mXmppConnectionService.getRNG()); @@ -946,7 +945,7 @@ public class XmppConnection implements Runnable { final Element password = new Element("password").setContent(account.getPassword()); register.query("jabber:iq:register").addChild(username); register.query().addChild(password); - register.setFrom(account.getJid().toBareJid()); + 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)); @@ -1035,7 +1034,7 @@ public class XmppConnection implements Runnable { try { mXmppConnectionService.restoredFromDatabaseLatch.await(); } catch (InterruptedException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": interrupted while waiting for DB restore during bind"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": interrupted while waiting for DB restore during bind"); return; } clearIqCallbacks(); @@ -1055,13 +1054,13 @@ public class XmppConnection implements Runnable { final Element jid = bind.findChild("jid"); if (jid != null && jid.getContent() != null) { try { - Jid assignedJid = Jid.fromString(jid.getContent()); - if (!account.getJid().getDomainpart().equals(assignedJid.getDomainpart())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server tried to re-assign domain to " + assignedJid.getDomainpart()); + Jid assignedJid = Jid.of(jid.getContent()); + if (!account.getJid().getDomain().equals(assignedJid.getDomain())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server tried to re-assign domain to " + assignedJid.getDomain()); throw new StateChangingError(Account.State.BIND_FAILURE); } if (account.setJid(assignedJid)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": jid changed during bind. updating database"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": jid changed during bind. updating database"); mXmppConnectionService.databaseBackend.updateAccount(account); } if (streamFeatures.hasChild("session") @@ -1071,8 +1070,8 @@ public class XmppConnection implements Runnable { sendPostBindInitialization(); } return; - } catch (final InvalidJidException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server reported invalid jid (" + jid.getContent() + ") on bind"); + } catch (final IllegalArgumentException e) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server reported invalid jid (" + jid.getContent() + ") on bind"); } } else { Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure. (no jid)"); @@ -1095,7 +1094,7 @@ public class XmppConnection implements Runnable { if (this.packetCallbacks.size() == 0) { return; } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing " + this.packetCallbacks.size() + " iq callbacks"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": clearing " + this.packetCallbacks.size() + " iq callbacks"); final Iterator<Pair<IqPacket, OnIqPacketReceived>> iterator = this.packetCallbacks.values().iterator(); while (iterator.hasNext()) { Pair<IqPacket, OnIqPacketReceived> entry = iterator.next(); @@ -1107,22 +1106,22 @@ public class XmppConnection implements Runnable { try { callback.onIqPacketReceived(account, failurePacket); } catch (StateChangingError error) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": caught StateChangingError(" + error.state.toString() + ") while clearing callbacks"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": caught StateChangingError(" + error.state.toString() + ") while clearing callbacks"); //ignore } } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": done clearing iq callbacks. " + this.packetCallbacks.size() + " left"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": done clearing iq callbacks. " + this.packetCallbacks.size() + " left"); } public void sendDiscoTimeout() { if (mWaitForDisco.compareAndSet(true, false)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": finalizing bind after disco timeout"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": finalizing bind after disco timeout"); finalizeBind(); } } private void sendStartSession() { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending legacy session to outdated server"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending legacy session to outdated server"); final IqPacket startSession = new IqPacket(IqPacket.TYPE.SET); startSession.addChild("session", "urn:ietf:params:xml:ns:xmpp-session"); this.sendUnmodifiedIqPacket(startSession, (account, packet) -> { @@ -1154,10 +1153,10 @@ public class XmppConnection implements Runnable { synchronized (this.disco) { this.disco.clear(); } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": starting service discovery"); mPendingServiceDiscoveries.set(0); - if (smVersion == 0 || Patches.DISCO_EXCEPTIONS.contains(account.getJid().getDomainpart())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": do not wait for service discovery"); + if (smVersion == 0 || Patches.DISCO_EXCEPTIONS.contains(account.getJid().getDomain())) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not wait for service discovery"); mWaitForDisco.set(false); } else { mWaitForDisco.set(true); @@ -1178,10 +1177,10 @@ public class XmppConnection implements Runnable { if (discoveryResult == null) { sendServiceDiscoveryInfo(account.getServer()); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server caps came from cache"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache"); disco.put(account.getServer(), discoveryResult); } - sendServiceDiscoveryInfo(account.getJid().toBareJid()); + sendServiceDiscoveryInfo(account.getJid().asBareJid()); if (!requestDiscoItemsFirst) { sendServiceDiscoveryItems(account.getServer()); } @@ -1210,13 +1209,13 @@ public class XmppConnection implements Runnable { } disco.put(jid, result); advancedStreamFeaturesLoaded = disco.containsKey(account.getServer()) - && disco.containsKey(account.getJid().toBareJid()); + && disco.containsKey(account.getJid().asBareJid()); } - if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))) { + if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().asBareJid()))) { enableAdvancedStreamFeatures(); } } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco info for " + jid.toString()); + 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 @@ -1229,7 +1228,7 @@ public class XmppConnection implements Runnable { } private void finalizeBind() { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": online with resource " + account.getResource()); if (bindListener != null) { bindListener.onBind(account); } @@ -1241,7 +1240,7 @@ public class XmppConnection implements Runnable { sendEnableCarbons(); } if (getFeatures().blocking() && !features.blockListRequested) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": Requesting block list"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": Requesting block list"); this.sendIqPacket(getIqGenerator().generateGetBlockList(), mXmppConnectionService.getIqParser()); } for (final OnAdvancedStreamFeaturesLoaded listener : advancedStreamFeaturesLoadedListeners) { @@ -1252,7 +1251,7 @@ public class XmppConnection implements Runnable { private void sendServiceDiscoveryItems(final Jid server) { mPendingServiceDiscoveries.incrementAndGet(); final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); - iq.setTo(server.toDomainJid()); + iq.setTo(Jid.ofDomain(server.getDomain())); iq.query("http://jabber.org/protocol/disco#items"); this.sendIqPacket(iq, new OnIqPacketReceived() { @@ -1273,7 +1272,7 @@ public class XmppConnection implements Runnable { sendServiceDiscoveryInfo(jid); } } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco items of " + server); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco items of " + server); } if (packet.getType() != IqPacket.TYPE.TIMEOUT) { if (mPendingServiceDiscoveries.decrementAndGet() == 0 @@ -1293,11 +1292,11 @@ public class XmppConnection implements Runnable { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { if (!packet.hasChild("error")) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": successfully enabled carbons"); features.carbonsEnabled = true; } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": error enableing carbons " + packet.toString()); } } @@ -1311,14 +1310,14 @@ public class XmppConnection implements Runnable { } if (streamError.hasChild("conflict")) { account.setResource(createNewResource()); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": switching resource due to conflict (" + account.getResource() + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": switching resource due to conflict (" + account.getResource() + ")"); throw new IOException(); } else if (streamError.hasChild("host-unknown")) { throw new StateChangingException(Account.State.HOST_UNKNOWN); } else if (streamError.hasChild("policy-violation")) { throw new StateChangingException(Account.State.POLICY_VIOLATION); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": stream error " + streamError.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": stream error " + streamError.toString()); throw new StateChangingException(Account.State.STREAM_ERROR); } } @@ -1385,7 +1384,7 @@ public class XmppConnection implements Runnable { if (force || isBound) { tagWriter.writeStanzaAsync(packet); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " do not write stanza to unbound stream " + packet.toString()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " do not write stanza to unbound stream " + packet.toString()); } if (packet instanceof AbstractAcknowledgeableStanza) { AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet; @@ -1399,7 +1398,7 @@ public class XmppConnection implements Runnable { this.mStanzaQueue.append(stanzasSent, stanza); if (stanza instanceof MessagePacket && stanza.getId() != null && inSmacksSession) { if (Config.EXTENDED_SM_LOGGING) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": requesting ack for message stanza #" + stanzasSent); } tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion)); } @@ -1460,10 +1459,10 @@ public class XmppConnection implements Runnable { try { socket.close(); } catch (IOException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": io exception " + e.getMessage() + " during force close"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception " + e.getMessage() + " during force close"); } } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": socket was null during force close"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": socket was null during force close"); } } @@ -1475,7 +1474,7 @@ public class XmppConnection implements Runnable { public void disconnect(final boolean force) { interrupt(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting force=" + Boolean.valueOf(force)); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": disconnecting force=" + Boolean.valueOf(force)); if (force) { forceCloseSocket(); } else { @@ -1486,19 +1485,19 @@ public class XmppConnection implements Runnable { final CountDownLatch streamCountDownLatch = this.mStreamCountDownLatch; try { currentTagWriter.await(1, TimeUnit.SECONDS); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": closing stream"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": closing stream"); currentTagWriter.writeTag(Tag.end("stream:stream")); if (streamCountDownLatch != null) { if (streamCountDownLatch.await(1, TimeUnit.SECONDS)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": remote ended stream"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": remote ended stream"); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": remote has not closed socket. force closing"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": remote has not closed socket. force closing"); } } } catch (InterruptedException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": interrupted while gracefully closing stream"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": interrupted while gracefully closing stream"); } catch (final IOException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": io exception during disconnect (" + e.getMessage() + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception during disconnect (" + e.getMessage() + ")"); } finally { FileBackend.close(currentSocket); } @@ -1611,7 +1610,7 @@ public class XmppConnection implements Runnable { public Identity getServerIdentity() { synchronized (this.disco) { - ServiceDiscoveryResult result = disco.get(account.getJid().toDomainJid()); + ServiceDiscoveryResult result = disco.get(Jid.ofDomain(account.getJid().getDomain())); if (result == null) { return Identity.UNKNOWN; } @@ -1764,38 +1763,38 @@ public class XmppConnection implements Runnable { public boolean pep() { synchronized (XmppConnection.this.disco) { - ServiceDiscoveryResult info = disco.get(account.getJid().toBareJid()); + ServiceDiscoveryResult info = disco.get(account.getJid().asBareJid()); return info != null && info.hasIdentity("pubsub", "pep"); } } public boolean pepPersistent() { synchronized (XmppConnection.this.disco) { - ServiceDiscoveryResult info = disco.get(account.getJid().toBareJid()); + ServiceDiscoveryResult info = disco.get(account.getJid().asBareJid()); return info != null && info.getFeatures().contains("http://jabber.org/protocol/pubsub#persistent-items"); } } public boolean pepPublishOptions() { - return hasDiscoFeature(account.getJid().toBareJid(),Namespace.PUBSUB_PUBLISH_OPTIONS); + return hasDiscoFeature(account.getJid().asBareJid(),Namespace.PUBSUB_PUBLISH_OPTIONS); } public boolean pepOmemoWhitelisted() { - return hasDiscoFeature(account.getJid().toBareJid(), AxolotlService.PEP_OMEMO_WHITELISTED); + return hasDiscoFeature(account.getJid().asBareJid(), AxolotlService.PEP_OMEMO_WHITELISTED); } public boolean mam() { - return hasDiscoFeature(account.getJid().toBareJid(), Namespace.MAM) - || hasDiscoFeature(account.getJid().toBareJid(), Namespace.MAM_LEGACY); + return hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM) + || hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM_LEGACY); } public boolean mamLegacy() { - return !hasDiscoFeature(account.getJid().toBareJid(), Namespace.MAM) - && hasDiscoFeature(account.getJid().toBareJid(), Namespace.MAM_LEGACY); + return !hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM) + && hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM_LEGACY); } public boolean push() { - return hasDiscoFeature(account.getJid().toBareJid(), "urn:xmpp:push:0") + return hasDiscoFeature(account.getJid().asBareJid(), "urn:xmpp:push:0") || hasDiscoFeature(account.getServer(), "urn:xmpp:push:0"); } @@ -1818,7 +1817,7 @@ public class XmppConnection implements Runnable { if (filesize <= maxsize) { return true; } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": http upload is not available for files with size " + filesize + " (max is " + maxsize + ")"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": http upload is not available for files with size " + filesize + " (max is " + maxsize + ")"); return false; } } catch (Exception e) { @@ -1844,7 +1843,7 @@ public class XmppConnection implements Runnable { } public boolean stanzaIds() { - return hasDiscoFeature(account.getJid().toBareJid(), Namespace.STANZA_IDS); + return hasDiscoFeature(account.getJid().asBareJid(), Namespace.STANZA_IDS); } } } diff --git a/src/main/java/de/pixart/messenger/xmpp/jid/InvalidJidException.java b/src/main/java/de/pixart/messenger/xmpp/jid/InvalidJidException.java deleted file mode 100644 index fa1b396d4..000000000 --- a/src/main/java/de/pixart/messenger/xmpp/jid/InvalidJidException.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.pixart.messenger.xmpp.jid; - -public class InvalidJidException extends Exception { - - // This is probably not the "Java way", but the "Java way" means we'd have a ton of extra tiny, - // annoying classes floating around. I like this. - public final static String INVALID_LENGTH = "JID must be between 0 and 3071 characters"; - public final static String INVALID_PART_LENGTH = "JID part must be between 0 and 1023 characters"; - public final static String INVALID_CHARACTER = "JID contains an invalid character"; - public final static String STRINGPREP_FAIL = "The STRINGPREP operation has failed for the given JID"; - public final static String IS_NULL = "JID can not be NULL"; - - /** - * Constructs a new {@code Exception} that includes the current stack trace. - */ - public InvalidJidException() { - } - - /** - * Constructs a new {@code Exception} with the current stack trace and the - * specified detail message. - * - * @param detailMessage the detail message for this exception. - */ - public InvalidJidException(final String detailMessage) { - super(detailMessage); - } - - /** - * Constructs a new {@code Exception} with the current stack trace, the - * specified detail message and the specified cause. - * - * @param detailMessage the detail message for this exception. - * @param throwable the cause of this exception. - */ - public InvalidJidException(final String detailMessage, final Throwable throwable) { - super(detailMessage, throwable); - } - - /** - * Constructs a new {@code Exception} with the current stack trace and the - * specified cause. - * - * @param throwable the cause of this exception. - */ - public InvalidJidException(final Throwable throwable) { - super(throwable); - } -} diff --git a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java b/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java deleted file mode 100644 index af21019b8..000000000 --- a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java +++ /dev/null @@ -1,253 +0,0 @@ -package de.pixart.messenger.xmpp.jid; - -import android.util.LruCache; - -import net.java.otr4j.session.SessionID; - -import java.net.IDN; - -import de.pixart.messenger.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; - - private static final char[] JID_ESCAPING_CHARS = {' ','"','&','\'','/',':','<','>','@','\\'}; - - // It's much more efficient to store the full JID as well as the parts instead of figuring them - // all out every time (since some characters are displayed but aren't used for comparisons). - private final String displayjid; - - public String getLocalpart() { - return localpart; - } - - public String getUnescapedLocalpart() { - if (localpart == null || !localpart.contains("\\")) { - return localpart; - } else { - String localpart = this.localpart; - for(char c : JID_ESCAPING_CHARS) { - localpart = localpart.replace(String.format ("\\%02x", (int)c),String.valueOf(c)); - } - return localpart; - } - } - - public String getDomainpart() { - return IDN.toUnicode(domainpart); - } - - public String getResourcepart() { - 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; - } - - public Jid toBareJid() { - try { - return resourcepart.isEmpty() ? this : fromParts(localpart, domainpart, ""); - } catch (final InvalidJidException e) { - // This should never happen. - throw new AssertionError("Jid " + this.toString() + " invalid"); - } - } - - public Jid toDomainJid() { - try { - return resourcepart.isEmpty() && localpart.isEmpty() ? this : fromString(getDomainpart()); - } catch (final InvalidJidException e) { - // This should never happen. - throw new AssertionError("Jid " + this.toString() + " invalid"); - } - } - - @Override - public String toString() { - return displayjid; - } - - public String toPreppedString() { - String out; - if (hasLocalpart()) { - out = localpart + '@' + domainpart; - } else { - out = domainpart; - } - if (!resourcepart.isEmpty()) { - out += '/' + resourcepart; - } - return out; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final Jid jid = (Jid) o; - - return jid.hashCode() == this.hashCode(); - } - - @Override - public int hashCode() { - int result = localpart.hashCode(); - result = 31 * result + domainpart.hashCode(); - result = 31 * result + resourcepart.hashCode(); - return result; - } - - public boolean hasLocalpart() { - return !localpart.isEmpty(); - } - - public boolean isBareJid() { - return this.resourcepart.isEmpty(); - } - - public boolean isDomainJid() { - return !this.hasLocalpart(); - } -} diff --git a/src/main/java/de/pixart/messenger/xmpp/jid/OtrJidHelper.java b/src/main/java/de/pixart/messenger/xmpp/jid/OtrJidHelper.java new file mode 100644 index 000000000..4710b9532 --- /dev/null +++ b/src/main/java/de/pixart/messenger/xmpp/jid/OtrJidHelper.java @@ -0,0 +1,16 @@ +package de.pixart.messenger.xmpp.jid; + +import net.java.otr4j.session.SessionID; + +import rocks.xmpp.addr.Jid; + +public final class OtrJidHelper { + + public static Jid fromSessionID(final SessionID id) throws IllegalArgumentException { + if (id.getUserID().isEmpty()) { + return Jid.of(id.getAccountID()); + } else { + return Jid.of(id.getAccountID() + "/" + id.getUserID()); + } + } +} diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleCandidate.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleCandidate.java index 6f87db473..9f163d5d9 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleCandidate.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleCandidate.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class JingleCandidate { diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java index f655a4241..3b83857e7 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java @@ -37,11 +37,11 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnIqPacketReceived; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.jingle.stanzas.Content; import de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket; import de.pixart.messenger.xmpp.jingle.stanzas.Reason; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class JingleConnection implements Transferable { private final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US); @@ -108,7 +108,7 @@ public class JingleConnection implements Transferable { public void onFileTransmitted(DownloadableFile file) { if (responding()) { if (expectedHash.length > 0 && !Arrays.equals(expectedHash, file.getSha1Sum())) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": hashes did not match"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": hashes did not match"); } sendSuccess(); mXmppConnectionService.getFileBackend().updateFileParams(message); @@ -338,7 +338,7 @@ public class JingleConnection implements Transferable { private void upgradeNamespace() { Jid jid = this.message.getCounterpart(); - String resource = jid != null ? jid.getResourcepart() : null; + String resource = jid != null ? jid.getResource() : null; if (resource != null) { Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource); ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null; @@ -357,7 +357,7 @@ public class JingleConnection implements Transferable { this.mJingleStatus = JINGLE_STATUS_INITIATED; Conversation conversation = this.mXmppConnectionService .findOrCreateConversation(account, - packet.getFrom().toBareJid(), false, true); + packet.getFrom().asBareJid(), false, true); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message.setStatus(Message.STATUS_RECEIVED); this.mStatus = Transferable.STATUS_OFFER; @@ -386,7 +386,7 @@ public class JingleConnection implements Transferable { if (fileOffer != null) { Element encrypted = fileOffer.findChild("encrypted", AxolotlService.PEP_PREFIX); if (encrypted != null) { - this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().toBareJid()); + this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().asBareJid()); } Element fileSize = fileOffer.findChild("size"); Element fileNameElement = fileOffer.findChild("name"); @@ -495,7 +495,7 @@ public class JingleConnection implements Transferable { if (message.getEncryption() == Message.ENCRYPTION_OTR) { Conversation conversation = this.message.getConversation(); if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not set symmetric key"); cancel(); } this.file.setKeyAndIv(conversation.getSymmetricKey()); @@ -527,7 +527,7 @@ public class JingleConnection implements Transferable { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": other party received offer"); if (mJingleStatus == JINGLE_STATUS_OFFERED) { mJingleStatus = JINGLE_STATUS_INITIATED; mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); @@ -709,7 +709,7 @@ public class JingleConnection implements Transferable { if (connection.getCandidate().isOurs()) { final String sid; if (ftVersion == Content.Version.FT_3) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": use session ID instead of transport ID to activate proxy"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": use session ID instead of transport ID to activate proxy"); sid = getSessionId(); } else { sid = getTransportId(); @@ -805,7 +805,7 @@ public class JingleConnection implements Transferable { } private void sendFallbackToIbb() { - Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": sending fallback to ibb"); + Log.d(Config.LOGTAG, account.getJid().asBareJid()+ ": sending fallback to ibb"); JinglePacket packet = this.bootstrapPacket("transport-replace"); Content content = new Content(this.contentCreator, this.contentName); this.transportId = this.mJingleConnectionManager.nextRandomId(); @@ -850,7 +850,7 @@ public class JingleConnection implements Transferable { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " recipient ACKed our transport-accept. creating ibb"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " recipient ACKed our transport-accept. creating ibb"); transport.connect(onIbbTransportConnected); } } @@ -896,7 +896,7 @@ public class JingleConnection implements Transferable { this.message.setTransferable(null); this.mJingleConnectionManager.finishConnection(this); } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": received session-terminate/success while responding"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received session-terminate/success while responding"); } } diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java index 8c1cee0fd..de0ce1ea0 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java @@ -18,9 +18,9 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnIqPacketReceived; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class JingleConnectionManager extends AbstractConnectionManager { private List<JingleConnection> connections = new CopyOnWriteArrayList<>(); @@ -87,7 +87,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { listener.onPrimaryCandidateFound(false, null); return; } - if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) { + if (!this.primaryCandidates.containsKey(account.getJid().asBareJid())) { final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS); if (proxy != null) { IqPacket iq = new IqPacket(IqPacket.TYPE.GET); @@ -108,7 +108,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { candidate.setType(JingleCandidate.TYPE_PROXY); candidate.setJid(proxy); candidate.setPriority(655360 + 65535); - primaryCandidates.put(account.getJid().toBareJid(), candidate); + primaryCandidates.put(account.getJid().asBareJid(), candidate); listener.onPrimaryCandidateFound(true, candidate); } catch (final NumberFormatException e) { listener.onPrimaryCandidateFound(false, null); @@ -125,7 +125,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { } else { listener.onPrimaryCandidateFound(true, - this.primaryCandidates.get(account.getJid().toBareJid())); + this.primaryCandidates.get(account.getJid().asBareJid())); } } diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleInbandTransport.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleInbandTransport.java index 61a87c2b9..151e9409f 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleInbandTransport.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleInbandTransport.java @@ -16,8 +16,8 @@ import de.pixart.messenger.entities.DownloadableFile; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnIqPacketReceived; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class JingleInbandTransport extends JingleTransport { @@ -102,13 +102,13 @@ public class JingleInbandTransport extends JingleTransport { digest.reset(); this.fileOutputStream = connection.getFileOutputStream(); if (this.fileOutputStream == null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not create output stream"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not create output stream"); callback.onFileTransferAborted(); return; } this.remainingSize = this.fileSize = file.getExpectedSize(); } catch (final NoSuchAlgorithmException | IOException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + " " + e.getMessage()); callback.onFileTransferAborted(); } } @@ -125,7 +125,7 @@ public class JingleInbandTransport extends JingleTransport { this.digest.reset(); fileInputStream = connection.getFileInputStream(); if (fileInputStream == null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could no create input stream"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could no create input stream"); callback.onFileTransferAborted(); return; } @@ -134,7 +134,7 @@ public class JingleInbandTransport extends JingleTransport { } } catch (NoSuchAlgorithmException e) { callback.onFileTransferAborted(); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage()); } } @@ -195,7 +195,7 @@ public class JingleInbandTransport extends JingleTransport { fileInputStream.close(); } } catch (IOException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": io exception during sendNextBlock() " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception during sendNextBlock() " + e.getMessage()); FileBackend.close(fileInputStream); this.onFileTransmissionStatusChanged.onFileTransferAborted(); } @@ -219,7 +219,7 @@ public class JingleInbandTransport extends JingleTransport { connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); } } catch (Exception e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage()); FileBackend.close(fileOutputStream); this.onFileTransmissionStatusChanged.onFileTransferAborted(); } @@ -245,7 +245,7 @@ public class JingleInbandTransport extends JingleTransport { this.connected = false; this.account.getXmppConnection().sendIqPacket( packet.generateResponse(IqPacket.TYPE.RESULT), null); - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": received ibb close"); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received ibb close"); } else { Log.d(Config.LOGTAG, payload.toString()); // TODO some sort of exception diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java index 595f17e28..946849858 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java @@ -37,7 +37,7 @@ public class JingleSocks5Transport extends JingleTransport { MessageDigest mDigest = MessageDigest.getInstance("SHA-1"); StringBuilder destBuilder = new StringBuilder(); if (jingleConnection.getFtVersion() == Content.Version.FT_3) { - Log.d(Config.LOGTAG, this.connection.getAccount().getJid().toBareJid() + ": using session Id instead of transport Id for proxy destination"); + Log.d(Config.LOGTAG, this.connection.getAccount().getJid().asBareJid() + ": using session Id instead of transport Id for proxy destination"); destBuilder.append(jingleConnection.getSessionId()); } else { destBuilder.append(jingleConnection.getTransportId()); @@ -97,7 +97,7 @@ public class JingleSocks5Transport extends JingleTransport { digest.reset(); fileInputStream = connection.getFileInputStream(); if (fileInputStream == null) { - Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": could not create input stream"); + Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": could not create input stream"); callback.onFileTransferAborted(); return; } @@ -117,7 +117,7 @@ public class JingleSocks5Transport extends JingleTransport { callback.onFileTransmitted(file); } } catch (Exception e) { - Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": " + e.getMessage()); callback.onFileTransferAborted(); } finally { FileBackend.close(fileInputStream); @@ -144,7 +144,7 @@ public class JingleSocks5Transport extends JingleTransport { fileOutputStream = connection.getFileOutputStream(); if (fileOutputStream == null) { callback.onFileTransferAborted(); - Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": could not create output stream"); + Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": could not create output stream"); return; } double size = file.getExpectedSize(); @@ -155,7 +155,7 @@ public class JingleSocks5Transport extends JingleTransport { count = inputStream.read(buffer); if (count == -1) { callback.onFileTransferAborted(); - Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": file ended prematurely with " + remainingSize + " bytes remaining"); + Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": file ended prematurely with " + remainingSize + " bytes remaining"); return; } else { fileOutputStream.write(buffer, 0, count); @@ -169,7 +169,7 @@ public class JingleSocks5Transport extends JingleTransport { file.setSha1Sum(digest.digest()); callback.onFileTransmitted(file); } catch (Exception e) { - Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": " + e.getMessage()); callback.onFileTransferAborted(); } finally { wakeLock.release(); diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/stanzas/JinglePacket.java b/src/main/java/de/pixart/messenger/xmpp/jingle/stanzas/JinglePacket.java index 3f7cc8e5b..8d16a1c6e 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/stanzas/JinglePacket.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/stanzas/JinglePacket.java @@ -3,8 +3,8 @@ package de.pixart.messenger.xmpp.jingle.stanzas; import android.util.Base64; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; import de.pixart.messenger.xmpp.stanzas.IqPacket; +import rocks.xmpp.addr.Jid; public class JinglePacket extends IqPacket { Content content = null; diff --git a/src/main/java/de/pixart/messenger/xmpp/pep/Avatar.java b/src/main/java/de/pixart/messenger/xmpp/pep/Avatar.java index 05b41c610..2521d09bc 100644 --- a/src/main/java/de/pixart/messenger/xmpp/pep/Avatar.java +++ b/src/main/java/de/pixart/messenger/xmpp/pep/Avatar.java @@ -3,7 +3,7 @@ package de.pixart.messenger.xmpp.pep; import android.util.Base64; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class Avatar { diff --git a/src/main/java/de/pixart/messenger/xmpp/stanzas/AbstractStanza.java b/src/main/java/de/pixart/messenger/xmpp/stanzas/AbstractStanza.java index 8d1b24ef8..9e26439c2 100644 --- a/src/main/java/de/pixart/messenger/xmpp/stanzas/AbstractStanza.java +++ b/src/main/java/de/pixart/messenger/xmpp/stanzas/AbstractStanza.java @@ -2,7 +2,7 @@ package de.pixart.messenger.xmpp.stanzas; import de.pixart.messenger.entities.Account; import de.pixart.messenger.xml.Element; -import de.pixart.messenger.xmpp.jid.Jid; +import rocks.xmpp.addr.Jid; public class AbstractStanza extends Element { @@ -33,18 +33,18 @@ public class AbstractStanza extends Element { public boolean fromServer(final Account account) { return getFrom() == null || getFrom().equals(account.getServer()) - || getFrom().equals(account.getJid().toBareJid()) + || getFrom().equals(account.getJid().asBareJid()) || getFrom().equals(account.getJid()); } public boolean toServer(final Account account) { return getTo() == null || getTo().equals(account.getServer()) - || getTo().equals(account.getJid().toBareJid()) + || getTo().equals(account.getJid().asBareJid()) || getTo().equals(account.getJid()); } public boolean fromAccount(final Account account) { - return getFrom() != null && getFrom().toBareJid().equals(account.getJid().toBareJid()); + return getFrom() != null && getFrom().asBareJid().equals(account.getJid().asBareJid()); } } |