[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1853: Add support for PROTOCOLINFO. (in trunk: . src/control)



Author: edmanm
Date: 2007-08-22 21:06:21 -0400 (Wed, 22 Aug 2007)
New Revision: 1853

Added:
   trunk/src/control/protocolinfo.cpp
   trunk/src/control/protocolinfo.h
Modified:
   trunk/
   trunk/src/control/control.pri
   trunk/src/control/torcontrol.cpp
   trunk/src/control/torcontrol.h
Log:
 r2025@adrastea:  edmanm | 2007-08-22 21:02:21 -0400
 Add support for PROTOCOLINFO. 



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /vidalia/local/trunk [r2025] on 54b3572a-7227-0410-958f-53ecd705b71a

Modified: trunk/src/control/control.pri
===================================================================
--- trunk/src/control/control.pri	2007-08-23 01:06:04 UTC (rev 1852)
+++ trunk/src/control/control.pri	2007-08-23 01:06:21 UTC (rev 1853)
@@ -41,7 +41,8 @@
            $$PWD/routerdescriptor.h \
            $$PWD/circuit.h \
            $$PWD/stream.h \
-           $$PWD/addressmap.h
+           $$PWD/addressmap.h \
+           $$PWD/protocolinfo.h
 
 SOURCES += $$PWD/torcontrol.cpp \
            $$PWD/torprocess.cpp \
@@ -57,7 +58,8 @@
            $$PWD/routerdescriptor.cpp \
            $$PWD/circuit.cpp \
            $$PWD/stream.cpp \
-           $$PWD/addressmap.cpp
+           $$PWD/addressmap.cpp \
+           $$PWD/protocolinfo.cpp
 
 win32 {
   HEADERS += $$PWD/torservice.h

Added: trunk/src/control/protocolinfo.cpp
===================================================================
--- trunk/src/control/protocolinfo.cpp	                        (rev 0)
+++ trunk/src/control/protocolinfo.cpp	2007-08-23 01:06:21 UTC (rev 1853)
@@ -0,0 +1,47 @@
+/****************************************************************
+ *  Vidalia is distributed under the following license:
+ *
+ *  Copyright (C) 2007,  Matt Edman, Justin Hipple
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ *  Boston, MA  02110-1301, USA.
+ ****************************************************************/
+
+/** 
+ * \file protocolinfo.cpp
+ * \version $Id$
+ * \brief Container for information in a PROTOCOLINFO reply from Tor
+ */
+
+#include "protocolinfo.h"
+
+
+/** Returns true if this ProtoclInfo object contains no data. */
+bool
+ProtocolInfo::isEmpty() const
+{
+  return (_torVersion.isEmpty() && 
+         _authMethods.isEmpty() &&
+         _cookieAuthFile.isEmpty());
+}
+
+/** Sets the authentication methods Tor currently accepts. <b>methods</b>
+ * should be a comma-delimited list of authentication methods. */
+void
+ProtocolInfo::setAuthMethods(const QString authMethods)
+{
+  _authMethods = authMethods.split(",");
+}
+


Property changes on: trunk/src/control/protocolinfo.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/src/control/protocolinfo.h
===================================================================
--- trunk/src/control/protocolinfo.h	                        (rev 0)
+++ trunk/src/control/protocolinfo.h	2007-08-23 01:06:21 UTC (rev 1853)
@@ -0,0 +1,67 @@
+/****************************************************************
+ *  Vidalia is distributed under the following license:
+ *
+ *  Copyright (C) 2007,  Matt Edman, Justin Hipple
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ *  Boston, MA  02110-1301, USA.
+ ****************************************************************/
+
+/** 
+ * \file protocolinfo.h
+ * \version $Id$
+ * \brief Container for information in a PROTOCOLINFO reply from Tor
+ */
+
+#ifndef _PROTOCOLINFO_H
+#define _PROTOCOLINFO_H
+
+#include <QStringList>
+
+
+class ProtocolInfo
+{
+public:
+  /** Default constructor. */
+  ProtocolInfo() {}
+  
+  /** Returns true if this ProtoclInfo object contains no data. */
+  bool isEmpty() const;
+  
+  /** Sets the authentication methods Tor currently accepts. <b>methods</b>
+   * should be a comma-delimited list of authentication methods. */
+  void setAuthMethods(const QString methods);
+  /** Returns the authentication methods Tor currently accepts. */
+  QStringList authMethods() const { return _authMethods; }
+
+  /** Sets the file to which Tor has written its authentication cookie. */
+  void setCookieAuthFile(const QString cookieAuthFile)
+    { _cookieAuthFile = cookieAuthFile; }
+  /** Returns the file to which Tor has written its authentication cookie. */
+  QString cookieAuthFile() const { return _cookieAuthFile; }
+
+  /** Sets the version of Tor to which the controller is connected. */
+  void setTorVersion(const QString torVersion) { _torVersion = torVersion; }
+  /** Returns the version of Tor to which the controller is connected. */
+  QString torVersionString() const { return _torVersion; }
+
+private:
+  QString _torVersion;      /**< The Tor version in the PROTOCOLINFO reply. */
+  QString _cookieAuthFile;  /**< Tor's authentication cookie file. */
+  QStringList _authMethods; /**< Tor's ccepted authentication methods. */
+};
+
+#endif
+


Property changes on: trunk/src/control/protocolinfo.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp	2007-08-23 01:06:04 UTC (rev 1852)
+++ trunk/src/control/torcontrol.cpp	2007-08-23 01:06:21 UTC (rev 1853)
@@ -365,6 +365,50 @@
   emit authenticated();
 }
 
+/** Sends a PROTOCOLINFO command to Tor and parses the response. */
+ProtocolInfo
+TorControl::protocolInfo(QString *errmsg)
+{
+  ControlCommand cmd("PROTOCOLINFO", "1");
+  ControlReply reply;
+  ProtocolInfo pi;
+  QString msg, topic;
+  QHash<QString,QString> keyvals;
+  int idx;
+  bool ok;
+
+  if (!send(cmd, reply, errmsg))
+    return ProtocolInfo();
+
+  foreach (ReplyLine line, reply.getLines()) {
+    if (line.getStatus() != "250")
+      continue;
+    
+    msg = line.getMessage().trimmed();
+    idx = msg.indexOf(" ");
+    topic = msg.mid(0, idx).toUpper();
+    
+    if (idx > 0) {
+      keyvals = string_parse_keyvals(msg.mid(idx+1), &ok);
+      if (!ok)
+        continue; /* Ignore malformed lines */
+    } else {
+      keyvals = QHash<QString,QString>();
+    }
+   
+    if (topic == "AUTH") {
+      if (keyvals.contains("METHODS"))
+        pi.setAuthMethods(keyvals.value("METHODS"));
+      if (keyvals.contains("COOKIEFILE"))
+        pi.setCookieAuthFile(keyvals.value("COOKIEFILE"));
+    } else if (topic == "VERSION") {
+      if (keyvals.contains("Tor"))
+        pi.setTorVersion(keyvals.value("Tor"));
+    }
+  }
+  return pi;
+}
+
 /** Sends a GETINFO message to Tor based on the given map of keyvals. The
  * syntax is:
  * 

Modified: trunk/src/control/torcontrol.h
===================================================================
--- trunk/src/control/torcontrol.h	2007-08-23 01:06:04 UTC (rev 1852)
+++ trunk/src/control/torcontrol.h	2007-08-23 01:06:21 UTC (rev 1853)
@@ -39,6 +39,7 @@
 #include "torsignal.h"
 #include "routerdescriptor.h"
 #include "addressmap.h"
+#include "protocolinfo.h"
 
 #if defined(Q_OS_WIN32)
 #include "torservice.h"
@@ -74,7 +75,10 @@
   bool authenticate(const QByteArray cookie, QString *errmsg = 0);
   /** Sends an authentication password to Tor. */
   bool authenticate(const QString password = QString(), QString *errmsg = 0);
-
+  
+  /** Sends a PROTOCOLINFO command to Tor and parses the response. */
+  ProtocolInfo protocolInfo(QString *errmsg = 0);
+  
   /** Sends a GETINFO message to Tor based on the given keys */
   bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
   /** Sends a GETINFO message for a single info value to Tor */