summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-04-30 22:56:09 +0200
committerArne Schwabe <arne@rfc2549.org>2012-04-30 22:56:09 +0200
commit370fa3686c7bfa74ed4b26c253ad0ba391bd34c4 (patch)
tree375f387d4f4cc0a3e39e86d9b6f86155e3dbae84 /src/de/blinkt/openvpn
parent273e83fee509d80f3bd0fd485dd0c49f7c12c32a (diff)
Version 0.4.6 - Codename "Welcome to the world people in 2012, where we use CIDR"
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java105
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java9
2 files changed, 80 insertions, 34 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 16f54b1..f600488 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -10,6 +10,7 @@ import android.os.Handler.Callback;
import android.os.Message;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
@@ -18,33 +19,42 @@ import android.widget.TextView;
import de.blinkt.openvpn.OpenVPN.LogListener;
public class LogWindow extends ListActivity {
-
+
class LogWindowListAdapter implements ListAdapter,LogListener, Callback {
+ private static final int MESSAGE_NEWLOG = 0;
+
+ private static final int MESSAGE_CLEARLOG = 1;
+
private Vector<String> myEntries=new Vector<String>();
-
+
private Handler mHandler;
private Vector<DataSetObserver> observers=new Vector<DataSetObserver>();
public LogWindowListAdapter() {
+ initLogBuffer();
+
+ if (mHandler == null) {
+ mHandler = new Handler(this);
+ }
+
+ OpenVPN.addLogListener(this);
+ }
+
+ private void initLogBuffer() {
+ myEntries.clear();
for (String litem : OpenVPN.getlogbuffer()) {
myEntries.add(litem);
}
-
- if (mHandler == null) {
- mHandler = new Handler(this);
- }
-
- OpenVPN.addLogListener(this);
}
-
+
@Override
public void registerDataSetObserver(DataSetObserver observer) {
observers.add(observer);
-
+
}
-
+
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
observers.remove(observer);
@@ -94,7 +104,7 @@ public class LogWindow extends ListActivity {
@Override
public boolean isEmpty() {
return myEntries.isEmpty();
-
+
}
@Override
@@ -110,6 +120,7 @@ public class LogWindow extends ListActivity {
@Override
public void newLog(String logmessage) {
Message msg = Message.obtain();
+ msg.what=MESSAGE_NEWLOG;
Bundle mbundle=new Bundle();
mbundle.putString("logmessage", logmessage);
msg.setData(mbundle);
@@ -119,39 +130,67 @@ public class LogWindow extends ListActivity {
@Override
public boolean handleMessage(Message msg) {
// We have been called
- String logmessage = msg.getData().getString("logmessage");
- myEntries.add(logmessage);
+ if(msg.what==MESSAGE_NEWLOG) {
+
+ String logmessage = msg.getData().getString("logmessage");
+ myEntries.add(logmessage);
- for (DataSetObserver observer : observers) {
- observer.onChanged();
+ for (DataSetObserver observer : observers) {
+ observer.onChanged();
+ }
+ } else if (msg.what == MESSAGE_CLEARLOG) {
+ initLogBuffer();
+ for (DataSetObserver observer : observers) {
+ observer.onInvalidated();
+ }
}
-
-
+
return true;
}
-
+
+ void clearLog() {
+ OpenVPN.clearLog();
+ OpenVPN.logMessage(0,"","Log cleared.");
+ mHandler.sendEmptyMessage(MESSAGE_CLEARLOG);
+ }
+
+ }
+
+
+
+ private LogWindowListAdapter ladapter;
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(item.getItemId()==R.id.clearlog) {
+ ladapter.clearLog();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.logmenu, menu);
- return true;
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.logmenu, menu);
+ return true;
}
-
-
+
+
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- ListView lv = getListView();
- //lv.setTextFilterEnabled(true);
- LogWindowListAdapter adapter = new LogWindowListAdapter();
- lv.setAdapter(adapter);
+ super.onCreate(savedInstanceState);
+
+ ListView lv = getListView();
+ //lv.setTextFilterEnabled(true);
+ ladapter = new LogWindowListAdapter();
+ lv.setAdapter(ladapter);
+
+ }
+
- }
-
-
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 8da49ba..442fd94 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -202,7 +202,11 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
for (CIDRIP route:mRoutes) {
- builder.addRoute(route.mIp, route.len);
+ try {
+ builder.addRoute(route.mIp, route.len);
+ } catch (IllegalArgumentException ia) {
+ OpenVPN.logMessage(0, "", getString(R.string.route_rejected) + route + " " + ia.getLocalizedMessage());
+ }
}
if(mDomain!=null)
@@ -243,6 +247,9 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
public void setLocalIP(String local, String netmask) {
mLocalIP = new CIDRIP(local, netmask);
+ if(mLocalIP.len == 32 && !netmask.equals("255.255.255.255")) {
+ OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask)));
+ }
}