share service via http hidden service
This commit is contained in:
parent
667fa647c7
commit
442216fd2e
|
@ -1,6 +1,7 @@
|
||||||
package org.torproject.android.share;
|
package org.torproject.android.share;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
@ -24,10 +25,14 @@ import android.database.Cursor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class ShareService implements Container {
|
public class ShareService implements Container, Runnable {
|
||||||
|
|
||||||
private final static String TAG = "OrbotShare";
|
private final static String TAG = "OrbotShare";
|
||||||
|
|
||||||
|
private final static String LOCALHOST = "127.0.0.1";
|
||||||
|
private int mPort = -1;
|
||||||
|
private Thread thread = null;
|
||||||
|
|
||||||
public static class Task implements Runnable {
|
public static class Task implements Runnable {
|
||||||
|
|
||||||
private final Response response;
|
private final Response response;
|
||||||
|
@ -41,12 +46,17 @@ public class ShareService implements Container {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// android.os.Debug.waitForDebugger();
|
||||||
|
|
||||||
Path path = request.getPath();
|
Path path = request.getPath();
|
||||||
String rPath = path.toString();
|
String rPath = path.toString();
|
||||||
if (rPath.length() > 0)
|
if (rPath.length() > 0)
|
||||||
rPath = rPath.substring(1);
|
rPath = rPath.substring(1);
|
||||||
|
|
||||||
ShareItem sItem = sShareItems.get(rPath);
|
ShareItem sItem = null;
|
||||||
|
|
||||||
|
if (sShareItems != null)
|
||||||
|
sItem = sShareItems.get(rPath);
|
||||||
|
|
||||||
if (sItem != null)
|
if (sItem != null)
|
||||||
{
|
{
|
||||||
|
@ -106,6 +116,13 @@ public class ShareService implements Container {
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.e(TAG,"error handling request",e);
|
Log.e(TAG,"error handling request",e);
|
||||||
|
try {
|
||||||
|
response.setCode(500);
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,11 +141,25 @@ public class ShareService implements Container {
|
||||||
|
|
||||||
public void startService (int port) throws Exception {
|
public void startService (int port) throws Exception {
|
||||||
|
|
||||||
mServer = new ContainerServer(this);
|
mPort = port;
|
||||||
mConnection = new SocketConnection(mServer);
|
thread = new Thread(this);
|
||||||
SocketAddress address = new InetSocketAddress(port);
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
mConnection.connect(address);
|
public void run ()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mServer = new ContainerServer(this);
|
||||||
|
mConnection = new SocketConnection(mServer);
|
||||||
|
SocketAddress address = new InetSocketAddress("0.0.0.0", mPort);
|
||||||
|
|
||||||
|
mConnection.connect(address);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.e(TAG,"error starting share service!",e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopService () throws Exception {
|
public void stopService () throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue