aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-11 22:49:26 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-11 22:49:26 +0200
commit259bb446cac55ea7367488dfd63eb2b8a3eb6139 (patch)
tree7cbbe509a955bd4b2b1820f33a24d8b8045bd801 /src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
parentc0e0a7086902a9d5cfbe88c4aa220abdf2ee3dde (diff)
first file transfer between gajim and conversations. still a lot to do though
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java b/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
index 5c36d66f..c1219ff7 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
@@ -1,5 +1,8 @@
package eu.siacs.conversations.xmpp.jingle;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -18,13 +21,18 @@ public class SocksConnection {
private JingleConnection jingleConnection;
private Socket socket;
private String host;
+ private String jid;
private int port;
+ private boolean isProxy = false;
private String destination;
+ private OutputStream outputStream;
- public SocksConnection(JingleConnection jingleConnection, String host, int port) {
+ public SocksConnection(JingleConnection jingleConnection, String host, String jid, int port, String type) {
this.jingleConnection = jingleConnection;
this.host = host;
+ this.jid = jid;
this.port = port;
+ this.isProxy = "proxy".equalsIgnoreCase(type);
try {
MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
StringBuilder destBuilder = new StringBuilder();
@@ -32,7 +40,6 @@ public class SocksConnection {
destBuilder.append(jingleConnection.getInitiator());
destBuilder.append(jingleConnection.getResponder());
mDigest.reset();
- Log.d("xmppService","plain destination: "+destBuilder.toString());
this.destination = CryptoHelper.bytesToHex(mDigest.digest(destBuilder.toString().getBytes()));
Log.d("xmppService","host="+host+", port="+port+", destination: "+destination);
} catch (NoSuchAlgorithmException e) {
@@ -44,15 +51,15 @@ public class SocksConnection {
try {
this.socket = new Socket(this.host, this.port);
InputStream is = socket.getInputStream();
- OutputStream os = socket.getOutputStream();
+ this.outputStream = socket.getOutputStream();
byte[] login = {0x05, 0x01, 0x00};
byte[] expectedReply = {0x05,0x00};
byte[] reply = new byte[2];
- os.write(login);
+ this.outputStream.write(login);
is.read(reply);
if (Arrays.equals(reply, expectedReply)) {
String connect = ""+'\u0005'+'\u0001'+'\u0000'+'\u0003'+'\u0028'+this.destination+'\u0000'+'\u0000';
- os.write(connect.getBytes());
+ this.outputStream.write(connect.getBytes());
byte[] result = new byte[2];
is.read(result);
int status = result[0];
@@ -67,4 +74,40 @@ public class SocksConnection {
return false;
}
}
+
+ public void send(File file) {
+ FileInputStream fileInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(file);
+ int count;
+ byte[] buffer = new byte[8192];
+ while ((count = fileInputStream.read(buffer)) > 0) {
+ this.outputStream.write(buffer, 0, count);
+ }
+
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fileInputStream!=null) {
+ fileInputStream.close();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public boolean isProxy() {
+ return this.isProxy;
+ }
+
+ public String getJid() {
+ return this.jid;
+ }
}