aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
commit1ac5be485502e7d6d4c117335e083c684739e6af (patch)
tree279c22e269158dde838f31ebcf3daf4272573583 /src/eu/siacs/conversations/xmpp/jingle
parent8d456085e57334dc34707a49666006619e2c77c6 (diff)
some code cleanup
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java67
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java72
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java58
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleFile.java35
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java12
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java51
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java51
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/OnFileTransmissionStatusChanged.java1
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCandidateFound.java3
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/OnTransportConnected.java1
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java64
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java28
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java2
13 files changed, 248 insertions, 197 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java b/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
index 80ffeaaa..2874b9a5 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java
@@ -6,11 +6,11 @@ import java.util.List;
import eu.siacs.conversations.xml.Element;
public class JingleCandidate {
-
+
public static int TYPE_UNKNOWN;
public static int TYPE_DIRECT = 0;
public static int TYPE_PROXY = 1;
-
+
private boolean ours;
private boolean usedByCounterpart = false;
private String cid;
@@ -19,12 +19,12 @@ public class JingleCandidate {
private int type;
private String jid;
private int priority;
-
- public JingleCandidate(String cid,boolean ours) {
+
+ public JingleCandidate(String cid, boolean ours) {
this.ours = ours;
this.cid = cid;
}
-
+
public String getCid() {
return cid;
}
@@ -32,15 +32,15 @@ public class JingleCandidate {
public void setHost(String host) {
this.host = host;
}
-
+
public String getHost() {
return this.host;
}
-
+
public void setJid(String jid) {
this.jid = jid;
}
-
+
public String getJid() {
return this.jid;
}
@@ -48,15 +48,15 @@ public class JingleCandidate {
public void setPort(int port) {
this.port = port;
}
-
+
public int getPort() {
return this.port;
}
-
+
public void setType(int type) {
this.type = type;
}
-
+
public void setType(String type) {
if ("proxy".equals(type)) {
this.type = TYPE_PROXY;
@@ -70,42 +70,46 @@ public class JingleCandidate {
public void setPriority(int i) {
this.priority = i;
}
-
+
public int getPriority() {
return this.priority;
}
-
+
public boolean equals(JingleCandidate other) {
return this.getCid().equals(other.getCid());
}
-
+
public boolean equalValues(JingleCandidate other) {
- return other.getHost().equals(this.getHost())&&(other.getPort()==this.getPort());
+ return other.getHost().equals(this.getHost())
+ && (other.getPort() == this.getPort());
}
-
+
public boolean isOurs() {
return ours;
}
-
+
public int getType() {
return this.type;
}
public static List<JingleCandidate> parse(List<Element> canditates) {
List<JingleCandidate> parsedCandidates = new ArrayList<JingleCandidate>();
- for(Element c : canditates) {
+ for (Element c : canditates) {
parsedCandidates.add(JingleCandidate.parse(c));
}
return parsedCandidates;
}
-
+
public static JingleCandidate parse(Element candidate) {
- JingleCandidate parsedCandidate = new JingleCandidate(candidate.getAttribute("cid"), false);
+ JingleCandidate parsedCandidate = new JingleCandidate(
+ candidate.getAttribute("cid"), false);
parsedCandidate.setHost(candidate.getAttribute("host"));
parsedCandidate.setJid(candidate.getAttribute("jid"));
parsedCandidate.setType(candidate.getAttribute("type"));
- parsedCandidate.setPriority(Integer.parseInt(candidate.getAttribute("priority")));
- parsedCandidate.setPort(Integer.parseInt(candidate.getAttribute("port")));
+ parsedCandidate.setPriority(Integer.parseInt(candidate
+ .getAttribute("priority")));
+ parsedCandidate
+ .setPort(Integer.parseInt(candidate.getAttribute("port")));
return parsedCandidate;
}
@@ -113,26 +117,27 @@ public class JingleCandidate {
Element element = new Element("candidate");
element.setAttribute("cid", this.getCid());
element.setAttribute("host", this.getHost());
- element.setAttribute("port", ""+this.getPort());
+ element.setAttribute("port", "" + this.getPort());
element.setAttribute("jid", this.getJid());
- element.setAttribute("priority",""+this.getPriority());
- if (this.getType()==TYPE_DIRECT) {
- element.setAttribute("type","direct");
- } else if (this.getType()==TYPE_PROXY) {
- element.setAttribute("type","proxy");
+ element.setAttribute("priority", "" + this.getPriority());
+ if (this.getType() == TYPE_DIRECT) {
+ element.setAttribute("type", "direct");
+ } else if (this.getType() == TYPE_PROXY) {
+ element.setAttribute("type", "proxy");
}
return element;
}
public void flagAsUsedByCounterpart() {
- this.usedByCounterpart = true;
+ this.usedByCounterpart = true;
}
public boolean isUsedByCounterpart() {
return this.usedByCounterpart;
}
-
+
public String toString() {
- return this.getHost()+":"+this.getPort()+" (prio="+this.getPriority()+")";
+ return this.getHost() + ":" + this.getPort() + " (prio="
+ + this.getPriority() + ")";
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index bfdbb7cc..317838fd 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -12,6 +12,7 @@ import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@@ -100,10 +101,11 @@ public class JingleConnection {
mXmppConnectionService.markMessage(message,
Message.STATUS_RECEIVED);
}
- Log.d("xmppService",
+ 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);
+ if (message.getEncryption() != Message.ENCRYPTION_PGP) {
+ Intent intent = new Intent(
+ Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
mXmppConnectionService.sendBroadcast(intent);
}
@@ -121,17 +123,17 @@ public class JingleConnection {
@Override
public void success() {
if (initiator.equals(account.getFullJid())) {
- Log.d("xmppService", "we were initiating. sending file");
+ Log.d(Config.LOGTAG, "we were initiating. sending file");
transport.send(file, onFileTransmissionSatusChanged);
} else {
transport.receive(file, onFileTransmissionSatusChanged);
- Log.d("xmppService", "we were responding. receiving file");
+ Log.d(Config.LOGTAG, "we were responding. receiving file");
}
}
@Override
public void failed() {
- Log.d("xmppService", "proxy activation failed");
+ Log.d(Config.LOGTAG, "proxy activation failed");
}
};
@@ -177,13 +179,13 @@ public class JingleConnection {
returnResult = this.receiveFallbackToIbb(packet);
} else {
returnResult = false;
- Log.d("xmppService", "trying to fallback to something unknown"
+ Log.d(Config.LOGTAG, "trying to fallback to something unknown"
+ packet.toString());
}
} else if (packet.isAction("transport-accept")) {
returnResult = this.receiveTransportAccept(packet);
} else {
- Log.d("xmppService", "packet arrived in connection. action was "
+ Log.d(Config.LOGTAG, "packet arrived in connection. action was "
+ packet.getAction());
returnResult = false;
}
@@ -224,14 +226,14 @@ public class JingleConnection {
@Override
public void failed() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"connection to our own primary candidete failed");
sendInitRequest();
}
@Override
public void established() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"succesfully connected to our own primary candidate");
mergeCandidate(candidate);
sendInitRequest();
@@ -239,7 +241,7 @@ public class JingleConnection {
});
mergeCandidate(candidate);
} else {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"no primary candidate of our own was found");
sendInitRequest();
}
@@ -288,7 +290,7 @@ public class JingleConnection {
filename[filename.length - 2])) {
supportedFile = true;
if (filename[filename.length - 1].equals("otr")) {
- Log.d("xmppService", "receiving otr file");
+ Log.d(Config.LOGTAG, "receiving otr file");
this.message
.setEncryption(Message.ENCRYPTION_OTR);
} else {
@@ -304,13 +306,13 @@ public class JingleConnection {
conversation.getMessages().add(message);
if (size <= this.mJingleConnectionManager
.getAutoAcceptFileSize()) {
- Log.d("xmppService", "auto accepting file from "
+ Log.d(Config.LOGTAG, "auto accepting file from "
+ packet.getFrom());
this.acceptedAutomatically = true;
this.sendAccept();
} else {
message.markUnread();
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"not auto accepting new file offer with size: "
+ size
+ " allowed size:"
@@ -400,7 +402,7 @@ public class JingleConnection {
@Override
public void failed() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"connection to our own primary candidate failed");
content.socks5transport().setChildren(
getCandidatesAsElements());
@@ -411,7 +413,7 @@ public class JingleConnection {
@Override
public void established() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"connected to primary candidate");
mergeCandidate(candidate);
content.socks5transport().setChildren(
@@ -422,7 +424,7 @@ public class JingleConnection {
}
});
} else {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"did not find a primary candidate for ourself");
content.socks5transport().setChildren(
getCandidatesAsElements());
@@ -446,7 +448,7 @@ public class JingleConnection {
}
private void sendJinglePacket(JinglePacket packet) {
- // Log.d("xmppService",packet.toString());
+ // Log.d(Config.LOGTAG,packet.toString());
account.getXmppConnection().sendIqPacket(packet, responseListener);
}
@@ -470,14 +472,14 @@ public class JingleConnection {
} else {
String cid = content.socks5transport()
.findChild("activated").getAttribute("cid");
- Log.d("xmppService", "received proxy activated (" + cid
+ Log.d(Config.LOGTAG, "received proxy activated (" + cid
+ ")prior to choosing our own transport");
JingleSocks5Transport connection = this.connections
.get(cid);
if (connection != null) {
connection.setActivated(true);
} else {
- Log.d("xmppService", "activated connection not found");
+ Log.d(Config.LOGTAG, "activated connection not found");
this.sendCancel();
this.cancel();
}
@@ -487,7 +489,7 @@ public class JingleConnection {
onProxyActivated.failed();
return true;
} else if (content.socks5transport().hasChild("candidate-error")) {
- Log.d("xmppService", "received candidate error");
+ Log.d(Config.LOGTAG, "received candidate error");
this.receivedCandidate = true;
if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
this.connect();
@@ -497,14 +499,14 @@ public class JingleConnection {
String cid = content.socks5transport()
.findChild("candidate-used").getAttribute("cid");
if (cid != null) {
- Log.d("xmppService", "candidate used by counterpart:" + cid);
+ Log.d(Config.LOGTAG, "candidate used by counterpart:" + cid);
JingleCandidate candidate = getCandidate(cid);
candidate.flagAsUsedByCounterpart();
this.receivedCandidate = true;
if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
this.connect();
} else {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"ignoring because file is already in transmission or we havent sent our candidate yet");
}
return true;
@@ -523,7 +525,7 @@ public class JingleConnection {
final JingleSocks5Transport connection = chooseConnection();
this.transport = connection;
if (connection == null) {
- Log.d("xmppService", "could not find suitable candidate");
+ Log.d(Config.LOGTAG, "could not find suitable candidate");
this.disconnect();
if (this.initiator.equals(account.getFullJid())) {
this.sendFallbackToIbb();
@@ -532,7 +534,7 @@ public class JingleConnection {
this.status = STATUS_TRANSMITTING;
if (connection.needsActivation()) {
if (connection.getCandidate().isOurs()) {
- Log.d("xmppService", "candidate "
+ Log.d(Config.LOGTAG, "candidate "
+ connection.getCandidate().getCid()
+ " was our proxy. going to activate");
IqPacket activation = new IqPacket(IqPacket.TYPE_SET);
@@ -557,17 +559,17 @@ public class JingleConnection {
}
});
} else {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"candidate "
+ connection.getCandidate().getCid()
+ " was a proxy. waiting for other party to activate");
}
} else {
if (initiator.equals(account.getFullJid())) {
- Log.d("xmppService", "we were initiating. sending file");
+ Log.d(Config.LOGTAG, "we were initiating. sending file");
connection.send(file, onFileTransmissionSatusChanged);
} else {
- Log.d("xmppService", "we were responding. receiving file");
+ Log.d(Config.LOGTAG, "we were responding. receiving file");
connection.receive(file, onFileTransmissionSatusChanged);
}
}
@@ -579,11 +581,11 @@ public class JingleConnection {
for (Entry<String, JingleSocks5Transport> cursor : connections
.entrySet()) {
JingleSocks5Transport currentConnection = cursor.getValue();
- // Log.d("xmppService","comparing candidate: "+currentConnection.getCandidate().toString());
+ // Log.d(Config.LOGTAG,"comparing candidate: "+currentConnection.getCandidate().toString());
if (currentConnection.isEstablished()
&& (currentConnection.getCandidate().isUsedByCounterpart() || (!currentConnection
.getCandidate().isOurs()))) {
- // Log.d("xmppService","is usable");
+ // Log.d(Config.LOGTAG,"is usable");
if (connection == null) {
connection = currentConnection;
} else {
@@ -592,7 +594,7 @@ public class JingleConnection {
connection = currentConnection;
} else if (connection.getCandidate().getPriority() == currentConnection
.getCandidate().getPriority()) {
- // Log.d("xmppService","found two candidates with same priority");
+ // Log.d(Config.LOGTAG,"found two candidates with same priority");
if (initiator.equals(account.getFullJid())) {
if (currentConnection.getCandidate().isOurs()) {
connection = currentConnection;
@@ -672,7 +674,7 @@ public class JingleConnection {
@Override
public void failed() {
- Log.d("xmppService", "ibb open failed");
+ Log.d(Config.LOGTAG, "ibb open failed");
}
@Override
@@ -742,7 +744,7 @@ public class JingleConnection {
@Override
public void failed() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"connection failed with " + candidate.getHost() + ":"
+ candidate.getPort());
connectNextCandidate();
@@ -750,7 +752,7 @@ public class JingleConnection {
@Override
public void established() {
- Log.d("xmppService",
+ Log.d(Config.LOGTAG,
"established connection with " + candidate.getHost()
+ ":" + candidate.getPort());
sendCandidateUsed(candidate.getCid());
@@ -874,7 +876,7 @@ public class JingleConnection {
}
}).start();
} else {
- Log.d("xmppService", "status (" + status + ") was not ok");
+ Log.d(Config.LOGTAG, "status (" + status + ") was not ok");
}
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
index f01d7fa9..79090af6 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -7,6 +7,7 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import android.annotation.SuppressLint;
import android.util.Log;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
@@ -33,18 +34,20 @@ public class JingleConnectionManager {
public void deliverPacket(Account account, JinglePacket packet) {
if (packet.isAction("session-initiate")) {
JingleConnection connection = new JingleConnection(this);
- connection.init(account,packet);
+ connection.init(account, packet);
connections.add(connection);
} else {
for (JingleConnection connection : connections) {
- if (connection.getAccountJid().equals(account.getFullJid()) && connection
- .getSessionId().equals(packet.getSessionId()) && connection
- .getCounterPart().equals(packet.getFrom())) {
+ if (connection.getAccountJid().equals(account.getFullJid())
+ && connection.getSessionId().equals(
+ packet.getSessionId())
+ && connection.getCounterPart().equals(packet.getFrom())) {
connection.deliverPacket(packet);
return;
}
}
- account.getXmppConnection().sendIqPacket(packet.generateRespone(IqPacket.TYPE_ERROR), null);
+ account.getXmppConnection().sendIqPacket(
+ packet.generateRespone(IqPacket.TYPE_ERROR), null);
}
}
@@ -60,7 +63,7 @@ public class JingleConnectionManager {
this.connections.add(connection);
return connection;
}
-
+
public void finishConnection(JingleConnection connection) {
this.connections.remove(connection);
}
@@ -90,12 +93,17 @@ public class JingleConnectionManager {
.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);
+ JingleCandidate candidate = new JingleCandidate(
+ nextRandomId(), true);
+ candidate.setHost(streamhost
+ .getAttribute("host"));
+ candidate.setPort(Integer
+ .parseInt(streamhost
+ .getAttribute("port")));
+ candidate
+ .setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy);
- candidate.setPriority(655360+65535);
+ candidate.setPriority(655360 + 65535);
primaryCandidates.put(account.getJid(),
candidate);
listener.onPrimaryCandidateFound(true,
@@ -119,9 +127,10 @@ public class JingleConnectionManager {
public String nextRandomId() {
return new BigInteger(50, random).toString(32);
}
-
+
public long getAutoAcceptFileSize() {
- String config = this.xmppConnectionService.getPreferences().getString("auto_accept_file_size", "524288");
+ String config = this.xmppConnectionService.getPreferences().getString(
+ "auto_accept_file_size", "524288");
try {
return Long.parseLong(config);
} catch (NumberFormatException e) {
@@ -132,32 +141,35 @@ public class JingleConnectionManager {
public void deliverIbbPacket(Account account, IqPacket packet) {
String sid = null;
Element payload = null;
- if (packet.hasChild("open","http://jabber.org/protocol/ibb")) {
- payload = packet.findChild("open","http://jabber.org/protocol/ibb");
+ if (packet.hasChild("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");
+ } else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
+ payload = packet
+ .findChild("data", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
}
- if (sid!=null) {
+ if (sid != null) {
for (JingleConnection connection : connections) {
if (connection.hasTransportId(sid)) {
JingleTransport transport = connection.getTransport();
if (transport instanceof JingleInbandTransport) {
JingleInbandTransport inbandTransport = (JingleInbandTransport) transport;
- inbandTransport.deliverPayload(packet,payload);
+ inbandTransport.deliverPayload(packet, payload);
return;
}
}
}
- Log.d("xmppService","couldnt deliver payload: "+payload.toString());
+ Log.d(Config.LOGTAG,
+ "couldnt deliver payload: " + payload.toString());
} else {
- Log.d("xmppService","no sid found in incomming ibb packet");
+ Log.d(Config.LOGTAG, "no sid found in incomming ibb packet");
}
}
-
+
public void cancelInTransmission() {
- for(JingleConnection connection : this.connections) {
+ for (JingleConnection connection : this.connections) {
if (connection.getStatus() == JingleConnection.STATUS_TRANSMITTING) {
connection.cancel();
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleFile.java b/src/eu/siacs/conversations/xmpp/jingle/JingleFile.java
index 3672351b..9253814b 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleFile.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleFile.java
@@ -5,60 +5,63 @@ import java.security.Key;
import javax.crypto.spec.SecretKeySpec;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.CryptoHelper;
import android.util.Log;
public class JingleFile extends File {
-
+
private static final long serialVersionUID = 2247012619505115863L;
-
+
private long expectedSize = 0;
private String sha1sum;
private Key aeskey;
-
+
public JingleFile(String path) {
super(path);
}
-
+
public long getSize() {
return super.length();
}
-
+
public long getExpectedSize() {
- if (this.aeskey!=null) {
- return (this.expectedSize/16 + 1) * 16;
+ if (this.aeskey != null) {
+ return (this.expectedSize / 16 + 1) * 16;
} else {
return this.expectedSize;
}
}
-
+
public void setExpectedSize(long size) {
this.expectedSize = size;
}
-
+
public String getSha1Sum() {
return this.sha1sum;
}
-
+
public void setSha1Sum(String sum) {
this.sha1sum = sum;
}
-
+
public void setKey(byte[] key) {
- if (key.length>=32) {
+ if (key.length >= 32) {
byte[] secretKey = new byte[32];
System.arraycopy(key, 0, secretKey, 0, 32);
this.aeskey = new SecretKeySpec(secretKey, "AES");
- } else if (key.length>=16) {
+ } else if (key.length >= 16) {
byte[] secretKey = new byte[16];
System.arraycopy(key, 0, secretKey, 0, 16);
this.aeskey = new SecretKeySpec(secretKey, "AES");
} else {
- Log.d("xmppService","weird key");
+ Log.d(Config.LOGTAG, "weird key");
}
- Log.d("xmppService","using aes key "+CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
+ Log.d(Config.LOGTAG,
+ "using aes key "
+ + CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
}
-
+
public Key getKey() {
return this.aeskey;
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
index b859e7c7..331b53de 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
@@ -32,7 +32,7 @@ public class JingleInbandTransport extends JingleTransport {
private OutputStream fileOutputStream;
private long remainingSize;
private MessageDigest digest;
-
+
private OnFileTransmissionStatusChanged onFileTransmissionStatusChanged;
private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() {
@@ -77,7 +77,8 @@ public class JingleInbandTransport extends JingleTransport {
}
@Override
- public void receive(JingleFile file, OnFileTransmissionStatusChanged callback) {
+ public void receive(JingleFile file,
+ OnFileTransmissionStatusChanged callback) {
this.onFileTransmissionStatusChanged = callback;
this.file = file;
try {
@@ -86,7 +87,7 @@ public class JingleInbandTransport extends JingleTransport {
file.getParentFile().mkdirs();
file.createNewFile();
this.fileOutputStream = getOutputStream(file);
- if (this.fileOutputStream==null) {
+ if (this.fileOutputStream == null) {
callback.onFileTransferAborted();
return;
}
@@ -106,7 +107,7 @@ public class JingleInbandTransport extends JingleTransport {
this.digest = MessageDigest.getInstance("SHA-1");
this.digest.reset();
fileInputStream = this.getInputStream(file);
- if (fileInputStream==null) {
+ if (fileInputStream == null) {
callback.onFileTransferAborted();
return;
}
@@ -150,7 +151,8 @@ public class JingleInbandTransport extends JingleTransport {
try {
byte[] buffer = Base64.decode(data, Base64.NO_WRAP);
if (this.remainingSize < buffer.length) {
- buffer = Arrays.copyOfRange(buffer, 0, (int) this.remainingSize);
+ buffer = Arrays
+ .copyOfRange(buffer, 0, (int) this.remainingSize);
}
this.remainingSize -= buffer.length;
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java
index d2c84325..e476decc 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java
@@ -21,7 +21,8 @@ public class JingleSocks5Transport extends JingleTransport {
private boolean activated = false;
protected Socket socket;
- public JingleSocks5Transport(JingleConnection jingleConnection, JingleCandidate candidate) {
+ public JingleSocks5Transport(JingleConnection jingleConnection,
+ JingleCandidate candidate) {
this.candidate = candidate;
try {
MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
@@ -44,11 +45,12 @@ public class JingleSocks5Transport extends JingleTransport {
public void connect(final OnTransportConnected callback) {
new Thread(new Runnable() {
-
+
@Override
public void run() {
try {
- socket = new Socket(candidate.getHost(), candidate.getPort());
+ socket = new Socket(candidate.getHost(),
+ candidate.getPort());
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
byte[] login = { 0x05, 0x01, 0x00 };
@@ -57,8 +59,9 @@ public class JingleSocks5Transport extends JingleTransport {
outputStream.write(login);
inputStream.read(reply);
if (Arrays.equals(reply, expectedReply)) {
- String connect = "" + '\u0005' + '\u0001' + '\u0000' + '\u0003'
- + '\u0028' + destination + '\u0000' + '\u0000';
+ String connect = "" + '\u0005' + '\u0001' + '\u0000'
+ + '\u0003' + '\u0028' + destination + '\u0000'
+ + '\u0000';
outputStream.write(connect.getBytes());
byte[] result = new byte[2];
inputStream.read(result);
@@ -80,12 +83,13 @@ public class JingleSocks5Transport extends JingleTransport {
}
}
}).start();
-
+
}
- public void send(final JingleFile file, final OnFileTransmissionStatusChanged callback) {
+ public void send(final JingleFile file,
+ final OnFileTransmissionStatusChanged callback) {
new Thread(new Runnable() {
-
+
@Override
public void run() {
InputStream fileInputStream = null;
@@ -93,7 +97,7 @@ public class JingleSocks5Transport extends JingleTransport {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.reset();
fileInputStream = getInputStream(file);
- if (fileInputStream==null) {
+ if (fileInputStream == null) {
callback.onFileTransferAborted();
return;
}
@@ -105,7 +109,7 @@ public class JingleSocks5Transport extends JingleTransport {
}
outputStream.flush();
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
- if (callback!=null) {
+ if (callback != null) {
callback.onFileTransmitted(file);
}
} catch (FileNotFoundException e) {
@@ -125,12 +129,13 @@ public class JingleSocks5Transport extends JingleTransport {
}
}
}).start();
-
+
}
-
- public void receive(final JingleFile file, final OnFileTransmissionStatusChanged callback) {
+
+ public void receive(final JingleFile file,
+ final OnFileTransmissionStatusChanged callback) {
new Thread(new Runnable() {
-
+
@Override
public void run() {
try {
@@ -141,22 +146,22 @@ public class JingleSocks5Transport extends JingleTransport {
file.getParentFile().mkdirs();
file.createNewFile();
OutputStream fileOutputStream = getOutputStream(file);
- if (fileOutputStream==null) {
+ if (fileOutputStream == null) {
callback.onFileTransferAborted();
return;
}
long remainingSize = file.getExpectedSize();
byte[] buffer = new byte[8192];
int count = buffer.length;
- while(remainingSize > 0) {
+ while (remainingSize > 0) {
count = inputStream.read(buffer);
- if (count==-1) {
+ if (count == -1) {
callback.onFileTransferAborted();
return;
} else {
fileOutputStream.write(buffer, 0, count);
digest.update(buffer, 0, count);
- remainingSize-=count;
+ remainingSize -= count;
}
}
fileOutputStream.flush();
@@ -177,25 +182,25 @@ public class JingleSocks5Transport extends JingleTransport {
public boolean isProxy() {
return this.candidate.getType() == JingleCandidate.TYPE_PROXY;
}
-
+
public boolean needsActivation() {
return (this.isProxy() && !this.activated);
}
public void disconnect() {
- if (this.socket!=null) {
+ if (this.socket != null) {
try {
this.socket.close();
} catch (IOException e) {
-
+
}
}
}
-
+
public boolean isEstablished() {
return this.isEstablished;
}
-
+
public JingleCandidate getCandidate() {
return this.candidate;
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java
index 1acdfc39..07dc8ecc 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java
@@ -15,61 +15,72 @@ import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
+import eu.siacs.conversations.Config;
+
import android.util.Log;
public abstract class JingleTransport {
public abstract void connect(final OnTransportConnected callback);
- public abstract void receive(final JingleFile file, final OnFileTransmissionStatusChanged callback);
- public abstract void send(final JingleFile file, final OnFileTransmissionStatusChanged callback);
- private byte[] iv = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0xf};
-
- protected InputStream getInputStream(JingleFile file) throws FileNotFoundException {
+
+ public abstract void receive(final JingleFile file,
+ final OnFileTransmissionStatusChanged callback);
+
+ public abstract void send(final JingleFile file,
+ final OnFileTransmissionStatusChanged callback);
+
+ private byte[] iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf };
+
+ protected InputStream getInputStream(JingleFile file)
+ throws FileNotFoundException {
if (file.getKey() == null) {
return new FileInputStream(file);
} else {
try {
IvParameterSpec ips = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- cipher.init(Cipher.ENCRYPT_MODE, file.getKey(),ips);
- Log.d("xmppService","opening encrypted input stream");
+ cipher.init(Cipher.ENCRYPT_MODE, file.getKey(), ips);
+ Log.d(Config.LOGTAG, "opening encrypted input stream");
return new CipherInputStream(new FileInputStream(file), cipher);
} catch (NoSuchAlgorithmException e) {
- Log.d("xmppService","no such algo: "+e.getMessage());
+ Log.d(Config.LOGTAG, "no such algo: " + e.getMessage());
return null;
} catch (NoSuchPaddingException e) {
- Log.d("xmppService","no such padding: "+e.getMessage());
+ Log.d(Config.LOGTAG, "no such padding: " + e.getMessage());
return null;
} catch (InvalidKeyException e) {
- Log.d("xmppService","invalid key: "+e.getMessage());
+ Log.d(Config.LOGTAG, "invalid key: " + e.getMessage());
return null;
} catch (InvalidAlgorithmParameterException e) {
- Log.d("xmppService","invavid iv:"+e.getMessage());
+ Log.d(Config.LOGTAG, "invavid iv:" + e.getMessage());
return null;
}
}
}
-
- protected OutputStream getOutputStream(JingleFile file) throws FileNotFoundException {
+
+ protected OutputStream getOutputStream(JingleFile file)
+ throws FileNotFoundException {
if (file.getKey() == null) {
return new FileOutputStream(file);
} else {
try {
IvParameterSpec ips = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- cipher.init(Cipher.DECRYPT_MODE, file.getKey(),ips);
- Log.d("xmppService","opening encrypted output stream");
- return new CipherOutputStream(new FileOutputStream(file), cipher);
+ cipher.init(Cipher.DECRYPT_MODE, file.getKey(), ips);
+ Log.d(Config.LOGTAG, "opening encrypted output stream");
+ return new CipherOutputStream(new FileOutputStream(file),
+ cipher);
} catch (NoSuchAlgorithmException e) {
- Log.d("xmppService","no such algo: "+e.getMessage());
+ Log.d(Config.LOGTAG, "no such algo: " + e.getMessage());
return null;
} catch (NoSuchPaddingException e) {
- Log.d("xmppService","no such padding: "+e.getMessage());
+ Log.d(Config.LOGTAG, "no such padding: " + e.getMessage());
return null;
} catch (InvalidKeyException e) {
- Log.d("xmppService","invalid key: "+e.getMessage());
+ Log.d(Config.LOGTAG, "invalid key: " + e.getMessage());
return null;
} catch (InvalidAlgorithmParameterException e) {
- Log.d("xmppService","invavid iv:"+e.getMessage());
+ Log.d(Config.LOGTAG, "invavid iv:" + e.getMessage());
return null;
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/OnFileTransmissionStatusChanged.java b/src/eu/siacs/conversations/xmpp/jingle/OnFileTransmissionStatusChanged.java
index 84f10417..19fd4d97 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/OnFileTransmissionStatusChanged.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/OnFileTransmissionStatusChanged.java
@@ -2,5 +2,6 @@ package eu.siacs.conversations.xmpp.jingle;
public interface OnFileTransmissionStatusChanged {
public void onFileTransmitted(JingleFile file);
+
public void onFileTransferAborted();
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCandidateFound.java b/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCandidateFound.java
index b91a90ff..03a437b2 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCandidateFound.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCandidateFound.java
@@ -1,5 +1,6 @@
package eu.siacs.conversations.xmpp.jingle;
public interface OnPrimaryCandidateFound {
- public void onPrimaryCandidateFound(boolean success, JingleCandidate canditate);
+ public void onPrimaryCandidateFound(boolean success,
+ JingleCandidate canditate);
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/OnTransportConnected.java b/src/eu/siacs/conversations/xmpp/jingle/OnTransportConnected.java
index 7d9a084a..38f03c5d 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/OnTransportConnected.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/OnTransportConnected.java
@@ -2,5 +2,6 @@ package eu.siacs.conversations.xmpp.jingle;
public interface OnTransportConnected {
public void failed();
+
public void established();
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java
index 494ff0d6..1e8e3fd6 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java
@@ -4,17 +4,17 @@ import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
public class Content extends Element {
-
+
private String transportId;
-
+
private Content(String name) {
super(name);
}
-
+
public Content() {
super("content");
}
-
+
public Content(String creator, String name) {
super("content");
this.setAttribute("creator", creator);
@@ -24,39 +24,43 @@ public class Content extends Element {
public void setTransportId(String sid) {
this.transportId = sid;
}
-
+
public void setFileOffer(JingleFile actualFile, boolean otr) {
- Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
+ Element description = this.addChild("description",
+ "urn:xmpp:jingle:apps:file-transfer:3");
Element offer = description.addChild("offer");
Element file = offer.addChild("file");
- file.addChild("size").setContent(""+actualFile.getSize());
+ file.addChild("size").setContent("" + actualFile.getSize());
if (otr) {
- file.addChild("name").setContent(actualFile.getName()+".otr");
+ file.addChild("name").setContent(actualFile.getName() + ".otr");
} else {
file.addChild("name").setContent(actualFile.getName());
}
}
-
+
public Element getFileOffer() {
- Element description = this.findChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
- if (description==null) {
+ Element description = this.findChild("description",
+ "urn:xmpp:jingle:apps:file-transfer:3");
+ if (description == null) {
return null;
}
Element offer = description.findChild("offer");
- if (offer==null) {
+ if (offer == null) {
return null;
}
return offer.findChild("file");
}
-
+
public void setFileOffer(Element fileOffer) {
- Element description = this.findChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
- if (description==null) {
- description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
+ Element description = this.findChild("description",
+ "urn:xmpp:jingle:apps:file-transfer:3");
+ if (description == null) {
+ description = this.addChild("description",
+ "urn:xmpp:jingle:apps:file-transfer:3");
}
description.addChild(fileOffer);
}
-
+
public String getTransportId() {
if (hasSocks5Transport()) {
this.transportId = socks5transport().getAttribute("sid");
@@ -65,30 +69,34 @@ public class Content extends Element {
}
return this.transportId;
}
-
+
public Element socks5transport() {
- Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
- if (transport==null) {
- transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
+ Element transport = this.findChild("transport",
+ "urn:xmpp:jingle:transports:s5b:1");
+ if (transport == null) {
+ transport = this.addChild("transport",
+ "urn:xmpp:jingle:transports:s5b:1");
transport.setAttribute("sid", this.transportId);
}
return transport;
}
-
+
public Element ibbTransport() {
- Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:ibb:1");
- if (transport==null) {
- transport = this.addChild("transport", "urn:xmpp:jingle:transports:ibb:1");
+ Element transport = this.findChild("transport",
+ "urn:xmpp:jingle:transports:ibb:1");
+ if (transport == null) {
+ transport = this.addChild("transport",
+ "urn:xmpp:jingle:transports:ibb:1");
transport.setAttribute("sid", this.transportId);
}
return transport;
}
-
+
public boolean hasSocks5Transport() {
return this.hasChild("transport", "urn:xmpp:jingle:transports:s5b:1");
}
-
+
public boolean hasIbbTransport() {
- return this.hasChild("transport","urn:xmpp:jingle:transports:ibb:1");
+ return this.hasChild("transport", "urn:xmpp:jingle:transports:ibb:1");
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
index 55700609..77a73643 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
@@ -7,18 +7,18 @@ public class JinglePacket extends IqPacket {
Content content = null;
Reason reason = null;
Element jingle = new Element("jingle");
-
+
@Override
public Element addChild(Element child) {
if ("jingle".equals(child.getName())) {
Element contentElement = child.findChild("content");
- if (contentElement!=null) {
+ if (contentElement != null) {
this.content = new Content();
this.content.setChildren(contentElement.getChildren());
this.content.setAttributes(contentElement.getAttributes());
}
Element reasonElement = child.findChild("reason");
- if (reasonElement!=null) {
+ if (reasonElement != null) {
this.reason = new Reason();
this.reason.setChildren(reasonElement.getChildren());
this.reason.setAttributes(reasonElement.getAttributes());
@@ -27,33 +27,33 @@ public class JinglePacket extends IqPacket {
}
return child;
}
-
+
public JinglePacket setContent(Content content) {
this.content = content;
return this;
}
-
+
public Content getJingleContent() {
- if (this.content==null) {
+ if (this.content == null) {
this.content = new Content();
}
return this.content;
}
-
+
public JinglePacket setReason(Reason reason) {
this.reason = reason;
return this;
}
-
+
public Reason getReason() {
return this.reason;
}
-
+
private void build() {
this.children.clear();
this.jingle.clearChildren();
this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
- if (this.content!=null) {
+ if (this.content != null) {
jingle.addChild(this.content);
}
if (this.reason != null) {
@@ -66,11 +66,11 @@ public class JinglePacket extends IqPacket {
public String getSessionId() {
return this.jingle.getAttribute("sid");
}
-
+
public void setSessionId(String sid) {
this.jingle.setAttribute("sid", sid);
}
-
+
@Override
public String toString() {
this.build();
@@ -80,11 +80,11 @@ public class JinglePacket extends IqPacket {
public void setAction(String action) {
this.jingle.setAttribute("action", action);
}
-
+
public String getAction() {
return this.jingle.getAttribute("action");
}
-
+
public void setInitiator(String initiator) {
this.jingle.setAttribute("initiator", initiator);
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java
index 195e0db7..610d5e76 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java
@@ -6,7 +6,7 @@ public class Reason extends Element {
private Reason(String name) {
super(name);
}
-
+
public Reason() {
super("reason");
}