[tor-commits] [vidalia/alpha] Add TorrcPrototype

chiiph at torproject.org chiiph at torproject.org
Tue Jun 12 13:21:18 UTC 2012


commit cfdacb216c2954abdcfd9bb7328a8ce81bf8cba4
Author: Feroze Naina <ferozenaina at gmail.com>
Date:   Tue Jun 5 16:39:46 2012 +0530

    Add TorrcPrototype
---
 changes/TorrcPrototype                           |    3 +
 src/vidalia/CMakeLists.txt                       |    2 +
 src/vidalia/plugin/PluginEngine.cpp              |    2 +
 src/vidalia/plugin/PluginEngine.h                |    1 +
 src/vidalia/plugin/prototypes/TorrcPrototype.cpp |   71 ++++++++++++++++++++++
 src/vidalia/plugin/prototypes/TorrcPrototype.h   |   63 +++++++++++++++++++
 6 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/changes/TorrcPrototype b/changes/TorrcPrototype
new file mode 100644
index 0000000..3851322
--- /dev/null
+++ b/changes/TorrcPrototype
@@ -0,0 +1,3 @@
+  New features:
+  o Added plugin prototype for Torrc class. This allows plugins to
+    modify the .torrc configuration file.
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 41e5aa8..23b5464 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -91,6 +91,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
   plugin/prototypes/VidaliaTabPrototype.cpp
   plugin/prototypes/HelperProcessPrototype.cpp
   plugin/prototypes/TorControlPrototype.cpp
+  plugin/prototypes/TorrcPrototype.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
   plugin/PluginEngine.h
@@ -99,6 +100,7 @@ qt4_wrap_cpp(vidalia_SRCS
   plugin/prototypes/VidaliaTabPrototype.h
   plugin/prototypes/HelperProcessPrototype.h
   plugin/prototypes/TorControlPrototype.h
+  plugin/prototypes/TorrcPrototype.h
 )
 
 ## Configuration dialog sources
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 097ed1e..0c9e75a 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -28,8 +28,10 @@ PluginEngine::PluginEngine(QObject *parent)
   ADD_PROTOTYPE(HelperProcessPrototype)
   MAKE_CREATABLE(HelperProcessPrototype)
   ADD_PROTOTYPE(TorControlPrototype)
+  ADD_PROTOTYPE(TorrcPrototype)
 
   globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
+  globalObject().setProperty("torrc", newQObject(Vidalia::torrc()));
   globalObject().setProperty("vidaliaApp", newQObject(vApp));
 
 //  globalObject().setProperty("include", newFunction(includeScript));
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index debede3..83a3d6f 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -22,6 +22,7 @@
 #include "VidaliaTabPrototype.h"
 #include "HelperProcessPrototype.h"
 #include "TorControlPrototype.h"
+#include "TorrcPrototype.h"
 
 class PluginWrapper;
 
diff --git a/src/vidalia/plugin/prototypes/TorrcPrototype.cpp b/src/vidalia/plugin/prototypes/TorrcPrototype.cpp
new file mode 100644
index 0000000..e2cbad1
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/TorrcPrototype.cpp
@@ -0,0 +1,71 @@
+/*
+**  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 TorrcPrototype.cpp
+** \brief Prototype for Torrc class
+*/
+
+#include "TorrcPrototype.h"
+#include "prototypemacros.h"
+
+TorrcPrototype::TorrcPrototype()
+  : QObject(), QScriptable() {}
+
+int
+TorrcPrototype::metaTypeId()
+{
+  return qMetaTypeId<Torrc *>();
+}
+
+DEF_TYPE0(Torrc, void,
+    load(const QString &torrcPath, const QString &defaultsPath = ""),
+    load(torrcPath, defaultsPath))
+
+bool
+TorrcPrototype::apply(TorControl *tc, QString *errmsg){
+  Torrc *obj = qscriptvalue_cast<Torrc *>(thisObject());
+
+  if(obj)
+    return obj->apply(tc, errmsg);
+}
+
+DEF_TYPE0(Torrc, void,
+    clear(QStringList keys),
+    clear(keys))
+
+DEF_TYPE0(Torrc, void,
+    clearAll(),
+    clearAll())
+
+DEF_TYPE0(Torrc, QStringList,
+    value(const QString &key) const,
+    value(key))
+
+DEF_TYPE0(Torrc, void,
+    setValue(const QString &key, const QString &value, const QString &comment),
+    setValue(key, value, comment))
+
+DEF_TYPE0(Torrc, QString,
+    getTorrcPath() const,
+    getTorrcPath())
+
+DEF_TYPE0(Torrc, bool,
+    isValid(const QString &key, const QString &value),
+    isValid(key, value))
+
+
+bool
+TorrcPrototype::setRawContents(const QString &contents, QString *errmsg, TorControl *tc){
+  Torrc *obj = qscriptvalue_cast<Torrc *>(thisObject());
+
+  if(obj)
+    return obj->setRawContents(contents, errmsg, tc);
+}
diff --git a/src/vidalia/plugin/prototypes/TorrcPrototype.h b/src/vidalia/plugin/prototypes/TorrcPrototype.h
new file mode 100644
index 0000000..cf6f9fd
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/TorrcPrototype.h
@@ -0,0 +1,63 @@
+/*
+**  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 TorrcPrototype.h
+** \brief Object for interacting with Torrc file
+*/
+
+#ifndef _TORRCPROTO_H
+#define _TORRCPROTO_H
+
+#include <QtGui>
+#include <QtScript>
+
+#include "Torrc.h"
+
+class TorrcPrototype : public QObject, QScriptable
+{
+  Q_OBJECT
+
+public:
+  TorrcPrototype();
+
+  static int metaTypeId();
+  static QString name();
+
+  /** Loads the torrc from the path provided and its defaults if provided */
+  Q_INVOKABLE void load(const QString &torrcPath, const QString &defaultsPath);
+  /** Applies the changes in configuration to the torrc file */
+  Q_INVOKABLE bool apply(TorControl *tc = 0, QString *errmsg = 0);
+
+  /** Clears the keys provided in the list */
+  Q_INVOKABLE void clear(QStringList keys);
+  /** Clears the _torrcMap and _lines values */
+  Q_INVOKABLE void clearAll();
+
+  /** Returns a list of values associated with the given key */
+  Q_INVOKABLE QStringList value(const QString &key) const;
+  /** Sets the value to the given key with a optional
+   *  comment that will appear in the file */
+  Q_INVOKABLE void setValue(const QString &key, const QString &value, const QString &comment = "");
+
+  /** Returns the used torrc path */
+  Q_INVOKABLE QString getTorrcPath() const;
+
+  /** Returns true if the key=value is a valid config option */
+  Q_INVOKABLE bool isValid(const QString &key, const QString &value);
+
+  /** Resets the config values as if the torrc file contained the
+   *  string in contents, and applies it. */
+  Q_INVOKABLE bool setRawContents(const QString &contents, QString *errmsg, TorControl *tc = 0);
+};
+
+Q_DECLARE_METATYPE(Torrc *);
+
+#endif





More information about the tor-commits mailing list