[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] fix debugging and listenforevents API a little



Update of /home/or/cvsroot/control/java/net/freehaven/tor/control
In directory moria:/tmp/cvs-serv11597/java/net/freehaven/tor/control

Modified Files:
	TorControlCommands.java TorControlConnection1.java 
Log Message:
fix debugging and listenforevents API a little

Index: TorControlCommands.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlCommands.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TorControlCommands.java	24 Jun 2005 18:03:27 -0000	1.2
+++ TorControlCommands.java	20 Jul 2005 22:48:34 -0000	1.3
@@ -65,6 +65,21 @@
     public static final short EVENT_MSG_WARN = 0x000A;
     public static final short EVENT_MSG_ERROR = 0x000B;
 
+    public static final String[] EVENT_NAMES = {
+        "(0)",
+        "CIRC",
+        "STREAM",
+        "ORCONN",
+        "BW",
+        "OLDLOG",
+        "NEWDESC",
+        "DEBUG",
+        "INFO",
+        "NOTICE",
+        "WARN",
+        "ERR",
+    };
+
     public static final byte CIRC_STATUS_LAUNCHED = 0x01;
     public static final byte CIRC_STATUS_BUILT = 0x02;
     public static final byte CIRC_STATUS_EXTENDED = 0x03;

Index: TorControlConnection1.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection1.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- TorControlConnection1.java	20 Jul 2005 22:30:58 -0000	1.5
+++ TorControlConnection1.java	20 Jul 2005 22:48:34 -0000	1.6
@@ -70,10 +70,12 @@
             else
                 line += "\r\n";
             if (debugOutput != null)
-                debugOutput.print("<< "+line);
+                debugOutput.print(">> "+line);
             output.write(line);
         }
         output.write(".\r\n");
+        if (debugOutput != null)
+            debugOutput.print(">> .\n");
     }
 
     protected static final String quote(String s) {
@@ -100,7 +102,7 @@
         do {
             String line = input.readLine();
             if (debugOutput != null)
-                debugOutput.print(">> "+line);
+                debugOutput.println("<< "+line);
             if (line.length() < 4)
                 throw new TorControlSyntaxError("Line (\""+line+"\") too short");
             String status = line.substring(0,3);
@@ -112,7 +114,7 @@
                 while (true) {
                     line = input.readLine();
                     if (debugOutput != null)
-                        debugOutput.print(">> "+line);
+                        debugOutput.print("<< "+line);
                     if (line.equals("."))
                         break;
                     else if (line.startsWith("."))
@@ -148,7 +150,7 @@
         checkThread();
         Waiter w = new Waiter();
         if (debugOutput != null)
-            debugOutput.println("<< "+s);
+            debugOutput.print(">> "+s);
         synchronized (waiters) {
             output.write(s);
             output.flush();
@@ -231,10 +233,10 @@
         if (w instanceof java.io.PrintWriter)
             debugOutput = (java.io.PrintWriter) w;
         else
-            debugOutput = new java.io.PrintWriter(w);
+            debugOutput = new java.io.PrintWriter(w, true);
     }
     public void setDebugging(java.io.PrintStream s) {
-        debugOutput = new java.io.PrintWriter(s);
+        debugOutput = new java.io.PrintWriter(s, true);
     }
 
     public List getConf(Collection keys) throws IOException {
@@ -258,8 +260,13 @@
     public void setEvents(List events) throws IOException {
         StringBuffer sb = new StringBuffer("SETEVENTS");
         for (Iterator it = events.iterator(); it.hasNext(); ) {
-            String event = (String) it.next();
-            sb.append(" ").append(event);
+            Object event = it.next();
+            if (event instanceof String) {
+                sb.append(" ").append((String)event);
+            } else {
+                int i = ((Number) event).intValue();
+                sb.append(" ").append(EVENT_NAMES[i]);
+            }
         }
         sb.append("\r\n");
         sendAndWaitForResponse(sb.toString(), null);