[tor-commits] [vidalia/alpha] Migrate from a hand made TorControl prototype to an extension
chiiph at torproject.org
chiiph at torproject.org
Thu Jun 14 22:42:08 UTC 2012
commit fd6260a279be96d9e8315312b7543902432ed75b
Author: Tomás Touceda <chiiph at torproject.org>
Date: Wed Jun 13 13:50:41 2012 -0300
Migrate from a hand made TorControl prototype to an extension
qtscript_TorControl is equivalent to TorControlPrototype only that it
was generated by qtscriptgenerator
---
changes/migrateToExtensions | 3 +
src/vidalia/CMakeLists.txt | 6 +-
src/vidalia/plugin/PluginEngine.cpp | 5 +-
src/vidalia/plugin/PluginEngine.h | 1 -
.../plugin/extensions/VidaliaExtensions.cpp | 26 +
src/vidalia/plugin/extensions/VidaliaExtensions.h | 17 +
.../plugin/extensions/VidaliaExtensionsInit.cpp | 25 +
.../plugin/extensions/qtscript_TorControl.cpp | 704 ++++++++++++++++++++
.../plugin/prototypes/TorControlPrototype.cpp | 379 -----------
.../plugin/prototypes/TorControlPrototype.h | 356 ----------
10 files changed, 783 insertions(+), 739 deletions(-)
diff --git a/changes/migrateToExtensions b/changes/migrateToExtensions
new file mode 100644
index 0000000..36c6a3b
--- /dev/null
+++ b/changes/migrateToExtensions
@@ -0,0 +1,3 @@
+ Internal cleanups and improvements:
+ o Migrate from the hand made TorControl prototype for QtScript to an
+ automatically generated equivalent with qtscriptgenerator.
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 23b5464..312191d 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -23,6 +23,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/network
${CMAKE_CURRENT_SOURCE_DIR}/plugin
${CMAKE_CURRENT_SOURCE_DIR}/plugin/prototypes
+ ${CMAKE_CURRENT_SOURCE_DIR}/plugin/extensions
${MARBLE_INCLUDE_DIR}
)
@@ -90,8 +91,10 @@ set(vidalia_SRCS ${vidalia_SRCS}
plugin/DebugDialog.cpp
plugin/prototypes/VidaliaTabPrototype.cpp
plugin/prototypes/HelperProcessPrototype.cpp
- plugin/prototypes/TorControlPrototype.cpp
plugin/prototypes/TorrcPrototype.cpp
+ plugin/extensions/VidaliaExtensions.cpp
+ plugin/extensions/VidaliaExtensionsInit.cpp
+ plugin/extensions/qtscript_TorControl.cpp
)
qt4_wrap_cpp(vidalia_SRCS
plugin/PluginEngine.h
@@ -99,7 +102,6 @@ qt4_wrap_cpp(vidalia_SRCS
plugin/DebugDialog.h
plugin/prototypes/VidaliaTabPrototype.h
plugin/prototypes/HelperProcessPrototype.h
- plugin/prototypes/TorControlPrototype.h
plugin/prototypes/TorrcPrototype.h
)
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index c20424c..93d50c0 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -19,17 +19,20 @@
#include "DebugDialog.h"
#include "Vidalia.h"
+#include "VidaliaExtensions.h"
#include <unistd.h>
PluginEngine::PluginEngine(QObject *parent)
: QScriptEngine(parent)
{
+ VidaliaExtensions ve;
+ ve.initialize("vidalia", this);
+
ADD_PROTOTYPE(VidaliaTabPrototype)
MAKE_CREATABLE(VidaliaTabPrototype)
ADD_PROTOTYPE(HelperProcessPrototype)
MAKE_CREATABLE(HelperProcessPrototype)
- ADD_PROTOTYPE(TorControlPrototype)
ADD_PROTOTYPE(TorrcPrototype)
globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 83a3d6f..b8b65aa 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -21,7 +21,6 @@
#include "VidaliaTabPrototype.h"
#include "HelperProcessPrototype.h"
-#include "TorControlPrototype.h"
#include "TorrcPrototype.h"
class PluginWrapper;
diff --git a/src/vidalia/plugin/extensions/VidaliaExtensions.cpp b/src/vidalia/plugin/extensions/VidaliaExtensions.cpp
new file mode 100644
index 0000000..7bb85f6
--- /dev/null
+++ b/src/vidalia/plugin/extensions/VidaliaExtensions.cpp
@@ -0,0 +1,26 @@
+#include <QtScript/QScriptExtensionPlugin>
+#include <QtScript/QScriptValue>
+#include <QtScript/QScriptEngine>
+
+#include <QDebug>
+
+#include "VidaliaExtensions.h"
+
+void vidalia_initialize_bindings(QScriptValue &);
+
+QStringList VidaliaExtensions::keys() const
+{
+ return QStringList() << "vidalia";
+}
+
+void VidaliaExtensions::initialize(const QString &key, QScriptEngine *engine)
+{
+ if (key == QLatin1String("vidalia")) {
+ QScriptValue extensionObject = engine->globalObject();
+ vidalia_initialize_bindings(extensionObject);
+ } else {
+ Q_ASSERT_X(false, "vidalia::initialize", qPrintable(key));
+ }
+}
+
+Q_EXPORT_PLUGIN2(vidalia_extensions, VidaliaExtensions)
diff --git a/src/vidalia/plugin/extensions/VidaliaExtensions.h b/src/vidalia/plugin/extensions/VidaliaExtensions.h
new file mode 100644
index 0000000..b3e9ed3
--- /dev/null
+++ b/src/vidalia/plugin/extensions/VidaliaExtensions.h
@@ -0,0 +1,17 @@
+#ifndef VIDALIAEXTENSIONS_H
+#define VIDALIAEXTENSIONS_H
+
+#include <QtCore>
+#include <QtScript/QScriptExtensionPlugin>
+#include <QtScript/QScriptValue>
+#include <QtScript/QScriptEngine>
+
+class VidaliaExtensions : public QScriptExtensionPlugin
+{
+public:
+ void initialize(const QString &key, QScriptEngine *engine);
+ QStringList keys() const;
+};
+
+
+#endif // VIDALIAEXTENSIONS_H
diff --git a/src/vidalia/plugin/extensions/VidaliaExtensionsInit.cpp b/src/vidalia/plugin/extensions/VidaliaExtensionsInit.cpp
new file mode 100644
index 0000000..0dd4887
--- /dev/null
+++ b/src/vidalia/plugin/extensions/VidaliaExtensionsInit.cpp
@@ -0,0 +1,25 @@
+#include <QtScript/QScriptValue>
+#include <QtScript/QScriptEngine>
+
+const int classCount = 1;
+
+QScriptValue qtscript_create_TorControl_class(QScriptEngine *engine);
+
+static const char * const vidalia_class_names[] = {
+ "TorControl"
+};
+
+typedef QScriptValue (*QtBindingCreator)(QScriptEngine *engine);
+static const QtBindingCreator vidalia_class_functions[] = {
+ qtscript_create_TorControl_class
+};
+
+void vidalia_initialize_bindings(QScriptValue &extensionObject)
+{
+ QScriptEngine *engine = extensionObject.engine();
+ for (int i = 0; i < classCount; ++i) {
+ extensionObject.setProperty(vidalia_class_names[i],
+ vidalia_class_functions[i](engine),
+ QScriptValue::SkipInEnumeration);
+ }
+}
diff --git a/src/vidalia/plugin/extensions/qtscript_TorControl.cpp b/src/vidalia/plugin/extensions/qtscript_TorControl.cpp
new file mode 100644
index 0000000..97cb237
--- /dev/null
+++ b/src/vidalia/plugin/extensions/qtscript_TorControl.cpp
@@ -0,0 +1,704 @@
+#include <QtScript/QScriptEngine>
+#include <QtScript/QScriptContext>
+#include <QtScript/QScriptValue>
+#include <QtCore/QStringList>
+#include <QtCore/QDebug>
+#include <qmetaobject.h>
+
+#include <TorControl.h>
+#include <QVariant>
+#include <qbytearray.h>
+#include <qcoreevent.h>
+#include <qdatetime.h>
+#include <qhostaddress.h>
+#include <qlist.h>
+#include <qobject.h>
+#include <qstringlist.h>
+
+static const char * const qtscript_TorControl_function_names[] = {
+ "TorControl"
+ // static
+ // prototype
+ , "authenticate"
+ , "clearErrState"
+ , "closeTorStdout"
+ , "connect"
+ , "disconnect"
+ , "finished"
+ , "getConf"
+ , "getDescriptorAnnotations"
+ , "getHiddenServiceConf"
+ , "getInfo"
+ , "getRouterDescriptorText"
+ , "getSocksAddress"
+ , "getSocksAddressList"
+ , "getSocksPort"
+ , "getSocksPortList"
+ , "getTorVersion"
+ , "getTorVersionString"
+ , "ipToCountry"
+ , "isAuthenticated"
+ , "isCircuitEstablished"
+ , "isConnected"
+ , "isRunning"
+ , "isVidaliaRunningTor"
+ , "loadConf"
+ , "resetConf"
+ , "saveConf"
+ , "setEvents"
+ , "shouldContinue"
+ , "start"
+ , "stop"
+ , "takeOwnership"
+ , "useMicrodescriptors"
+ , "toString"
+};
+
+static const char * const qtscript_TorControl_function_signatures[] = {
+ ""
+ // static
+ // prototype
+ , "QByteArray cookie, String errmsg\nString password, String errmsg"
+ , ""
+ , ""
+ , "QHostAddress address, unsigned short port\nString path"
+ , ""
+ , "int exitCode, ExitStatus exitStatus"
+ , "HashMap map, String errmsg\nString key, List value, String errmsg\nString key, String errmsg\nList keys, String errmsg"
+ , "String id, String errmsg"
+ , "String key, String errmsg"
+ , "String key, String errmsg\nList keys, String errmsg"
+ , "String id, String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+ , ""
+ , ""
+ , "QHostAddress ip, String errmsg"
+ , ""
+ , ""
+ , ""
+ , ""
+ , ""
+ , "String contents, String errmsg"
+ , "String key, String errmsg\nList keys, String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+ , "String tor, List args"
+ , "String errmsg"
+ , "String errmsg"
+ , "String errmsg"
+""
+};
+
+static const int qtscript_TorControl_function_lengths[] = {
+ 0
+ // static
+ // prototype
+ , 2
+ , 0
+ , 0
+ , 2
+ , 0
+ , 2
+ , 3
+ , 2
+ , 2
+ , 2
+ , 2
+ , 1
+ , 1
+ , 1
+ , 1
+ , 0
+ , 0
+ , 2
+ , 0
+ , 0
+ , 0
+ , 0
+ , 0
+ , 2
+ , 2
+ , 1
+ , 1
+ , 1
+ , 2
+ , 1
+ , 1
+ , 1
+ , 0
+};
+
+static QScriptValue qtscript_TorControl_throw_ambiguity_error_helper(
+ QScriptContext *context, const char *functionName, const char *signatures)
+{
+ QStringList lines = QString::fromLatin1(signatures).split(QLatin1Char('\n'));
+ QStringList fullSignatures;
+ for (int i = 0; i < lines.size(); ++i)
+ fullSignatures.append(QString::fromLatin1("%0(%1)").arg(functionName).arg(lines.at(i)));
+ return context->throwError(QString::fromLatin1("TorControl::%0(): could not find a function match; candidates are:\n%1")
+ .arg(functionName).arg(fullSignatures.join(QLatin1String("\n"))));
+}
+
+Q_DECLARE_METATYPE(TorControl*)
+Q_DECLARE_METATYPE(QString*)
+Q_DECLARE_METATYPE(QHostAddress)
+Q_DECLARE_METATYPE(int*)
+Q_DECLARE_METATYPE(QProcess::ExitStatus*)
+template <> \
+struct QMetaTypeId< QHash<QString,QStringList> > \
+{ \
+ enum { Defined = 1 }; \
+ static int qt_metatype_id() \
+ { \
+ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
+ if (!metatype_id) \
+ metatype_id = qRegisterMetaType< QHash<QString,QStringList> >("QHash<QString,QStringList>"); \
+ return metatype_id; \
+ } \
+};
+template <> \
+struct QMetaTypeId< QHash<QString,QString> > \
+{ \
+ enum { Defined = 1 }; \
+ static int qt_metatype_id() \
+ { \
+ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
+ if (!metatype_id) \
+ metatype_id = qRegisterMetaType< QHash<QString,QString> >("QHash<QString,QString>"); \
+ return metatype_id; \
+ } \
+};
+Q_DECLARE_METATYPE(QList<unsigned short>)
+
+//
+// TorControl
+//
+
+static QScriptValue qtscript_TorControl_prototype_call(QScriptContext *context, QScriptEngine *)
+{
+#if QT_VERSION > 0x040400
+ Q_ASSERT(context->callee().isFunction());
+ uint _id = context->callee().data().toUInt32();
+#else
+ uint _id;
+ if (context->callee().isFunction())
+ _id = context->callee().data().toUInt32();
+ else
+ _id = 0xBABE0000 + 32;
+#endif
+ Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
+ _id &= 0x0000FFFF;
+ TorControl* _q_self = qscriptvalue_cast<TorControl*>(context->thisObject());
+ if (!_q_self) {
+ return context->throwError(QScriptContext::TypeError,
+ QString::fromLatin1("TorControl.%0(): this object is not a TorControl")
+ .arg(qtscript_TorControl_function_names[_id+1]));
+ }
+
+ switch (_id) {
+ case 0:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->authenticate();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ if ((qMetaTypeId<QByteArray>() == context->argument(0).toVariant().userType())) {
+ QByteArray _q_arg0 = qscriptvalue_cast<QByteArray>(context->argument(0));
+ bool _q_result = _q_self->authenticate(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isString()) {
+ QString _q_arg0 = context->argument(0).toString();
+ bool _q_result = _q_self->authenticate(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ }
+ if (context->argumentCount() == 2) {
+ if ((qMetaTypeId<QByteArray>() == context->argument(0).toVariant().userType())
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QByteArray _q_arg0 = qscriptvalue_cast<QByteArray>(context->argument(0));
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->authenticate(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isString()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->authenticate(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ }
+ break;
+
+ case 1:
+ if (context->argumentCount() == 0) {
+ _q_self->clearErrState();
+ return context->engine()->undefinedValue();
+ }
+ break;
+
+ case 2:
+ if (context->argumentCount() == 0) {
+ _q_self->closeTorStdout();
+ return context->engine()->undefinedValue();
+ }
+ break;
+
+ case 3:
+ if (context->argumentCount() == 1) {
+ QString _q_arg0 = context->argument(0).toString();
+ _q_self->connect(_q_arg0);
+ return context->engine()->undefinedValue();
+ }
+ if (context->argumentCount() == 2) {
+ QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
+ unsigned short _q_arg1 = qscriptvalue_cast<unsigned short>(context->argument(1));
+ _q_self->connect(_q_arg0, _q_arg1);
+ return context->engine()->undefinedValue();
+ }
+ break;
+
+ case 4:
+ if (context->argumentCount() == 0) {
+ _q_self->disconnect();
+ return context->engine()->undefinedValue();
+ }
+ break;
+
+ case 5:
+ if (context->argumentCount() == 2) {
+ int* _q_arg0 = qscriptvalue_cast<int*>(context->argument(0));
+ QProcess::ExitStatus* _q_arg1 = qscriptvalue_cast<QProcess::ExitStatus*>(context->argument(1));
+ bool _q_result = _q_self->finished(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 6:
+ if (context->argumentCount() == 1) {
+ if ((qMetaTypeId<QHash<QString,QStringList> >() == context->argument(0).toVariant().userType())) {
+ QHash<QString,QStringList> _q_arg0 = qscriptvalue_cast<QHash<QString,QStringList> >(context->argument(0));
+ bool _q_result = _q_self->getConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isString()) {
+ QString _q_arg0 = context->argument(0).toString();
+ QVariant _q_result = _q_self->getConf(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ QMap<QString,QVariant> _q_result = _q_self->getConf(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ }
+ if (context->argumentCount() == 2) {
+ if ((qMetaTypeId<QHash<QString,QStringList> >() == context->argument(0).toVariant().userType())
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QHash<QString,QStringList> _q_arg0 = qscriptvalue_cast<QHash<QString,QStringList> >(context->argument(0));
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->getConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isString()
+ && context->argument(1).isArray()) {
+ QString _q_arg0 = context->argument(0).toString();
+ QStringList _q_arg1;
+ qScriptValueToSequence(context->argument(1), _q_arg1);
+ bool _q_result = _q_self->getConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isString()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QVariant _q_result = _q_self->getConf(_q_arg0, _q_arg1);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QMap<QString,QVariant> _q_result = _q_self->getConf(_q_arg0, _q_arg1);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ }
+ if (context->argumentCount() == 3) {
+ QString _q_arg0 = context->argument(0).toString();
+ QStringList _q_arg1;
+ qScriptValueToSequence(context->argument(1), _q_arg1);
+ QString* _q_arg2 = qscriptvalue_cast<QString*>(context->argument(2));
+ bool _q_result = _q_self->getConf(_q_arg0, _q_arg1, _q_arg2);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 7:
+ if (context->argumentCount() == 1) {
+ QString _q_arg0 = context->argument(0).toString();
+ QHash<QString,QString> _q_result = _q_self->getDescriptorAnnotations(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 2) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QHash<QString,QString> _q_result = _q_self->getDescriptorAnnotations(_q_arg0, _q_arg1);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 8:
+ if (context->argumentCount() == 1) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString _q_result = _q_self->getHiddenServiceConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 2) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QString _q_result = _q_self->getHiddenServiceConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 9:
+ if (context->argumentCount() == 1) {
+ if (context->argument(0).isString()) {
+ QString _q_arg0 = context->argument(0).toString();
+ QVariant _q_result = _q_self->getInfo(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ QMap<QString,QVariant> _q_result = _q_self->getInfo(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ }
+ if (context->argumentCount() == 2) {
+ if (context->argument(0).isString()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QVariant _q_result = _q_self->getInfo(_q_arg0, _q_arg1);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QMap<QString,QVariant> _q_result = _q_self->getInfo(_q_arg0, _q_arg1);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ }
+ break;
+
+ case 10:
+ if (context->argumentCount() == 1) {
+ QString _q_arg0 = context->argument(0).toString();
+ QStringList _q_result = _q_self->getRouterDescriptorText(_q_arg0);
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 2) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QStringList _q_result = _q_self->getRouterDescriptorText(_q_arg0, _q_arg1);
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ break;
+
+ case 11:
+ if (context->argumentCount() == 0) {
+ QHostAddress _q_result = _q_self->getSocksAddress();
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ QHostAddress _q_result = _q_self->getSocksAddress(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 12:
+ if (context->argumentCount() == 0) {
+ QStringList _q_result = _q_self->getSocksAddressList();
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ QStringList _q_result = _q_self->getSocksAddressList(_q_arg0);
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ break;
+
+ case 13:
+ if (context->argumentCount() == 0) {
+ unsigned short _q_result = _q_self->getSocksPort();
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ unsigned short _q_result = _q_self->getSocksPort(_q_arg0);
+ return qScriptValueFromValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 14:
+ if (context->argumentCount() == 0) {
+ QList<unsigned short> _q_result = _q_self->getSocksPortList();
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ QList<unsigned short> _q_result = _q_self->getSocksPortList(_q_arg0);
+ return qScriptValueFromSequence(context->engine(), _q_result);
+ }
+ break;
+
+ case 15:
+ if (context->argumentCount() == 0) {
+ uint _q_result = _q_self->getTorVersion();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 16:
+ if (context->argumentCount() == 0) {
+ QString _q_result = _q_self->getTorVersionString();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 17:
+ if (context->argumentCount() == 1) {
+ QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
+ QString _q_result = _q_self->ipToCountry(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 2) {
+ QHostAddress _q_arg0 = qscriptvalue_cast<QHostAddress>(context->argument(0));
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ QString _q_result = _q_self->ipToCountry(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 18:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->isAuthenticated();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 19:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->isCircuitEstablished();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 20:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->isConnected();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 21:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->isRunning();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 22:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->isVidaliaRunningTor();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 23:
+ if (context->argumentCount() == 1) {
+ QString _q_arg0 = context->argument(0).toString();
+ bool _q_result = _q_self->loadConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 2) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->loadConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 24:
+ if (context->argumentCount() == 1) {
+ if (context->argument(0).isString()) {
+ QString _q_arg0 = context->argument(0).toString();
+ bool _q_result = _q_self->resetConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ bool _q_result = _q_self->resetConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ }
+ if (context->argumentCount() == 2) {
+ if (context->argument(0).isString()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QString _q_arg0 = context->argument(0).toString();
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->resetConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ } else if (context->argument(0).isArray()
+ && qscriptvalue_cast<QString*>(context->argument(1))) {
+ QStringList _q_arg0;
+ qScriptValueToSequence(context->argument(0), _q_arg0);
+ QString* _q_arg1 = qscriptvalue_cast<QString*>(context->argument(1));
+ bool _q_result = _q_self->resetConf(_q_arg0, _q_arg1);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ }
+ break;
+
+ case 25:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->saveConf();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->saveConf(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 26:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->setEvents();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->setEvents(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 27:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->shouldContinue();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->shouldContinue(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 28:
+ if (context->argumentCount() == 2) {
+ QString _q_arg0 = context->argument(0).toString();
+ QStringList _q_arg1;
+ qScriptValueToSequence(context->argument(1), _q_arg1);
+ _q_self->start(_q_arg0, _q_arg1);
+ return context->engine()->undefinedValue();
+ }
+ break;
+
+ case 29:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->stop();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->stop(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 30:
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->takeOwnership(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 31:
+ if (context->argumentCount() == 0) {
+ bool _q_result = _q_self->useMicrodescriptors();
+ return QScriptValue(context->engine(), _q_result);
+ }
+ if (context->argumentCount() == 1) {
+ QString* _q_arg0 = qscriptvalue_cast<QString*>(context->argument(0));
+ bool _q_result = _q_self->useMicrodescriptors(_q_arg0);
+ return QScriptValue(context->engine(), _q_result);
+ }
+ break;
+
+ case 32: {
+ QString result = QString::fromLatin1("TorControl");
+ return QScriptValue(context->engine(), result);
+ }
+
+ default:
+ Q_ASSERT(false);
+ }
+ return qtscript_TorControl_throw_ambiguity_error_helper(context,
+ qtscript_TorControl_function_names[_id+1],
+ qtscript_TorControl_function_signatures[_id+1]);
+}
+
+static QScriptValue qtscript_TorControl_static_call(QScriptContext *context, QScriptEngine *)
+{
+ uint _id = context->callee().data().toUInt32();
+ Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
+ _id &= 0x0000FFFF;
+ switch (_id) {
+ case 0:
+ return context->throwError(QScriptContext::TypeError,
+ QString::fromLatin1("TorControl cannot be constructed"));
+ break;
+
+ default:
+ Q_ASSERT(false);
+ }
+ return qtscript_TorControl_throw_ambiguity_error_helper(context,
+ qtscript_TorControl_function_names[_id],
+ qtscript_TorControl_function_signatures[_id]);
+}
+
+static QScriptValue qtscript_TorControl_toScriptValue(QScriptEngine *engine, TorControl* const &in)
+{
+ return engine->newQObject(in, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);
+}
+
+static void qtscript_TorControl_fromScriptValue(const QScriptValue &value, TorControl* &out)
+{
+ out = qobject_cast<TorControl*>(value.toQObject());
+}
+
+QScriptValue qtscript_create_TorControl_class(QScriptEngine *engine)
+{
+ engine->setDefaultPrototype(qMetaTypeId<TorControl*>(), QScriptValue());
+ QScriptValue proto = engine->newVariant(qVariantFromValue((TorControl*)0));
+ proto.setPrototype(engine->defaultPrototype(qMetaTypeId<QObject*>()));
+ for (int i = 0; i < 33; ++i) {
+ QScriptValue fun = engine->newFunction(qtscript_TorControl_prototype_call, qtscript_TorControl_function_lengths[i+1]);
+ fun.setData(QScriptValue(engine, uint(0xBABE0000 + i)));
+ proto.setProperty(QString::fromLatin1(qtscript_TorControl_function_names[i+1]),
+ fun, QScriptValue::SkipInEnumeration);
+ }
+
+ qScriptRegisterMetaType<TorControl*>(engine, qtscript_TorControl_toScriptValue,
+ qtscript_TorControl_fromScriptValue, proto);
+
+ QScriptValue ctor = engine->newFunction(qtscript_TorControl_static_call, proto, qtscript_TorControl_function_lengths[0]);
+ ctor.setData(QScriptValue(engine, uint(0xBABE0000 + 0)));
+
+ return ctor;
+}
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
deleted file mode 100644
index ec7799e..0000000
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
-** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If you
-** did not receive the LICENSE file with this file, you may obtain it from the
-** Vidalia source package distributed by the Vidalia Project at
-** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-** including this file, may be copied, modified, propagated, or distributed
-** except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file TorControlPrototype.cpp
-** \brief Prototype for TorControl class
-*/
-
-#include "TorControlPrototype.h"
-#include "prototypemacros.h"
-
-TorControlPrototype::TorControlPrototype()
- : QObject(), QScriptable() {}
-
-int
-TorControlPrototype::metaTypeId() {
- return qMetaTypeId<TorControl *>();
-}
-
-QString
-TorControlPrototype::name() {
- return QString("TorControl");
-}
-
-DEF_TYPE0(TorControl, void,
- start(const QString &tor, const QStringList &args),
- start(tor, args))
-
-DEF_TYPE1(TorControl, bool,
- stop(),
- stop(&errmsg))
-
-DEF_TYPE0(TorControl, bool,
- isRunning(),
- isRunning())
-
-DEF_TYPE0(TorControl, bool,
- isVidaliaRunningTor(),
- isVidaliaRunningTor())
-
-DEF_TYPE0(TorControl, void,
- closeTorStdout(),
- closeTorStdout())
-
-DEF_TYPE0(TorControl, void,
- connect(const QHostAddress &address, quint16 port),
- connect(address, port))
-
-DEF_TYPE0(TorControl, void,
- connect(const QString &path),
- connect(path))
-
-DEF_TYPE0(TorControl, void,
- disconnect(),
- disconnect())
-
-DEF_TYPE0(TorControl, bool,
- isConnected(),
- isConnected())
-
-DEF_TYPE1(TorControl, bool,
- authenticate(const QByteArray cookie),
- authenticate(cookie, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- authenticate(const QString &password),
- authenticate(password, &errmsg))
-
-// TODO: make a QVariant for this two
-//QVariant
-//TorControlPrototype::protocolInfo()
-//{
-// ProtocolInfo info;
-// QString errmsg;
-
-// GET_AND_CALL(TorControl *, protocolInfo(&errmsg), info)
-
-// return MERGE2(info, errmsg);
-//}
-
-//BootstrapStatus
-//TorControlPrototype::bootstrapStatus(QString *errmsg)
-//{
-// BootstrapStatus status;
-// QString errmsg;
-
-// GET_AND_CALL(TorControl *, protocolInfo(&errmsg), status)
-
-// return MERGE2(status, errmsg);
-//}
-
-DEF_TYPE0(TorControl, bool,
- isCircuitEstablished(),
- isCircuitEstablished())
-
-DEF_TYPE1(TorControl, bool,
- getInfo(QHash<QString,QString> &map),
- getInfo(map, &errmsg))
-
-// TODO: this one may be useless
-//QVariant
-//TorControlPrototype::getInfo(QString key)
-//{
-// TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-// QString val, *errmsg = new QString();
-// bool res = false;
-// QList<QVariant> vals;
-
-// if(obj)
-// res = obj->getInfo(key, val, errmsg);
-
-// vals.append(QVariant(res));
-// vals.append(QVariant(val));
-// vals.append(QVariant(*errmsg));
-
-// return QVariant(vals);
-//}
-
-// TODO: There is no StringList, this may be useless
-//DEF_TYPE1(TorControl, QVariantMap,
-// getInfo(const QStringList &keys),
-// getInfo(keys, &errmsg))
-
-DEF_TYPE1(TorControl, QVariant,
- getInfo(const QString &key),
- getInfo(key, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- signal(TorSignal::Signal sig),
- signal(sig, &errmsg))
-
-// TODO: QVariant don't like QHostAddress
-//DEF_TYPE1(TorControl, QHostAddress,
-// getSocksAddress(),
-// getSocksAddress(&errmsg))
-
-// TODO: make it a QVariant(QList<QVariant>() << QVariant(QString) <<
-// QVariant(QString) ...
-QStringList
-TorControlPrototype::getSocksAddressList(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getSocksAddressList(errmsg);
-}
-
-DEF_TYPE1(TorControl, quint16,
- getSocksPort(),
- getSocksPort(&errmsg))
-
-// TODO: same as getSocksAddressList but with quint16
-QList<quint16>
-TorControlPrototype::getSocksPortList(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getSocksPortList(errmsg);
-}
-
-DEF_TYPE0(TorControl, QString,
- getTorVersionString(),
- getTorVersionString())
-
-DEF_TYPE0(TorControl, quint32,
- getTorVersion(),
- getTorVersion())
-
-DEF_TYPE1(TorControl, bool,
- setEvent(TorEvents::Event e, bool add, bool set),
- setEvent(e, add, set, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- setEvents(),
- setEvents(&errmsg))
-
-DEF_TYPE1(TorControl, bool,
- setConf(QHash<QString,QString> map),
- setConf(map, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- setConf(QString key, QString value),
- setConf(key, value, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- setConf(QString keyAndValue),
- setConf(keyAndValue, &errmsg))
-
-// TODO: macros don't like template variables
-// do this one by hand
-//DEF_TYPE2(TorControl, bool, QHash<QString,QString>,
-// getConf(QHash<QString,QString> &map),
-// getConf(map, &errmsg))
-bool
-TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(map, errmsg);
-}
-
-// TODO: this one too
-bool
-TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(map, errmsg);
-}
-
-DEF_TYPE2(TorControl, bool, QString,
- getConf(QString key),
- getConf(key, ans, &errmsg))
-
-// TODO: same as the last one with StringList
-bool
-TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(key, value, errmsg);
-}
-
-// TODO: idem
-QVariantMap
-TorControlPrototype::getConf(const QStringList &keys, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(keys, errmsg);
-}
-
-// TODO: possibly useless
-//QVariant
-//TorControlPrototype::getConf(const QString &key, QString *errmsg)
-//{
-// TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
-// if(obj)
-// return obj->getConf(key, errmsg);
-//}
-
-DEF_TYPE1(TorControl, QString,
- getHiddenServiceConf(const QString &key),
- getHiddenServiceConf(key, &errmsg))
-
-DEF_TYPE1(TorControl, bool,
- saveConf(),
- saveConf(&errmsg))
-
-// TODO: another stringlist one
-bool
-TorControlPrototype::resetConf(QStringList keys, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->resetConf(keys, errmsg);
-}
-
-DEF_TYPE1(TorControl, bool,
- resetConf(QString key),
- resetConf(key, &errmsg))
-
-// TODO: you know
-QStringList
-TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getRouterDescriptorText(id, errmsg);
-}
-
-// TODO: QVariantize RouterDescriptor
-RouterDescriptor
-TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getRouterDescriptor(id, errmsg);
-}
-
-// TODO: QVariantize RouterStatus
-RouterStatus
-TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getRouterStatus(id, errmsg);
-}
-
-// TODO: QVariantize NetworkStatus
-NetworkStatus
-TorControlPrototype::getNetworkStatus(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getNetworkStatus(errmsg);
-}
-
-// TODO: QVariantize DescriptorAnnotations
-DescriptorAnnotations
-TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getDescriptorAnnotations(id, errmsg);
-}
-
-// TODO: QVariantize CircuitList
-CircuitList
-TorControlPrototype::getCircuits(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getCircuits(errmsg);
-}
-
-// TODO: QVariantize StreamList
-StreamList
-TorControlPrototype::getStreams(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getStreams(errmsg);
-}
-
-// TODO: QVariantize AddressMap
-AddressMap
-TorControlPrototype::getAddressMap(AddressMap::AddressMapType type, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getAddressMap(type, errmsg);
-}
-
-DEF_TYPE1(TorControl, QString,
- ipToCountry(const QHostAddress &ip),
- ipToCountry(ip, &errmsg))
-
-// TODO: migrate CircuitId
-bool
-TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->closeCircuit(circId, ifUnused, errmsg);
-}
-
-// TODO: migrate StreamId
-bool
-TorControlPrototype::closeStream(const StreamId &streamId, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->closeStream(streamId, errmsg);
-}
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
deleted file mode 100644
index 071b90b..0000000
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.h
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
-** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If you
-** did not receive the LICENSE file with this file, you may obtain it from the
-** Vidalia source package distributed by the Vidalia Project at
-** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-** including this file, may be copied, modified, propagated, or distributed
-** except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file TorControlPrototype.h
-** \brief Prototype for TorControl class
-*/
-
-#ifndef _TORCONTROLPROTO_H
-#define _TORCONTROLPROTO_H
-
-#include <QtGui>
-#include <QtScript>
-
-#include "TorControl.h"
-#include "ProtocolInfo.h"
-
-class TorControlPrototype : public QObject, QScriptable
-{
- Q_OBJECT
-
-public:
- TorControlPrototype();
-
- static int metaTypeId();
- static QString name();
-
- /** Start the Tor process */
- Q_INVOKABLE void start(const QString &tor, const QStringList &args);
- /** Stop the Tor process */
- Q_INVOKABLE QVariant stop();
- /** Detect if the Tor process is running */
- Q_INVOKABLE bool isRunning();
- /** Detects if the Tor process is running under Vidalia. */
- Q_INVOKABLE bool isVidaliaRunningTor();
- /** Stops reading log messages from the Tor process's stdout. This has no
- * effect if isVidaliaRunningTor() is false. */
- Q_INVOKABLE void closeTorStdout();
-
- /** Connect to Tor's control socket */
- Q_INVOKABLE void connect(const QHostAddress &address, quint16 port);
- Q_INVOKABLE void connect(const QString &path);
- /** Disconnect from Tor's control socket */
- Q_INVOKABLE void disconnect();
- /** Check if we're connected to Tor's control socket */
- Q_INVOKABLE bool isConnected();
- /** Sends an authentication cookie to Tor. */
- Q_INVOKABLE QVariant authenticate(const QByteArray cookie);
- /** Sends an authentication password to Tor. */
- Q_INVOKABLE QVariant authenticate(const QString &password = QString());
-
- /** Sends a PROTOCOLINFO command to Tor and parses the response. */
-// Q_INVOKABLE QVariant protocolInfo();
-
- /** Returns the Tor software's current bootstrap phase and status. */
-// Q_INVOKABLE BootstrapStatus bootstrapStatus(QString *errmsg = 0);
-
- /** Returns true if Tor either has an open circuit or (on Tor >=
- * 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
- Q_INVOKABLE bool isCircuitEstablished();
-
- /** Sends a GETINFO message to Tor based on the given keys */
- Q_INVOKABLE QVariant getInfo(QHash<QString,QString> &map);
- /** Sends a GETINFO message for a single info value to Tor */
-// Q_INVOKABLE QVariant getInfo(QString key);
-
- /** 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. */
-// Q_INVOKABLE 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. */
- Q_INVOKABLE QVariant getInfo(const QString &key);
-
- /** Sends a signal to Tor */
- Q_INVOKABLE QVariant signal(TorSignal::Signal sig);
-
- /** Returns an address on which Tor is listening for application
- * requests. If none are available, a null QHostAddress is returned. */
-// Q_INVOKABLE QVariant getSocksAddress();
- /** Returns a (possibly empty) list of all currently configured
- * SocksListenAddress entries. */
- Q_INVOKABLE QStringList getSocksAddressList(QString *errmsg = 0);
- /** Returns a valid SOCKS port for Tor, or 0 if Tor is not accepting
- * application requests. */
- Q_INVOKABLE QVariant getSocksPort();
- /** Returns a list of all currently configured SOCKS ports. If Tor is not
- * accepting any application connections, an empty list will be returned. */
- Q_INVOKABLE QList<quint16> getSocksPortList(QString *errmsg = 0);
-
- /** Returns Tor's version as a string. */
- Q_INVOKABLE QString getTorVersionString();
- /** Returns Tor's version as a numeric value. */
- Q_INVOKABLE quint32 getTorVersion();
-
- /** Sets an event and its handler. If add is true, then the event is added,
- * otherwise it is removed. If set is true, then the given event will be
- * registered with Tor. */
- Q_INVOKABLE QVariant setEvent(TorEvents::Event e, bool add = true, bool set = true);
- /** Register events of interest with Tor */
- Q_INVOKABLE QVariant setEvents();
-
- /** Sets each configuration key in <b>map</b> to the value associated with its key. */
- Q_INVOKABLE QVariant setConf(QHash<QString,QString> map);
- /** Sets a single configuration key to the given value. */
- Q_INVOKABLE QVariant setConf(QString key, QString value);
- /** Sets a single configuration string that is formatted <key=escaped value>. */
- Q_INVOKABLE QVariant setConf(QString keyAndValue);
- /** Gets values for a set of configuration keys, each of which has a single
- * value. */
- Q_INVOKABLE bool getConf(QHash<QString,QString> &map, QString *errmsg);
- /** Gets a set of configuration keyvalues and stores them in <b>map</b>. */
- Q_INVOKABLE bool getConf(QHash<QString,QStringList> &map, QString *errmsg = 0);
- /** Gets a single configuration value for <b>key</b>. */
- Q_INVOKABLE QVariant getConf(QString key);
- /** Gets a list of configuration values for <b>key</b>. */
- Q_INVOKABLE 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. */
- Q_INVOKABLE 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. */
-// Q_INVOKABLE QVariant getConf(const QString &key, QString *errmsg = 0);
- /** Sends a GETCONF message to Tor with the single key and returns a QString
- * containing the value returned by Tor */
- Q_INVOKABLE QVariant getHiddenServiceConf(const QString &key);
-
- /** Asks Tor to save the current configuration to its torrc */
- Q_INVOKABLE QVariant saveConf();
- /** Tells Tor to reset the given configuration keys back to defaults. */
- Q_INVOKABLE bool resetConf(QStringList keys, QString *errmsg = 0);
- /** Tells Tor to reset a configuration key back to its default value. */
- Q_INVOKABLE QVariant resetConf(QString key);
-
- /** Returns an unparsed router descriptor for the router whose fingerprint
- * matches <b>id</b>. The returned text can later be parsed by the
- * RouterDescriptor class. If <b>id</b> is invalid, then an empty
- * QStringList is returned. */
- Q_INVOKABLE QStringList getRouterDescriptorText(const QString &id, QString *errmsg = 0);
- /** Returns the descriptor for the router whose fingerprint matches
- * <b>id</b>. If <b>id</b> is invalid or the router's descriptor cannot be
- * parsed, then an invalid RouterDescriptor is returned. */
- Q_INVOKABLE RouterDescriptor getRouterDescriptor(const QString &id, QString *errmsg = 0);
- /** Returns the status of the router whose fingerprint matches <b>id</b>. If
- * <b>id</b> is invalid or the router's status cannot be parsed, then an
- * invalid RouterStatus is returned. */
- Q_INVOKABLE RouterStatus getRouterStatus(const QString &id, QString *errmsg = 0);
- /** Returns a RouterStatus object for every known router in the network. If
- * the network status document cannot be parsed, then an empty NetworkStatus
- * is returned. */
- Q_INVOKABLE NetworkStatus getNetworkStatus(QString *errmsg = 0);
- /** Returns the annotations for the router whose fingerprint matches
- * <b>id</b>. If <b>id</b> is invalid or the router's descriptor cannot be
- * parsed, then an empty DescriptorAnnotations is returned and
- * <b>errmsg</b> is set if it's not NULL. (Tor >= 0.2.0.13-alpha only) */
- Q_INVOKABLE DescriptorAnnotations getDescriptorAnnotations(const QString &id,
- QString *errmsg = 0);
-
- /** Gets a list of current circuits. */
- Q_INVOKABLE CircuitList getCircuits(QString *errmsg = 0);
- /** Gets a list of current streams. */
- Q_INVOKABLE StreamList getStreams(QString *errmsg = 0);
-
- /** Gets a list of address mappings of the type specified by <b>type</b>
- * (defaults to <i>AddressMapAll</i>. */
- Q_INVOKABLE AddressMap getAddressMap(
- AddressMap::AddressMapType type = AddressMap::AddressMapAll,
- QString *errmsg = 0);
-
- /** Gets the ISO-3166 two-letter country code for <b>ip</b> from Tor.
- * Returns a default-constructed QString on failure or if a country code
- * is not known for <b>ip</b>. On failure, <b>errmsg</b> will be set if
- * it's not NULL. */
- Q_INVOKABLE QVariant ipToCountry(const QHostAddress &ip);
-
-public slots:
- /** Closes the circuit specified by <b>circId</b>. If <b>ifUnused</b> is
- * true, then the circuit will not be closed unless it is unused. */
- bool closeCircuit(const CircuitId &circId, bool ifUnused = false,
- QString *errmsg = 0);
- /** Closes the stream specified by <b>streamId</b>. */
- bool closeStream(const StreamId &streamId, QString *errmsg = 0);
-
-signals:
- /** Emitted when the Tor process has started */
- void started();
- /** Emitted when the Tor process fails to start. */
- void startFailed(QString errmsg);
- /** Emitted when the Tor process has stopped */
- void stopped(int exitCode, QProcess::ExitStatus exitStatus);
- /** Emitted when the Tor process has stopped. */
- void stopped();
- /** Emitted when the controller has connected to Tor */
- void connected();
- /** Emitted when the controller failed to connect to Tor. */
- void connectFailed(QString errmsg);
- /** Emitted when the controller has disconnected from Tor */
- void disconnected();
- /** Emitted when the control socket is connected and authenticated. */
- void authenticated();
- /** Emitted when Tor rejects our authentication attempt. */
- void authenticationFailed(QString errmsg);
-
- /** Emitted when Tor writes the message <b>msg</b> to the control port
- * with message severity <b>level</b>.
- */
- void logMessage(tc::Severity level, const QString &msg);
-
- /** Emitted when Tor sends a bandwidth usage update (roughly once every
- * second). <b>bytesReceived</b> is the number of bytes read by Tor over
- * the previous second and <b>bytesWritten</b> is the number of bytes
- * sent over the same interval.
- */
- void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent);
-
- /** Emitted when the stream status of <b>stream</b> has changed.
- */
- void streamStatusChanged(const Stream &stream);
-
- /** Emitted when the circuit status of <b>circuit</b> has changed.
- */
- void circuitStatusChanged(const Circuit &circuit);
-
- /** Emitted when Tor has mapped the address <b>from</b> to the address
- * <b>to</b>. <b>expires</b> indicates the time at which when the address
- * mapping will no longer be considered valid.
- */
- void addressMapped(const QString &from, const QString &to,
- const QDateTime &expires);
-
- /** Emitted when Tor has received one or more new router descriptors.
- * <b>ids</b> contains a list of digests of the new descriptors.
- */
- void newDescriptors(const QStringList &ids);
-
- /** Indicates Tor has been able to successfully establish one or more
- * circuits.
- */
- void circuitEstablished();
-
- /** Indicates that Tor has decided the user's Tor software <b>version</b>
- * is no longer recommended for some <b>reason</b>. <b>recommended</b> is
- * a list of Tor software versions that are considered current.
- */
- void dangerousTorVersion(tc::TorVersionStatus reason,
- const QString &version,
- const QStringList &recommended);
-
- /** Emitted during Tor's startup process to indicate how far in its
- * bootstrapping process it has progressed. <b>status</b> may indicate
- * the current bootstrapping stage or an error during bootstrapping.
- */
- void bootstrapStatusChanged(const BootstrapStatus &status);
-
- /** Emitted when the user attempts to establish a connection to some
- * destination on port <b>port</b>, which is a port known to use
- * plaintext connections (as determined by Tor's WarnPlaintextPorts and
- * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether
- * Tor rejected the connection or permitted it to connect anyway.
- */
- void dangerousPort(quint16 port, bool rejected);
-
- /** Emitted when Tor detects a problem with a SOCKS connection from the
- * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad
- * hostname. <b>type</b> indicates the type of error encountered and
- * <b>destination</b> (if non-empty) specifies the attempted connection
- * destination address or hostname.
- */
- void socksError(tc::SocksError type, const QString &destination);
-
- /** Emitted when Tor decides the client's external IP address has changed
- * to <b>ip</b>. If <b>hostname</b> is non-empty, Tor obtained the new
- * value for <b>ip</b> by resolving <b>hostname</b>.
- */
- void externalAddressChanged(const QHostAddress &ip, const QString &hostname);
-
- /** Indicates that Tor has determined the client's clock is potentially
- * skewed by <b>skew</b> seconds relative to <b>source</b>.
- */
- void clockSkewed(int skew, const QString &source);
-
- /** Emitted when Tor has encountered an internal bug. <b>reason</b> is
- * Tor's description of the bug.
- */
- void bug(const QString &reason);
-
- /** Emitted when Tor determines that the user's DNS provider is providing
- * an address for non-existent domains when it should really be saying
- * "NXDOMAIN".
- */
- void dnsHijacked();
-
- /** Emitted when Tor determines that the user's DNS provider is providing
- * a hijacked address even for well-known websites.
- */
- void dnsUseless();
-
- /** Indicates Tor has started testing the reachability of its OR port
- * using the IP address <b>ip</b> and port <b>port</b>.
- */
- void checkingOrPortReachability(const QHostAddress &ip, quint16 port);
-
- /** Tor has completed testing the reachability of its OR port using
- * the IP address <b>ip</b> and port <b>port</b>. If the user's OR port
- * was reachable, <b>reachable</b> will be set to true.
- */
- void orPortReachabilityFinished(const QHostAddress &ip, quint16 port,
- bool reachable);
-
- /** Indicates Tor has started testing the reachability of its directory
- * port using the IP address <b>ip</b> and port <b>port</b>.
- */
- void checkingDirPortReachability(const QHostAddress &ip, quint16 port);
-
- /** Tor has completed testing the reachability of its directory port using
- * the IP address <b>ip</b> and port <b>port</b>. If the user's directory
- * port was reachable, <b>reachable</b> will be set to true.
- */
- void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port,
- bool reachable);
-
- /** Emitted when the directory authority with IP address <b>ip</b> and
- * port <b>port</b> rejected the user's server descriptor. <b>reason</b>
- * describes why the descriptor was rejected (e.g., malformed, skewed
- * clock, etc.).
- */
- void serverDescriptorRejected(const QHostAddress &ip, quint16 port,
- const QString &reason);
-
- /** Emitted when the directory authority with IP address <b>ip</b> and
- * port <b>port</b> accepted the user's server descriptor.
- */
- void serverDescriptorAccepted(const QHostAddress &ip, quint16 port);
-
- /** Emitted when at least one directory authority has accepted the user's
- * server descriptor.
- */
- void serverDescriptorAccepted();
-};
-
-Q_DECLARE_METATYPE(TorControl *);
-
-#endif
-
-
More information about the tor-commits
mailing list