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

[vidalia-svn] r1858: PROTOCOLINFO gives us the complete path to the authenticatio (in trunk: . src/gui)



Author: edmanm
Date: 2007-08-22 23:09:50 -0400 (Wed, 22 Aug 2007)
New Revision: 1858

Modified:
   trunk/
   trunk/src/gui/mainwindow.cpp
   trunk/src/gui/mainwindow.h
Log:
 r2038@adrastea:  edmanm | 2007-08-22 23:07:10 -0400
 PROTOCOLINFO gives us the complete path to the authentication cookie,
 including the filename, but loadControlCookie() was expecting a directory and
 appending '/control_auth_cookie' to the path.



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

Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp	2007-08-23 02:15:25 UTC (rev 1857)
+++ trunk/src/gui/mainwindow.cpp	2007-08-23 03:09:50 UTC (rev 1858)
@@ -816,38 +816,45 @@
 }
 
 /** Searches for and attempts to load the control authentication cookie. This
- * assumes the cookie is named 'control_auth_cookie'. If <b>cookieDir</b> is
+ * assumes the cookie is named 'control_auth_cookie'. If <b>cookiePath</b> is
  * empty, this method will search some default locations depending on the
- * current platform. */
+ * current platform. <b>cookiePath</b> can point to either a cookie file or a
+ * directory containing the cookie file. */
 QByteArray
-MainWindow::loadControlCookie(QString cookieDir)
+MainWindow::loadControlCookie(QString cookiePath)
 {
   QFile authCookie;
-  QStringList dirList;
+  QStringList pathList;
 
-  if (!cookieDir.isEmpty()) {
-    dirList << cookieDir;
+  if (!cookiePath.isEmpty()) {
+    pathList << cookiePath;
   } else {
     /* Try some default locations */
     TorSettings settings;
     QString dataDir = settings.getDataDirectory();
     if (!dataDir.isEmpty())
-      dirList << dataDir;
+      pathList << dataDir;
       
 #if defined(Q_WS_WIN)
-    dirList << expand_filename("%APPDATA%\\Tor");
+    pathList << expand_filename("%APPDATA%\\Tor");
 #else
-    dirList << expand_filename("~/.tor");
+    pathList << expand_filename("~/.tor");
 #endif
   }
   
   /* Search for the cookie file */
-  foreach (QString dir, dirList) {
-    if (!QFileInfo(dir + "/control_auth_cookie").exists())
+  foreach (QString path, pathList) {
+    QString cookieFile = QFileInfo(path).isFile() ?
+                          path : path + "/control_auth_cookie";
+    if (!QFileInfo(cookieFile).exists())
       continue;
-    authCookie.setFileName(dir + "/control_auth_cookie");
+    
+    authCookie.setFileName(cookieFile);
     if (authCookie.open(QIODevice::ReadOnly))
       return authCookie.readAll();
+    else
+      vWarn("Couldn't open cookie file '%1': %2")
+        .arg(cookieFile).arg(authCookie.errorString());
   }
   return QByteArray();
 }

Modified: trunk/src/gui/mainwindow.h
===================================================================
--- trunk/src/gui/mainwindow.h	2007-08-23 02:15:25 UTC (rev 1857)
+++ trunk/src/gui/mainwindow.h	2007-08-23 03:09:50 UTC (rev 1858)
@@ -144,9 +144,10 @@
   bool authenticate();
   /** Searches for and attempts to load the control authentication cookie.
    * This assumes the cookie is named 'control_auth_cookie'. If
-   * <b>cookieDir</b> is empty, this method will search some default locations
-   * depending on the current platform. */
-  QByteArray loadControlCookie(QString cookieDir = QString());
+   * <b>cookiePath</b> is empty, this method will search some default locations
+   * depending on the current platform. <b>cookiePath</b> can point to either
+   * a cookie file or a directory containing the cookie file. */
+  QByteArray loadControlCookie(QString cookiePath = QString());
 
   /** The current status of Tor. */
   TorStatus _status;