Skip to content
Snippets Groups Projects
Commit 0a9941d4 authored by Nick Mathewson's avatar Nick Mathewson :family:
Browse files

fix most torctl issues; move rest into TODO

parent 04ac0755
No related branches found
No related tags found
No related merge requests found
// $Id$
// Copyright 2005 Nick Mathewson, Roger Dingledine
// See LICENSE file for copying information
package net.freehaven.tor.control;
/** A single key-value pair from Tor's configuration. */
public class ConfigEntry {
public ConfigEntry(String k, String v) {
key = k;
value = v;
}
public final String key;
public final String value;
}
......@@ -15,6 +15,12 @@ import java.util.Map;
/** A connection to a running Tor process. */
public abstract class TorControlConnection// implements TorControlCommands {
{
public static class ConfigEntry {
public ConfigEntry(String k, String v) { key = k; value = v; }
public final String key;
public final String value;
}
protected EventHandler handler;
protected LinkedList waiters;
......@@ -137,15 +143,14 @@ public abstract class TorControlConnection// implements TorControlCommands {
public abstract void setConf(Collection kvList) throws IOException;
/** Return the value of the configuration option 'key' */
public String getConf(String key) throws IOException {
public List getConf(String key) throws IOException {
List lst = new ArrayList();
lst.add(key);
Map r = getConf(lst);
return (String) r.get(key);
return getConf(lst);
}
/** Return a key-value map for the configuration options in 'keys' */
public abstract Map getConf(Collection keys) throws IOException;
public abstract List getConf(Collection keys) throws IOException;
/** Tell Tor to begin sending us events of the types listed in 'events'.
* Elements must be one of the EVENT_* values from TorControlCommands */
......
......@@ -249,7 +249,7 @@ public class TorControlConnection0 extends TorControlConnection
sendAndWaitForResponse(CMD_SETCONF, b.toString().getBytes());
}
public Map getConf(Collection keys) throws IOException {
public List getConf(Collection keys) throws IOException {
StringBuffer s = new StringBuffer();
for (Iterator it = keys.iterator(); it.hasNext(); ) {
String key = (String) it.next();
......@@ -259,12 +259,12 @@ public class TorControlConnection0 extends TorControlConnection
CMD_CONFVALUE);
List lines = new ArrayList();
Bytes.splitStr(lines, c.body, 0, (byte)'\n');
Map result = new HashMap();
List result = new ArrayList();
for (Iterator it = lines.iterator(); it.hasNext(); ) {
String kv = (String) it.next();
int idx = kv.indexOf(' ');
result.put(kv.substring(0, idx),
kv.substring(idx+1));
result.add(new ConfigEntry(kv.substring(0, idx),
kv.substring(idx+1)));
}
return result;
}
......
......@@ -218,7 +218,7 @@ public class TorControlConnection1 extends TorControlConnection
sendAndWaitForResponse(b.toString(), null);
}
public Map getConf(Collection keys) throws IOException {
public List getConf(Collection keys) throws IOException {
StringBuffer sb = new StringBuffer("GETCONF");
for (Iterator it = keys.iterator(); it.hasNext(); ) {
String key = (String) it.next();
......@@ -226,12 +226,12 @@ public class TorControlConnection1 extends TorControlConnection
}
sb.append("\r\n");
ArrayList lst = sendAndWaitForResponse(sb.toString(), null);
Map result = new HashMap();
ArrayList result = new ArrayList();
for (Iterator it = lst.iterator(); it.hasNext(); ) {
String kv = ((ReplyLine) it.next()).msg;
int idx = kv.indexOf('=');
result.put(kv.substring(0, idx),
kv.substring(idx+1));
result.add(new ConfigEntry(kv.substring(0, idx),
kv.substring(idx+1)));
}
return result;
}
......
......@@ -7,6 +7,7 @@ import net.freehaven.tor.control.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import java.util.Iterator;
......@@ -83,11 +84,11 @@ public class Main implements TorControlCommands {
public static void getConfig(String[] args) throws IOException {
// Usage: get-config key key key
TorControlConnection conn = getConnection(args);
Map m = conn.getConf(Arrays.asList(args).subList(1,args.length));
for (Iterator i = m.entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
System.out.println("KEY: "+e.getKey());
System.out.println("VAL: "+e.getValue());
List lst = conn.getConf(Arrays.asList(args).subList(1,args.length));
for (Iterator i = lst.iterator(); i.hasNext(); ) {
ConfigEntry e = (ConfigEntry) i.next();
System.out.println("KEY: "+e.key);
System.out.println("VAL: "+e.value);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment