[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] make v0 connections handle lists of event names.
Update of /home/or/cvsroot/control/java/net/freehaven/tor/control
In directory moria:/tmp/cvs-serv11903/java/net/freehaven/tor/control
Modified Files:
TorControlConnection0.java
Log Message:
make v0 connections handle lists of event names.
Index: TorControlConnection0.java
===================================================================
RCS file: /home/or/cvsroot/control/java/net/freehaven/tor/control/TorControlConnection0.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- TorControlConnection0.java 14 Jul 2005 20:26:11 -0000 1.5
+++ TorControlConnection0.java 20 Jul 2005 22:55:41 -0000 1.6
@@ -274,8 +274,22 @@
int i;
Iterator it;
for(i=0, it = events.iterator(); it.hasNext(); i += 2) {
- short event = ((Number)it.next()).shortValue();
- Bytes.setU16(ba, i, event);
+ Object event = it.next();
+ short e = -1;
+ if (event instanceof Number) {
+ e = ((Number)event).shortValue();
+ } else {
+ String s = ((String) event).toUpperCase();
+ for (int j = 0; i < EVENT_NAMES.length; ++i) {
+ if (EVENT_NAMES[j].equals(s)) {
+ e = (short)j;
+ break;
+ }
+ }
+ if (e < 0)
+ throw new Error("Unknown v0 code for event '"+s+"'");
+ }
+ Bytes.setU16(ba, i, e);
}
sendAndWaitForResponse(CMD_SETEVENTS, ba);
System.out.println("OK");