aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-11-06 14:10:03 -0500
committerSam Whited <sam@samwhited.com>2014-11-09 07:00:40 -0500
commitf15900426d4713b48eb96e0ad0b1cdda5a86becf (patch)
treeffed4d06be23ca25c416f5463aceb36e20a5e4c3 /src/main/java/eu/siacs/conversations/xmpp
parent9053f4aca0c232db77dbd0a1e5b9b09bf41bec22 (diff)
Update more files to use JID objects
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp')
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java4
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java31
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java25
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java18
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java13
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java5
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java23
7 files changed, 72 insertions, 47 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java
index 2bbde7ab..7a1e1f1b 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java
@@ -161,4 +161,8 @@ public final class Jid {
result = 31 * result + resourcepart.hashCode();
return result;
}
+
+ public boolean isBareJid() {
+ return this.resourcepart.isEmpty();
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
index 3e7c7b68..9a0306fc 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.Jid;
public class JingleCandidate {
@@ -17,7 +18,7 @@ public class JingleCandidate {
private String host;
private int port;
private int type;
- private String jid;
+ private Jid jid;
private int priority;
public JingleCandidate(String cid, boolean ours) {
@@ -37,11 +38,11 @@ public class JingleCandidate {
return this.host;
}
- public void setJid(String jid) {
+ public void setJid(final Jid jid) {
this.jid = jid;
}
- public String getJid() {
+ public Jid getJid() {
return this.jid;
}
@@ -58,13 +59,17 @@ public class JingleCandidate {
}
public void setType(String type) {
- if ("proxy".equals(type)) {
- this.type = TYPE_PROXY;
- } else if ("direct".equals(type)) {
- this.type = TYPE_DIRECT;
- } else {
- this.type = TYPE_UNKNOWN;
- }
+ switch (type) {
+ case "proxy":
+ this.type = TYPE_PROXY;
+ break;
+ case "direct":
+ this.type = TYPE_DIRECT;
+ break;
+ default:
+ this.type = TYPE_UNKNOWN;
+ break;
+ }
}
public void setPriority(int i) {
@@ -93,7 +98,7 @@ public class JingleCandidate {
}
public static List<JingleCandidate> parse(List<Element> canditates) {
- List<JingleCandidate> parsedCandidates = new ArrayList<JingleCandidate>();
+ List<JingleCandidate> parsedCandidates = new ArrayList<>();
for (Element c : canditates) {
parsedCandidates.add(JingleCandidate.parse(c));
}
@@ -104,7 +109,7 @@ public class JingleCandidate {
JingleCandidate parsedCandidate = new JingleCandidate(
candidate.getAttribute("cid"), false);
parsedCandidate.setHost(candidate.getAttribute("host"));
- parsedCandidate.setJid(candidate.getAttribute("jid"));
+ parsedCandidate.setJid(candidate.getJid());
parsedCandidate.setType(candidate.getAttribute("type"));
parsedCandidate.setPriority(Integer.parseInt(candidate
.getAttribute("priority")));
@@ -118,7 +123,7 @@ public class JingleCandidate {
element.setAttribute("cid", this.getCid());
element.setAttribute("host", this.getHost());
element.setAttribute("port", Integer.toString(this.getPort()));
- element.setAttribute("jid", this.getJid());
+ element.setAttribute("jid", this.getJid().toString());
element.setAttribute("priority", Integer.toString(this.getPriority()));
if (this.getType() == TYPE_DIRECT) {
element.setAttribute("type", "direct");
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index 6b9ca9aa..a863775d 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -21,6 +21,7 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
import eu.siacs.conversations.xmpp.jingle.stanzas.Reason;
@@ -49,10 +50,10 @@ public class JingleConnection implements Downloadable {
private Message message;
private String sessionId;
private Account account;
- private String initiator;
- private String responder;
- private List<JingleCandidate> candidates = new ArrayList<JingleCandidate>();
- private ConcurrentHashMap<String, JingleSocks5Transport> connections = new ConcurrentHashMap<String, JingleSocks5Transport>();
+ private Jid initiator;
+ private Jid responder;
+ private List<JingleCandidate> candidates = new ArrayList<>();
+ private ConcurrentHashMap<String, JingleSocks5Transport> connections = new ConcurrentHashMap<>();
private String transportId;
private Element fileOffer;
@@ -150,7 +151,7 @@ public class JingleConnection implements Downloadable {
return this.account;
}
- public String getCounterPart() {
+ public Jid getCounterPart() {
return this.message.getCounterpart();
}
@@ -254,14 +255,14 @@ public class JingleConnection implements Downloadable {
this.mJingleStatus = JINGLE_STATUS_INITIATED;
Conversation conversation = this.mXmppConnectionService
.findOrCreateConversation(account,
- packet.getFrom().split("/", 2)[0], false);
+ packet.getFrom().toBareJid(), false);
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
this.message.setStatus(Message.STATUS_RECEIVED);
this.message.setType(Message.TYPE_IMAGE);
this.mStatus = Downloadable.STATUS_OFFER;
this.message.setDownloadable(this);
- String[] fromParts = packet.getFrom().split("/", 2);
- this.message.setPresence(fromParts[1]);
+ final Jid from = packet.getFrom();
+ this.message.setPresence(from.isBareJid() ? "" : from.getResourcepart());
this.account = account;
this.initiator = packet.getFrom();
this.responder = this.account.getFullJid();
@@ -375,7 +376,7 @@ public class JingleConnection implements Downloadable {
}
private List<Element> getCandidatesAsElements() {
- List<Element> elements = new ArrayList<Element>();
+ List<Element> elements = new ArrayList<>();
for (JingleCandidate c : this.candidates) {
elements.add(c.toElement());
}
@@ -547,7 +548,7 @@ public class JingleConnection implements Downloadable {
activation.query("http://jabber.org/protocol/bytestreams")
.setAttribute("sid", this.getSessionId());
activation.query().addChild("activate")
- .setContent(this.getCounterPart());
+ .setContent(this.getCounterPart().toString());
this.account.getXmppConnection().sendIqPacket(activation,
new OnIqPacketReceived() {
@@ -810,11 +811,11 @@ public class JingleConnection implements Downloadable {
this.sendJinglePacket(packet);
}
- public String getInitiator() {
+ public Jid getInitiator() {
return this.initiator;
}
- public String getResponder() {
+ public Jid getResponder() {
return this.responder;
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
index d937146a..6684a4c6 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -14,13 +14,15 @@ import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleConnectionManager extends AbstractConnectionManager {
- private List<JingleConnection> connections = new CopyOnWriteArrayList<JingleConnection>();
+ private List<JingleConnection> connections = new CopyOnWriteArrayList<>();
- private HashMap<String, JingleCandidate> primaryCandidates = new HashMap<String, JingleCandidate>();
+ private HashMap<Jid, JingleCandidate> primaryCandidates = new HashMap<>();
@SuppressLint("TrulyRandom")
private SecureRandom random = new SecureRandom();
@@ -61,7 +63,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return connection;
}
- public JingleConnection createNewConnection(JinglePacket packet) {
+ public JingleConnection createNewConnection(final JinglePacket packet) {
JingleConnection connection = new JingleConnection(this);
this.connections.add(connection);
return connection;
@@ -79,7 +81,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
.findDiscoItemByFeature(xmlns);
if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
- iq.setTo(proxy);
+ iq.setAttribute("to", proxy);
iq.query(xmlns);
account.getXmppConnection().sendIqPacket(iq,
new OnIqPacketReceived() {
@@ -101,8 +103,12 @@ public class JingleConnectionManager extends AbstractConnectionManager {
.getAttribute("port")));
candidate
.setType(JingleCandidate.TYPE_PROXY);
- candidate.setJid(proxy);
- candidate.setPriority(655360 + 65535);
+ try {
+ candidate.setJid(Jid.fromString(proxy));
+ } catch (final InvalidJidException e) {
+ candidate.setJid(null);
+ }
+ candidate.setPriority(655360 + 65535);
primaryCandidates.put(account.getJid(),
candidate);
listener.onPrimaryCandidateFound(true,
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
index cc1e92f6..e3f4fd61 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
@@ -13,12 +13,13 @@ import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleInbandTransport extends JingleTransport {
private Account account;
- private String counterpart;
+ private Jid counterpart;
private int blockSize;
private int bufferSize;
private int seq = 0;
@@ -44,8 +45,8 @@ public class JingleInbandTransport extends JingleTransport {
}
};
- public JingleInbandTransport(Account account, String counterpart,
- String sid, int blocksize) {
+ public JingleInbandTransport(final Account account, final Jid counterpart,
+ final String sid, final int blocksize) {
this.account = account;
this.counterpart = counterpart;
this.blockSize = blocksize;
@@ -92,12 +93,10 @@ public class JingleInbandTransport extends JingleTransport {
return;
}
this.remainingSize = file.getExpectedSize();
- } catch (NoSuchAlgorithmException e) {
- callback.onFileTransferAborted();
- } catch (IOException e) {
+ } catch (final NoSuchAlgorithmException | IOException e) {
callback.onFileTransferAborted();
}
- }
+ }
@Override
public void send(DownloadableFile file,
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
index 77a73643..4f73a83a 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
@@ -1,6 +1,7 @@
package eu.siacs.conversations.xmpp.jingle.stanzas;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JinglePacket extends IqPacket {
@@ -85,8 +86,8 @@ public class JinglePacket extends IqPacket {
return this.jingle.getAttribute("action");
}
- public void setInitiator(String initiator) {
- this.jingle.setAttribute("initiator", initiator);
+ public void setInitiator(final Jid initiator) {
+ this.jingle.setAttribute("initiator", initiator.toString());
}
public boolean isAction(String action) {
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
index ea8f64a9..54028a45 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
@@ -1,6 +1,7 @@
package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class AbstractStanza extends Element {
@@ -9,13 +10,21 @@ public class AbstractStanza extends Element {
super(name);
}
- public String getTo() {
- return getAttribute("to");
- }
-
- public String getFrom() {
- return getAttribute("from");
- }
+ public Jid getTo() {
+ try {
+ return Jid.fromString(getAttribute("to"));
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
+
+ public Jid getFrom() {
+ try {
+ return Jid.fromString(getAttribute("from"));
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
public String getId() {
return this.getAttribute("id");