[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2264: Add some getConf() and getInfo() methods that return QVarian (in trunk: . src/torcontrol)
Author: edmanm
Date: 2007-12-27 11:34:35 -0500 (Thu, 27 Dec 2007)
New Revision: 2264
Modified:
trunk/
trunk/src/torcontrol/torcontrol.cpp
trunk/src/torcontrol/torcontrol.h
Log:
r2377@lysithea: edmanm | 2007-12-26 23:37:40 -0500
Add some getConf() and getInfo() methods that return QVariants or
QVariantMaps. Soon I would like to change all getConf() or getInfo() callers
use these methods and get rid of the other overloads.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /local/vidalia/trunk [r2377] on 0108964c-5b0b-4c9e-969f-e2288315d100
Modified: trunk/src/torcontrol/torcontrol.cpp
===================================================================
--- trunk/src/torcontrol/torcontrol.cpp 2007-12-27 16:34:19 UTC (rev 2263)
+++ trunk/src/torcontrol/torcontrol.cpp 2007-12-27 16:34:35 UTC (rev 2264)
@@ -397,6 +397,52 @@
return false;
}
+/** Sends a GETINFO message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+QVariantMap
+TorControl::getInfo(const QStringList &keys, QString *errmsg)
+{
+ ControlCommand cmd("GETINFO");
+ ControlReply reply;
+ QVariantMap infoMap;
+
+ cmd.addArguments(keys);
+ if (!send(cmd, reply, errmsg))
+ return QVariantMap();
+
+ foreach (ReplyLine line, reply.getLines()) {
+ QString msg = line.getMessage();
+ int index = msg.indexOf("=");
+ QString key = msg.mid(0, index);
+ QStringList val;
+
+ if (index > 0 && index < msg.length()-1)
+ val << msg.mid(index+1);
+ if (line.hasData())
+ val << line.getData();
+
+ if (infoMap.contains(key)) {
+ QStringList values = infoMap.value(key).toStringList();
+ values << val;
+ infoMap.insert(key, values);
+ } else {
+ infoMap.insert(key, val);
+ }
+ }
+ return infoMap;
+}
+
+/** Sends a GETINFO message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+QVariant
+TorControl::getInfo(const QString &key, QString *errmsg)
+{
+ QVariantMap map = getInfo(QStringList() << key, errmsg);
+ return map.value(key);
+}
+
/** Overloaded method to send a GETINFO command for a single info value */
bool
TorControl::getInfo(QString key, QString &val, QString *errmsg)
@@ -706,6 +752,50 @@
return false;
}
+/** Sends a GETICONF message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+QVariantMap
+TorControl::getConf(const QStringList &keys, QString *errmsg)
+{
+ ControlCommand cmd("GETCONF");
+ ControlReply reply;
+ QVariantMap confMap;
+
+ cmd.addArguments(keys);
+ if (!send(cmd, reply, errmsg))
+ return QVariantMap();
+
+ foreach (ReplyLine line, reply.getLines()) {
+ QString msg = line.getMessage();
+ int index = msg.indexOf("=");
+ QString key = msg.mid(0, index);
+ QString val;
+
+ if (index > 0 && index < msg.length()-1)
+ val = msg.mid(index+1);
+
+ if (confMap.contains(key)) {
+ QStringList values = confMap.value(key).toStringList();
+ values << val;
+ confMap.insert(key, values);
+ } else {
+ confMap.insert(key, val);
+ }
+ }
+ return confMap;
+}
+
+/** Sends a GETCONF message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+QVariant
+TorControl::getConf(const QString &key, QString *errmsg)
+{
+ QVariantMap map = getConf(QStringList() << key, errmsg);
+ return map.value(key);
+}
+
/** Asks Tor to save the current configuration to its torrc. */
bool
TorControl::saveConf(QString *errmsg)
Modified: trunk/src/torcontrol/torcontrol.h
===================================================================
--- trunk/src/torcontrol/torcontrol.h 2007-12-27 16:34:19 UTC (rev 2263)
+++ trunk/src/torcontrol/torcontrol.h 2007-12-27 16:34:35 UTC (rev 2264)
@@ -32,6 +32,7 @@
#include <QHash>
#include <QList>
#include <QStringList>
+#include <QVariant>
#include "controlconnection.h"
#include "torprocess.h"
@@ -88,6 +89,16 @@
/** Sends a GETINFO message for a single info value to Tor */
bool getInfo(QString key, QString &val, QString *errmsg = 0);
+ /** Sends a GETINFO message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+ QVariantMap getInfo(const QStringList &keys, QString *errmsg = 0);
+ /** Sends a GETINFO message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+ QVariant getInfo(const QString &key, QString *errmsg = 0);
+
+
/** Sends a signal to Tor */
bool signal(TorSignal::Signal sig, QString *errmsg = 0);
@@ -133,6 +144,16 @@
bool getConf(QString key, QString &value, QString *errmsg = 0);
/** Gets a list of configuration values for <b>key</b>. */
bool getConf(QString key, QStringList &value, QString *errmsg = 0);
+
+ /** Sends a GETCONF message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+ QVariantMap getConf(const QStringList &keys, QString *errmsg = 0);
+ /** Sends a GETCONF message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+ QVariant getConf(const QString &key, QString *errmsg = 0);
+
/** Asks Tor to save the current configuration to its torrc */
bool saveConf(QString *errmsg = 0);
/** Tells Tor to reset the given configuration keys back to defaults. */