summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/OpenVPN.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-06-13 23:23:49 +0200
committerArne Schwabe <arne@rfc2549.org>2012-06-13 23:23:49 +0200
commit6709f66650ec4cc4a22d7bb4d0e809eab119cbe9 (patch)
treee67897cf3097900838ba68296b8a9a6be941b593 /src/de/blinkt/openvpn/OpenVPN.java
parent7dfa673e931656924ce4a85bec84441c46c5a5f5 (diff)
Correct network state message
Improve logging framework a bit Add logging of certificates received from Keystore
Diffstat (limited to 'src/de/blinkt/openvpn/OpenVPN.java')
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java85
1 files changed, 73 insertions, 12 deletions
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index 55e15abc..39533db3 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -3,21 +3,67 @@ package de.blinkt.openvpn;
import java.util.LinkedList;
import java.util.Vector;
+import android.content.Context;
+
public class OpenVPN {
+
+ static class LogItem {
+ public static final int ERROR = 1;
+ public static final int INFO = 2;
+ public static final int VERBOSE = 3;
+
+ private Object [] mArgs = null;
+ private String mMessage = null;
+ private int mRessourceId;
+ // Default log priority
+ int mLevel = INFO;
+
+ public LogItem(int ressourceId, Object[] args) {
+ mRessourceId = ressourceId;
+ mArgs = args;
+ }
+
+
+ public LogItem(int loglevel,int ressourceId, Object[] args) {
+ mRessourceId = ressourceId;
+ mArgs = args;
+ mLevel = loglevel;
+ }
+
+
+ public LogItem(String message) {
+ mMessage = message;
+ }
+
+ String getString(Context c) {
+ if(mMessage !=null) {
+ return mMessage;
+ } else {
+ if(mArgs == null)
+ return c.getString(mRessourceId);
+ else
+ return c.getString(mRessourceId,mArgs);
+ }
+ }
+ }
+
private static final int MAXLOGENTRIES = 200;
public static final String MANAGMENT_PREFIX = "M:";
- public static LinkedList<String> logbuffer = new LinkedList<String>();
+
+
+
+ public static LinkedList<LogItem> logbuffer = new LinkedList<LogItem>();
private static Vector<LogListener> logListener=new Vector<OpenVPN.LogListener>();
private static Vector<StateListener> stateListener=new Vector<OpenVPN.StateListener>();
private static String[] mBconfig;
public interface LogListener {
- void newLog(String logmessage);
+ void newLog(LogItem logItem);
}
public interface StateListener {
@@ -26,13 +72,7 @@ public class OpenVPN {
synchronized static void logMessage(int level,String prefix, String message)
{
- logbuffer.addLast(prefix + message);
- if(logbuffer.size()>MAXLOGENTRIES)
- logbuffer.removeFirst();
-
- for (LogListener ll : logListener) {
- ll.newLog(prefix + message);
- }
+ newlogItem(new LogItem(prefix + message));
}
@@ -59,15 +99,15 @@ public class OpenVPN {
- synchronized public static String[] getlogbuffer() {
+ synchronized public static LogItem[] getlogbuffer() {
// The stoned way of java to return an array from a vector
// brought to you by eclipse auto complete
- return (String[]) logbuffer.toArray(new String[logbuffer.size()]);
+ return (LogItem[]) logbuffer.toArray(new LogItem[logbuffer.size()]);
}
public static void logBuilderConfig(String[] bconfig) {
- mBconfig =bconfig;
+ mBconfig = bconfig;
}
public static void triggerLogBuilderConfig() {
if(mBconfig==null) {
@@ -85,4 +125,25 @@ public class OpenVPN {
sl.updateState(msg);
}
}
+
+ public static void logInfo(String message) {
+
+ }
+
+ public static void logInfo(int ressourceId, Object... args) {
+ newlogItem(new LogItem(LogItem.INFO, ressourceId, args));
+ }
+
+ private static void newlogItem(LogItem logItem) {
+ logbuffer.addLast(logItem);
+ if(logbuffer.size()>MAXLOGENTRIES)
+ logbuffer.removeFirst();
+
+ for (LogListener ll : logListener) {
+ ll.newLog(logItem);
+ }
+ }
+
+
+
}