aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-02-20 22:19:31 +0100
committersteckbrief <steckbrief@chefmail.de>2015-02-20 22:19:31 +0100
commit20eae3955700341188bc1907a506970f5817a153 (patch)
tree6e50d9083a4392875b5f9dbe92b38973cf95c332 /src/main/java/eu/siacs/conversations/xmpp
parent980a84a6ce4358e8662addf203695e01d9f931dc (diff)
parentecbceae88b7a7aa871e5396efec1e2ff8d056d46 (diff)
Merge master-origin
Conflicts: src/main/java/eu/siacs/conversations/ui/SettingsActivity.java src/main/java/eu/siacs/conversations/ui/XmppActivity.java src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java src/main/java/eu/siacs/conversations/utils/UIHelper.java src/main/res/values-de/strings.xml
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp')
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java266
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java3
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java145
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java80
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java14
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java17
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java46
7 files changed, 266 insertions, 305 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index f7f0c346..19e271b2 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -9,6 +9,7 @@ import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
+import android.util.Pair;
import android.util.SparseArray;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
@@ -52,6 +53,7 @@ import eu.siacs.conversations.crypto.sasl.ScramSha1;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
@@ -94,17 +96,14 @@ public class XmppConnection implements Runnable {
private int smVersion = 3;
private final SparseArray<String> messageReceipts = new SparseArray<>();
- private boolean enabledEncryption = false;
- private boolean enabledCarbons = false;
-
private int stanzasReceived = 0;
private int stanzasSent = 0;
- private long lastPaketReceived = 0;
+ private long lastPacketReceived = 0;
private long lastPingSent = 0;
private long lastConnect = 0;
private long lastSessionStarted = 0;
private int attempt = 0;
- private final Map<String, PacketReceived> packetCallbacks = new Hashtable<>();
+ private final Map<String, Pair<IqPacket, OnIqPacketReceived>> packetCallbacks = new Hashtable<>();
private OnPresencePacketReceived presenceListener = null;
private OnJinglePacketReceived jingleListener = null;
private OnIqPacketReceived unregisteredIqListener = null;
@@ -146,13 +145,12 @@ public class XmppConnection implements Runnable {
protected void connect() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
- enabledEncryption = false;
+ features.encryptionEnabled = false;
lastConnect = SystemClock.elapsedRealtime();
lastPingSent = SystemClock.elapsedRealtime();
this.attempt++;
try {
- shouldAuthenticate = shouldBind = !account
- .isOptionSet(Account.OPTION_REGISTER);
+ shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
packetCallbacks.clear();
@@ -231,6 +229,7 @@ public class XmppConnection implements Runnable {
} catch (final IOException | XmlPullParserException | NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage());
this.changeStatus(Account.State.OFFLINE);
+ this.attempt--; //don't count attempt when reconnecting instantly anyway
} finally {
if (wakeLock.isHeld()) {
try {
@@ -303,7 +302,7 @@ public class XmppConnection implements Runnable {
final RequestPacket r = new RequestPacket(smVersion);
tagWriter.writeStanzaAsync(r);
} else if (nextTag.isStart("resumed")) {
- lastPaketReceived = SystemClock.elapsedRealtime();
+ lastPacketReceived = SystemClock.elapsedRealtime();
final Element resumed = tagReader.readElement(nextTag);
final String h = resumed.getAttribute("h");
try {
@@ -336,7 +335,7 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(ack);
} else if (nextTag.isStart("a")) {
final Element ack = tagReader.readElement(nextTag);
- lastPaketReceived = SystemClock.elapsedRealtime();
+ lastPacketReceived = SystemClock.elapsedRealtime();
final int serverSequence = Integer.parseInt(ack.getAttribute("h"));
final String msgId = this.messageReceipts.get(serverSequence);
if (msgId != null) {
@@ -372,7 +371,7 @@ public class XmppConnection implements Runnable {
private void sendInitialPing() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": sending intial ping");
- final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid());
iq.addChild("ping", "urn:xmpp:ping");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@@ -425,69 +424,54 @@ public class XmppConnection implements Runnable {
}
}
++stanzasReceived;
- lastPaketReceived = SystemClock.elapsedRealtime();
+ lastPacketReceived = SystemClock.elapsedRealtime();
return element;
}
- private void processIq(final Tag currentTag) throws XmlPullParserException,
- IOException {
- final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
-
- if (packet.getId() == null) {
- return; // an iq packet without id is definitely invalid
- }
+ private void processIq(final Tag currentTag) throws XmlPullParserException, IOException {
+ final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
- if (packet instanceof JinglePacket) {
- if (this.jingleListener != null) {
- this.jingleListener.onJinglePacketReceived(account,
- (JinglePacket) packet);
- }
- } else {
- if (packetCallbacks.containsKey(packet.getId())) {
- if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
- ((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
- .onIqPacketReceived(account, packet);
- }
+ if (packet.getId() == null) {
+ return; // an iq packet without id is definitely invalid
+ }
- packetCallbacks.remove(packet.getId());
- } else if ((packet.getType() == IqPacket.TYPE_GET || packet
- .getType() == IqPacket.TYPE_SET)
- && this.unregisteredIqListener != null) {
- this.unregisteredIqListener.onIqPacketReceived(account, packet);
- }
- }
+ if (packet instanceof JinglePacket) {
+ if (this.jingleListener != null) {
+ this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet);
+ }
+ } else {
+ if (packetCallbacks.containsKey(packet.getId())) {
+ final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
+ // Packets to the server should have responses from the server
+ if (packetCallbackDuple.first.toServer(account)) {
+ if (packet.fromServer(account)) {
+ packetCallbackDuple.second.onIqPacketReceived(account, packet);
+ packetCallbacks.remove(packet.getId());
+ } else {
+ Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
+ }
+ } else {
+ if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
+ packetCallbackDuple.second.onIqPacketReceived(account, packet);
+ packetCallbacks.remove(packet.getId());
+ } else {
+ Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
+ }
+ }
+ } else if (packet.getType() == IqPacket.TYPE.GET|| packet.getType() == IqPacket.TYPE.SET) {
+ this.unregisteredIqListener.onIqPacketReceived(account, packet);
+ }
+ }
}
- private void processMessage(final Tag currentTag) throws XmlPullParserException,
- IOException {
- final MessagePacket packet = (MessagePacket) processPacket(currentTag,
- PACKET_MESSAGE);
- final String id = packet.getAttribute("id");
- if ((id != null) && (packetCallbacks.containsKey(id))) {
- if (packetCallbacks.get(id) instanceof OnMessagePacketReceived) {
- ((OnMessagePacketReceived) packetCallbacks.get(id))
- .onMessagePacketReceived(account, packet);
- }
- packetCallbacks.remove(id);
- } else if (this.messageListener != null) {
- this.messageListener.onMessagePacketReceived(account, packet);
- }
+ private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
+ final MessagePacket packet = (MessagePacket) processPacket(currentTag,PACKET_MESSAGE);
+ this.messageListener.onMessagePacketReceived(account, packet);
}
- private void processPresence(final Tag currentTag) throws XmlPullParserException,
- IOException {
- PresencePacket packet = (PresencePacket) processPacket(currentTag,
- PACKET_PRESENCE);
- final String id = packet.getAttribute("id");
- if ((id != null) && (packetCallbacks.containsKey(id))) {
- if (packetCallbacks.get(id) instanceof OnPresencePacketReceived) {
- ((OnPresencePacketReceived) packetCallbacks.get(id))
- .onPresencePacketReceived(account, packet);
- }
- packetCallbacks.remove(id);
- } else if (this.presenceListener != null) {
- this.presenceListener.onPresencePacketReceived(account, packet);
- }
+ private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
+ PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
+ this.presenceListener.onPresencePacketReceived(account, packet);
}
private void sendStartTLS() throws IOException {
@@ -497,8 +481,7 @@ public class XmppConnection implements Runnable {
}
private SharedPreferences getPreferences() {
- return PreferenceManager
- .getDefaultSharedPreferences(applicationContext);
+ return PreferenceManager.getDefaultSharedPreferences(applicationContext);
}
private boolean enableLegacySSL() {
@@ -506,70 +489,72 @@ public class XmppConnection implements Runnable {
}
private void switchOverToTls(final Tag currentTag) throws XmlPullParserException, IOException {
- tagReader.readTag();
- try {
+ tagReader.readTag();
+ try {
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null,new X509TrustManager[]{this.mXmppConnectionService.getMemorizingTrustManager()},mXmppConnectionService.getRNG());
final SSLSocketFactory factory = sc.getSocketFactory();
final HostnameVerifier verifier = this.mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
- final InetAddress address = socket == null ? null : socket.getInetAddress();
+ final InetAddress address = socket == null ? null : socket.getInetAddress();
if (factory == null || address == null || verifier == null) {
throw new IOException("could not setup ssl");
}
- final SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,address.getHostAddress(), socket.getPort(),true);
+ final SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,address.getHostAddress(), socket.getPort(),true);
if (sslSocket == null) {
throw new IOException("could not initialize ssl socket");
}
final String[] supportProtocols;
- if (enableLegacySSL()) {
- supportProtocols = sslSocket.getSupportedProtocols();
- } else {
- final Collection<String> supportedProtocols = new LinkedList<>(
- Arrays.asList(sslSocket.getSupportedProtocols()));
- supportedProtocols.remove("SSLv3");
- supportProtocols = new String[supportedProtocols.size()];
- supportedProtocols.toArray(supportProtocols);
- }
+ final Collection<String> supportedProtocols = new LinkedList<>(
+ Arrays.asList(sslSocket.getSupportedProtocols()));
+ supportedProtocols.remove("SSLv3");
+ supportProtocols = supportedProtocols.toArray(new String[supportedProtocols.size()]);
+
sslSocket.setEnabledProtocols(supportProtocols);
- if (!verifier.verify(account.getServer().getDomainpart(),sslSocket.getSession())) {
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
- disconnect(true);
- changeStatus(Account.State.SECURITY_ERROR);
+ final String[] cipherSuites = CryptoHelper.getSupportedCipherSuites(
+ sslSocket.getSupportedCipherSuites());
+ if (cipherSuites.length > 0) {
+ sslSocket.setEnabledCipherSuites(cipherSuites);
+ }
+
+ if (!verifier.verify(account.getServer().getDomainpart(),sslSocket.getSession())) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
+ disconnect(true);
+ changeStatus(Account.State.SECURITY_ERROR);
}
tagReader.setInputStream(sslSocket.getInputStream());
tagWriter.setOutputStream(sslSocket.getOutputStream());
sendStartStream();
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": TLS connection established");
- enabledEncryption = true;
+ features.encryptionEnabled = true;
processStream(tagReader.readTag());
sslSocket.close();
- } catch (final NoSuchAlgorithmException | KeyManagementException e1) {
+ } catch (final NoSuchAlgorithmException | KeyManagementException e1) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
disconnect(true);
changeStatus(Account.State.SECURITY_ERROR);
- }
+ }
}
private void processStreamFeatures(final Tag currentTag)
throws XmlPullParserException, IOException {
this.streamFeatures = tagReader.readElement(currentTag);
- if (this.streamFeatures.hasChild("starttls") && !enabledEncryption) {
+ if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) {
sendStartTLS();
} else if (this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER)
- && enabledEncryption) {
+ && features.encryptionEnabled) {
sendRegistryRequest();
} else if (!this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER)) {
changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED);
disconnect(true);
} else if (this.streamFeatures.hasChild("mechanisms")
- && shouldAuthenticate && enabledEncryption) {
+ && shouldAuthenticate && features.encryptionEnabled) {
final List<String> mechanisms = extractMechanisms(streamFeatures
.findChild("mechanisms"));
final Element auth = new Element("auth");
@@ -625,7 +610,7 @@ public class XmppConnection implements Runnable {
}
private void sendRegistryRequest() {
- final IqPacket register = new IqPacket(IqPacket.TYPE_GET);
+ final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
register.query("jabber:iq:register");
register.setTo(account.getServer());
sendIqPacket(register, new OnIqPacketReceived() {
@@ -635,7 +620,7 @@ public class XmppConnection implements Runnable {
final Element instructions = packet.query().findChild("instructions");
if (packet.query().hasChild("username")
&& (packet.query().hasChild("password"))) {
- final IqPacket register = new IqPacket(IqPacket.TYPE_SET);
+ final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
final Element username = new Element("username")
.setContent(account.getUsername());
final Element password = new Element("password")
@@ -646,7 +631,7 @@ public class XmppConnection implements Runnable {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE_RESULT) {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
account.setOption(Account.OPTION_REGISTER,
false);
changeStatus(Account.State.REGISTRATION_SUCCESSFUL);
@@ -673,10 +658,10 @@ public class XmppConnection implements Runnable {
}
private void sendBindRequest() {
- final IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind")
.addChild("resource").setContent(account.getResource());
- this.sendUnboundIqPacket(iq, new OnIqPacketReceived() {
+ this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
final Element bind = packet.findChild("bind");
@@ -694,15 +679,15 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(enable);
stanzasSent = 0;
messageReceipts.clear();
- } else if (streamFeatures.hasChild("sm",
- "urn:xmpp:sm:2")) {
+ } else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) {
smVersion = 2;
final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable);
stanzasSent = 0;
messageReceipts.clear();
}
- enabledCarbons = false;
+ features.carbonsEnabled = false;
+ features.blockListRequested = false;
disco.clear();
sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryItems(account.getServer());
@@ -719,12 +704,10 @@ public class XmppConnection implements Runnable {
}
});
if (this.streamFeatures.hasChild("session")) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + ": sending deprecated session");
- final IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
- startSession.addChild("session",
- "urn:ietf:params:xml:ns:xmpp-session");
- this.sendUnboundIqPacket(startSession, null);
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending deprecated session");
+ final IqPacket startSession = new IqPacket(IqPacket.TYPE.SET);
+ startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
+ this.sendUnmodifiedIqPacket(startSession, null);
}
}
@@ -734,7 +717,7 @@ public class XmppConnection implements Runnable {
enableAdvancedStreamFeatures();
}
} else {
- final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(server.toDomainJid());
iq.query("http://jabber.org/protocol/disco#info");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@@ -767,19 +750,17 @@ public class XmppConnection implements Runnable {
}
private void enableAdvancedStreamFeatures() {
- if (getFeatures().carbons()) {
- if (!enabledCarbons) {
- sendEnableCarbons();
- }
+ if (getFeatures().carbons() && !features.carbonsEnabled) {
+ sendEnableCarbons();
}
- if (getFeatures().blocking()) {
+ if (getFeatures().blocking() && !features.blockListRequested) {
Log.d(Config.LOGTAG, "Requesting block list");
this.sendIqPacket(getIqGenerator().generateGetBlockList(), mXmppConnectionService.getIqParser());
}
}
private void sendServiceDiscoveryItems(final Jid server) {
- final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(server.toDomainJid());
iq.query("http://jabber.org/protocol/disco#items");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@@ -800,7 +781,7 @@ public class XmppConnection implements Runnable {
}
private void sendEnableCarbons() {
- final IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.addChild("enable", "urn:xmpp:carbons:2");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@@ -809,7 +790,7 @@ public class XmppConnection implements Runnable {
if (!packet.hasChild("error")) {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": successfully enabled carbons");
- enabledCarbons = true;
+ features.carbonsEnabled = true;
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": error enableing carbons " + packet.toString());
@@ -845,49 +826,44 @@ public class XmppConnection implements Runnable {
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
}
- public void sendIqPacket(final IqPacket packet, final PacketReceived callback) {
- if (packet.getId() == null) {
- final String id = nextRandomId();
- packet.setAttribute("id", id);
- }
+ public void sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
packet.setFrom(account.getJid());
- this.sendPacket(packet, callback);
+ this.sendUnmodifiedIqPacket(packet,callback);
+
}
- public void sendUnboundIqPacket(final IqPacket packet, final PacketReceived callback) {
+ private synchronized void sendUnmodifiedIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
if (packet.getId() == null) {
final String id = nextRandomId();
packet.setAttribute("id", id);
}
- this.sendPacket(packet, callback);
+ if (callback != null) {
+ if (packet.getId() == null) {
+ packet.setId(nextRandomId());
+ }
+ packetCallbacks.put(packet.getId(), new Pair<>(packet, callback));
+ }
+ this.sendPacket(packet);
}
public void sendMessagePacket(final MessagePacket packet) {
- this.sendPacket(packet, null);
+ this.sendPacket(packet);
}
public void sendPresencePacket(final PresencePacket packet) {
- this.sendPacket(packet, null);
+ this.sendPacket(packet);
}
- private synchronized void sendPacket(final AbstractStanza packet, final PacketReceived callback) {
- if (packet.getName().equals("iq") || packet.getName().equals("message")
- || packet.getName().equals("presence")) {
+ private synchronized void sendPacket(final AbstractStanza packet) {
+ final String name = packet.getName();
+ if (name.equals("iq") || name.equals("message") || name.equals("presence")) {
++stanzasSent;
- }
+ }
tagWriter.writeStanzaAsync(packet);
- if (packet instanceof MessagePacket && packet.getId() != null
- && this.streamId != null) {
- Log.d(Config.LOGTAG, "request delivery report for stanza "
- + stanzasSent);
+ if (packet instanceof MessagePacket && packet.getId() != null && this.streamId != null) {
+ Log.d(Config.LOGTAG, "request delivery report for stanza " + stanzasSent);
this.messageReceipts.put(stanzasSent, packet.getId());
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
- }
- if (callback != null) {
- if (packet.getId() == null) {
- packet.setId(nextRandomId());
- }
- packetCallbacks.put(packet.getId(), callback);
}
}
@@ -895,7 +871,7 @@ public class XmppConnection implements Runnable {
if (streamFeatures.hasChild("sm")) {
tagWriter.writeStanzaAsync(new RequestPacket(smVersion));
} else {
- final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid());
iq.addChild("ping", "urn:xmpp:ping");
this.sendIqPacket(iq, null);
@@ -1040,19 +1016,22 @@ public class XmppConnection implements Runnable {
}
public long getLastPacketReceived() {
- return this.lastPaketReceived;
+ return this.lastPacketReceived;
}
public void sendActive() {
- this.sendPacket(new ActivePacket(), null);
+ this.sendPacket(new ActivePacket());
}
public void sendInactive() {
- this.sendPacket(new InactivePacket(), null);
+ this.sendPacket(new InactivePacket());
}
public class Features {
XmppConnection connection;
+ private boolean carbonsEnabled = false;
+ private boolean encryptionEnabled = false;
+ private boolean blockListRequested = false;
public Features(final XmppConnection connection) {
this.connection = connection;
@@ -1100,9 +1079,8 @@ public class XmppConnection implements Runnable {
return connection.streamFeatures != null && connection.streamFeatures.hasChild("ver");
}
- public boolean streamhost() {
- return connection
- .findDiscoItemByFeature("http://jabber.org/protocol/bytestreams") != null;
+ public void setBlockListRequested(boolean value) {
+ this.blockListRequested = value;
}
}
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 281ea3ca..dcadb92f 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
@@ -85,8 +85,7 @@ public class JingleCandidate {
}
public boolean equalValues(JingleCandidate other) {
- return other.getHost().equals(this.getHost())
- && (other.getPort() == this.getPort());
+ return other != null && other.getHost().equals(this.getHost()) && (other.getPort() == this.getPort());
}
public boolean isOurs() {
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 d578ca38..2d949e21 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -36,8 +36,6 @@ public class JingleConnection implements Downloadable {
protected static final int JINGLE_STATUS_INITIATED = 0;
protected static final int JINGLE_STATUS_ACCEPTED = 1;
- protected static final int JINGLE_STATUS_TERMINATED = 2;
- protected static final int JINGLE_STATUS_CANCELED = 3;
protected static final int JINGLE_STATUS_FINISHED = 4;
protected static final int JINGLE_STATUS_TRANSMITTING = 5;
protected static final int JINGLE_STATUS_FAILED = 99;
@@ -75,7 +73,7 @@ public class JingleConnection implements Downloadable {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE_ERROR) {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
fail();
}
}
@@ -101,11 +99,9 @@ public class JingleConnection implements Downloadable {
file.delete();
}
}
- Log.d(Config.LOGTAG,
- "sucessfully transmitted file:" + file.getAbsolutePath());
+ Log.d(Config.LOGTAG,"sucessfully transmitted file:" + file.getAbsolutePath());
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
- Intent intent = new Intent(
- Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
mXmppConnectionService.sendBroadcast(intent);
}
@@ -191,10 +187,10 @@ public class JingleConnection implements Downloadable {
}
IqPacket response;
if (returnResult) {
- response = packet.generateResponse(IqPacket.TYPE_RESULT);
+ response = packet.generateResponse(IqPacket.TYPE.RESULT);
} else {
- response = packet.generateResponse(IqPacket.TYPE_ERROR);
+ response = packet.generateResponse(IqPacket.TYPE.ERROR);
}
account.getXmppConnection().sendIqPacket(response, null);
}
@@ -280,16 +276,18 @@ public class JingleConnection implements Downloadable {
Element fileNameElement = fileOffer.findChild("name");
if (fileNameElement != null) {
String[] filename = fileNameElement.getContent()
- .toLowerCase(Locale.US).split("\\.");
- if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(
- filename[filename.length - 1])) {
+ .toLowerCase(Locale.US).toLowerCase().split("\\.");
+ String extension = filename[filename.length - 1];
+ if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) {
message.setType(Message.TYPE_IMAGE);
+ message.setRelativeFilePath(message.getUuid()+"."+extension);
} else if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains(
filename[filename.length - 1])) {
if (filename.length == 3) {
- if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(
- filename[filename.length - 2])) {
+ extension = filename[filename.length - 2];
+ if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) {
message.setType(Message.TYPE_IMAGE);
+ message.setRelativeFilePath(message.getUuid()+"."+extension);
} else {
message.setType(Message.TYPE_FILE);
}
@@ -360,7 +358,6 @@ public class JingleConnection implements Downloadable {
}
private void sendInitRequest() {
- this.mXmppConnectionService.markMessage(this.message, Message.STATUS_OFFERED);
JinglePacket packet = this.bootstrapPacket("session-initiate");
Content content = new Content(this.contentCreator, this.contentName);
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
@@ -379,8 +376,19 @@ public class JingleConnection implements Downloadable {
content.setTransportId(this.transportId);
content.socks5transport().setChildren(getCandidatesAsElements());
packet.setContent(content);
- this.sendJinglePacket(packet);
- this.mJingleStatus = JINGLE_STATUS_INITIATED;
+ this.sendJinglePacket(packet,new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ if (packet.getType() != IqPacket.TYPE.ERROR) {
+ mJingleStatus = JINGLE_STATUS_INITIATED;
+ mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
+ } else {
+ fail();
+ }
+ }
+ });
+
}
}
@@ -396,58 +404,48 @@ public class JingleConnection implements Downloadable {
mJingleStatus = JINGLE_STATUS_ACCEPTED;
this.mStatus = Downloadable.STATUS_DOWNLOADING;
mXmppConnectionService.updateConversationUi();
- this.mJingleConnectionManager.getPrimaryCandidate(this.account,
- new OnPrimaryCandidateFound() {
-
- @Override
- public void onPrimaryCandidateFound(boolean success,
- final JingleCandidate candidate) {
- final JinglePacket packet = bootstrapPacket("session-accept");
- final Content content = new Content(contentCreator,
- contentName);
- content.setFileOffer(fileOffer);
- content.setTransportId(transportId);
- if ((success) && (!equalCandidateExists(candidate))) {
- final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
- JingleConnection.this, candidate);
- connections.put(candidate.getCid(), socksConnection);
- socksConnection.connect(new OnTransportConnected() {
-
- @Override
- public void failed() {
- Log.d(Config.LOGTAG,
- "connection to our own primary candidate failed");
- content.socks5transport().setChildren(
- getCandidatesAsElements());
- packet.setContent(content);
- sendJinglePacket(packet);
- connectNextCandidate();
- }
+ this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
+ @Override
+ public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
+ final JinglePacket packet = bootstrapPacket("session-accept");
+ final Content content = new Content(contentCreator,contentName);
+ content.setFileOffer(fileOffer);
+ content.setTransportId(transportId);
+ if (success && candidate != null && !equalCandidateExists(candidate)) {
+ final JingleSocks5Transport socksConnection = new JingleSocks5Transport(
+ JingleConnection.this,
+ candidate);
+ connections.put(candidate.getCid(), socksConnection);
+ socksConnection.connect(new OnTransportConnected() {
- @Override
- public void established() {
- Log.d(Config.LOGTAG,
- "connected to primary candidate");
- mergeCandidate(candidate);
- content.socks5transport().setChildren(
- getCandidatesAsElements());
- packet.setContent(content);
- sendJinglePacket(packet);
- connectNextCandidate();
- }
- });
- } else {
- Log.d(Config.LOGTAG,
- "did not find a primary candidate for ourself");
- content.socks5transport().setChildren(
- getCandidatesAsElements());
+ @Override
+ public void failed() {
+ Log.d(Config.LOGTAG,"connection to our own primary candidate failed");
+ content.socks5transport().setChildren(getCandidatesAsElements());
packet.setContent(content);
sendJinglePacket(packet);
connectNextCandidate();
}
- }
- });
+ @Override
+ public void established() {
+ Log.d(Config.LOGTAG, "connected to primary candidate");
+ mergeCandidate(candidate);
+ content.socks5transport().setChildren(getCandidatesAsElements());
+ packet.setContent(content);
+ sendJinglePacket(packet);
+ connectNextCandidate();
+ }
+ });
+ } else {
+ Log.d(Config.LOGTAG,"did not find a primary candidate for ourself");
+ content.socks5transport().setChildren(getCandidatesAsElements());
+ packet.setContent(content);
+ sendJinglePacket(packet);
+ connectNextCandidate();
+ }
+ }
+ });
}
private JinglePacket bootstrapPacket(String action) {
@@ -461,10 +459,13 @@ public class JingleConnection implements Downloadable {
}
private void sendJinglePacket(JinglePacket packet) {
- // Log.d(Config.LOGTAG,packet.toString());
account.getXmppConnection().sendIqPacket(packet, responseListener);
}
+ private void sendJinglePacket(JinglePacket packet, OnIqPacketReceived callback) {
+ account.getXmppConnection().sendIqPacket(packet,callback);
+ }
+
private boolean receiveAccept(JinglePacket packet) {
Content content = packet.getJingleContent();
mergeCandidates(JingleCandidate.parse(content.socks5transport()
@@ -479,16 +480,13 @@ public class JingleConnection implements Downloadable {
Content content = packet.getJingleContent();
if (content.hasSocks5Transport()) {
if (content.socks5transport().hasChild("activated")) {
- if ((this.transport != null)
- && (this.transport instanceof JingleSocks5Transport)) {
+ if ((this.transport != null) && (this.transport instanceof JingleSocks5Transport)) {
onProxyActivated.success();
} else {
- String cid = content.socks5transport()
- .findChild("activated").getAttribute("cid");
+ String cid = content.socks5transport().findChild("activated").getAttribute("cid");
Log.d(Config.LOGTAG, "received proxy activated (" + cid
+ ")prior to choosing our own transport");
- JingleSocks5Transport connection = this.connections
- .get(cid);
+ JingleSocks5Transport connection = this.connections.get(cid);
if (connection != null) {
connection.setActivated(true);
} else {
@@ -552,7 +550,7 @@ public class JingleConnection implements Downloadable {
Log.d(Config.LOGTAG, "candidate "
+ connection.getCandidate().getCid()
+ " was our proxy. going to activate");
- IqPacket activation = new IqPacket(IqPacket.TYPE_SET);
+ IqPacket activation = new IqPacket(IqPacket.TYPE.SET);
activation.setTo(connection.getCandidate().getJid());
activation.query("http://jabber.org/protocol/bytestreams")
.setAttribute("sid", this.getSessionId());
@@ -564,7 +562,7 @@ public class JingleConnection implements Downloadable {
@Override
public void onIqPacketReceived(Account account,
IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE_ERROR) {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
onProxyActivated.failed();
} else {
onProxyActivated.success();
@@ -707,8 +705,7 @@ public class JingleConnection implements Downloadable {
private void receiveSuccess() {
this.mJingleStatus = JINGLE_STATUS_FINISHED;
- this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_SEND);
+ this.mXmppConnectionService.markMessage(this.message,Message.STATUS_SEND_RECEIVED);
this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) {
this.transport.disconnect();
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 b0a730b1..5dfa3ff4 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -12,6 +12,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
@@ -46,7 +47,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return;
}
}
- IqPacket response = packet.generateResponse(IqPacket.TYPE_ERROR);
+ IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
Element error = response.addChild("error");
error.setAttribute("type", "cancel");
error.addChild("item-not-found",
@@ -80,49 +81,37 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return;
}
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
- String xmlns = "http://jabber.org/protocol/bytestreams";
- final String proxy = account.getXmppConnection()
- .findDiscoItemByFeature(xmlns);
+ final String proxy = account.getXmppConnection().findDiscoItemByFeature(Xmlns.BYTE_STREAMS);
if (proxy != null) {
- IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setAttribute("to", proxy);
- iq.query(xmlns);
- account.getXmppConnection().sendIqPacket(iq,
- new OnIqPacketReceived() {
+ iq.query(Xmlns.BYTE_STREAMS);
+ account.getXmppConnection().sendIqPacket(iq,new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account,
- IqPacket packet) {
- Element streamhost = packet
- .query()
- .findChild("streamhost",
- "http://jabber.org/protocol/bytestreams");
- if (streamhost != null) {
- JingleCandidate candidate = new JingleCandidate(
- nextRandomId(), true);
- candidate.setHost(streamhost
- .getAttribute("host"));
- candidate.setPort(Integer
- .parseInt(streamhost
- .getAttribute("port")));
- candidate
- .setType(JingleCandidate.TYPE_PROXY);
- try {
- candidate.setJid(Jid.fromString(proxy));
- } catch (final InvalidJidException e) {
- candidate.setJid(null);
- }
- candidate.setPriority(655360 + 65535);
- primaryCandidates.put(account.getJid().toBareJid(),
- candidate);
- listener.onPrimaryCandidateFound(true,
- candidate);
- } else {
- listener.onPrimaryCandidateFound(false,
- null);
- }
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Element streamhost = packet.query().findChild("streamhost",Xmlns.BYTE_STREAMS);
+ final String host = streamhost == null ? null : streamhost.getAttribute("host");
+ final String port = streamhost == null ? null : streamhost.getAttribute("port");
+ if (host != null && port != null) {
+ try {
+ JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
+ candidate.setHost(host);
+ candidate.setPort(Integer.parseInt(port));
+ candidate.setType(JingleCandidate.TYPE_PROXY);
+ candidate.setJid(Jid.fromString(proxy));
+ candidate.setPriority(655360 + 65535);
+ primaryCandidates.put(account.getJid().toBareJid(),candidate);
+ listener.onPrimaryCandidateFound(true,candidate);
+ } catch (final NumberFormatException | InvalidJidException e) {
+ listener.onPrimaryCandidateFound(false,null);
+ return;
}
- });
+ } else {
+ listener.onPrimaryCandidateFound(false,null);
+ }
+ }
+ });
} else {
listener.onPrimaryCandidateFound(false, null);
}
@@ -141,12 +130,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
String sid = null;
Element payload = null;
if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
- payload = packet
- .findChild("open", "http://jabber.org/protocol/ibb");
+ payload = packet.findChild("open", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
} else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
- payload = packet
- .findChild("data", "http://jabber.org/protocol/ibb");
+ payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
}
if (sid != null) {
@@ -161,10 +148,9 @@ public class JingleConnectionManager extends AbstractConnectionManager {
}
}
}
- Log.d(Config.LOGTAG,
- "couldnt deliver payload: " + payload.toString());
+ Log.d(Config.LOGTAG,"couldn't deliver payload: " + payload.toString());
} else {
- Log.d(Config.LOGTAG, "no sid found in incomming ibb packet");
+ Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
}
}
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 e25f7e65..174f70fa 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
@@ -44,7 +44,7 @@ public class JingleInbandTransport extends JingleTransport {
private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- if (connected && packet.getType() == IqPacket.TYPE_RESULT) {
+ if (connected && packet.getType() == IqPacket.TYPE.RESULT) {
sendNextBlock();
}
}
@@ -60,7 +60,7 @@ public class JingleInbandTransport extends JingleTransport {
}
public void connect(final OnTransportConnected callback) {
- IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
+ IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.setTo(this.counterpart);
Element open = iq.addChild("open", "http://jabber.org/protocol/ibb");
open.setAttribute("sid", this.sessionId);
@@ -73,7 +73,7 @@ public class JingleInbandTransport extends JingleTransport {
@Override
public void onIqPacketReceived(Account account,
IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE_ERROR) {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
callback.failed();
} else {
callback.established();
@@ -157,7 +157,7 @@ public class JingleInbandTransport extends JingleTransport {
this.remainingSize -= count;
this.digest.update(buffer);
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
- IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
+ IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.setTo(this.counterpart);
Element data = iq.addChild("data",
"http://jabber.org/protocol/ibb");
@@ -208,15 +208,15 @@ public class JingleInbandTransport extends JingleTransport {
established = true;
connected = true;
this.account.getXmppConnection().sendIqPacket(
- packet.generateResponse(IqPacket.TYPE_RESULT), null);
+ packet.generateResponse(IqPacket.TYPE.RESULT), null);
} else {
this.account.getXmppConnection().sendIqPacket(
- packet.generateResponse(IqPacket.TYPE_ERROR), null);
+ packet.generateResponse(IqPacket.TYPE.ERROR), null);
}
} else if (connected && payload.getName().equals("data")) {
this.receiveNextBlock(payload.getContent());
this.account.getXmppConnection().sendIqPacket(
- packet.generateResponse(IqPacket.TYPE_RESULT), null);
+ packet.generateResponse(IqPacket.TYPE.RESULT), null);
} else {
// TODO some sort of exception
}
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 1a49b45e..55256ece 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
@@ -1,11 +1,12 @@
package eu.siacs.conversations.xmpp.stanzas;
+import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.Jid;
public class AbstractStanza extends Element {
- protected AbstractStanza(String name) {
+ protected AbstractStanza(final String name) {
super(name);
}
@@ -36,4 +37,18 @@ public class AbstractStanza extends Element {
public void setId(final String id) {
setAttribute("id", id);
}
+
+ public boolean fromServer(final Account account) {
+ return getFrom() == null
+ || getFrom().equals(account.getServer())
+ || getFrom().equals(account.getJid().toBareJid())
+ || 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());
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
index 2481112b..7b36fc49 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
@@ -4,32 +4,18 @@ import eu.siacs.conversations.xml.Element;
public class IqPacket extends AbstractStanza {
- public static final int TYPE_ERROR = -1;
- public static final int TYPE_SET = 0;
- public static final int TYPE_RESULT = 1;
- public static final int TYPE_GET = 2;
-
- private IqPacket(final String name) {
- super(name);
+ public static enum TYPE {
+ ERROR,
+ SET,
+ RESULT,
+ GET,
+ INVALID
}
- public IqPacket(final int type) {
+ public IqPacket(final TYPE type) {
super("iq");
- switch (type) {
- case TYPE_SET:
- this.setAttribute("type", "set");
- break;
- case TYPE_GET:
- this.setAttribute("type", "get");
- break;
- case TYPE_RESULT:
- this.setAttribute("type", "result");
- break;
- case TYPE_ERROR:
- this.setAttribute("type", "error");
- break;
- default:
- break;
+ if (type != TYPE.INVALID) {
+ this.setAttribute("type", type.toString().toLowerCase());
}
}
@@ -51,23 +37,23 @@ public class IqPacket extends AbstractStanza {
return query();
}
- public int getType() {
+ public TYPE getType() {
final String type = getAttribute("type");
switch (type) {
case "error":
- return TYPE_ERROR;
+ return TYPE.ERROR;
case "result":
- return TYPE_RESULT;
+ return TYPE.RESULT;
case "set":
- return TYPE_SET;
+ return TYPE.SET;
case "get":
- return TYPE_GET;
+ return TYPE.GET;
default:
- return 1000;
+ return TYPE.INVALID;
}
}
- public IqPacket generateResponse(final int type) {
+ public IqPacket generateResponse(final TYPE type) {
final IqPacket packet = new IqPacket(type);
packet.setTo(this.getFrom());
packet.setId(this.getId());