[tor-commits] [tor-launcher/master] Change bridge into a textbox and make it functional.

brade at torproject.org brade at torproject.org
Tue Apr 9 15:22:42 UTC 2013


commit d44dfc5db8acc391130579bdf260dc3e1a3610ed
Author: Kathy Brade <brade at torproject.org>
Date:   Tue Apr 9 11:21:45 2013 -0400

    Change bridge into a textbox and make it functional.
---
 src/chrome/content/network-settings.js        |   88 +++++++++++++++++--------
 src/chrome/content/network-settings.xul       |   23 +++----
 src/chrome/locale/en/network-settings.dtd     |    5 +-
 src/chrome/locale/en/torcontroller.properties |    1 +
 4 files changed, 72 insertions(+), 45 deletions(-)

diff --git a/src/chrome/content/network-settings.js b/src/chrome/content/network-settings.js
index 73c10f1..98d4ed7 100644
--- a/src/chrome/content/network-settings.js
+++ b/src/chrome/content/network-settings.js
@@ -3,6 +3,8 @@
 //
 // vim: set sw=2 sts=2 ts=8 et syntax=javascript:
 
+// TODO: if clean start and "Unable to read Tor settings" error is displayed, we should not bootstrap Tor or start the browser.
+
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
@@ -405,15 +407,21 @@ function applyFirewallSettings()
 // Returns true if settings were successfully applied.
 function applyBridgeSettings()
 {
-  // TODO: validate user-entered data.  See Vidalia's NetworkPage::save()
-
   var settings = {};
   settings[kTorConfKeyUseBridges] = null;
   settings[kTorConfKeyBridgeList] = null;
 
   var useBridges = getElemValue(kUseBridgesCheckbox, false);
-  var bridgeList = getElemValue(kBridgeList, null);
+  var bridgeStr = getElemValue(kBridgeList, null);
 
+  var bridgeList = parseAndValidateBridges(bridgeStr);
+  if (useBridges && !bridgeList)
+  {
+    reportValidationError("error_bridges_missing");
+    return false;
+  }
+
+  setElemValue(kBridgeList, bridgeList);
   if (useBridges && bridgeList)
   {
     settings[kTorConfKeyUseBridges] = true;
@@ -424,6 +432,42 @@ function applyBridgeSettings()
 }
 
 
+// Returns an array or null.
+function parseAndValidateBridges(aStr)
+{
+  if (!aStr)
+    return null;
+
+  var resultStr = aStr;
+  resultStr = resultStr.replace(/bridge/gi, ""); // Remove "bridge" everywhere.
+  resultStr = resultStr.replace(/\r\n/g, "\n");  // Convert \r\n pairs into \n.
+  resultStr = resultStr.replace(/\r/g, "\n");    // Convert \r into \n.
+  resultStr = resultStr.replace(/\n\n/g, "\n");  // Condense blank lines.
+
+  var resultArray = new Array;
+  var tmpArray = resultStr.split('\n');
+  for (var i = 0; i < tmpArray.length; i++)
+  {
+    let s = tmpArray[i].trim(); // Remove extraneous whitespace.
+    if (s.indexOf(' ') >= 0)
+    {
+      // Handle a space-separated list of bridge specs.
+      var tmpArray2 = s.split(' ');
+      for (var j = 0; j < tmpArray2.length; ++j)
+      {
+        let s2 = tmpArray2[j];
+        if (s2.length > 0)
+          resultArray.push(s2);
+      }
+    }
+    else if (s.length > 0)
+      resultArray.push(s);
+  }
+
+  return (0 == resultArray.length) ? null : resultArray;
+}
+
+
 // Returns true if successful.
 function setConfAndReportErrors(aSettingsObj)
 {
@@ -472,28 +516,27 @@ function setElemValue(aID, aValue)
         toggleElemUI(elem);
         break;
       case "textbox":
-      case "menulist":
-        elem.value = (aValue) ? aValue : "";
-        break;
-      case "listbox":
-        // Remove all existing items.
-        while (elem.itemCount > 0)
-          elem.removeItemAt(0);
-
-        // Add new items.
-        if (aValue && Array.isArray(aValue))
+        var s = aValue;
+        if (Array.isArray(aValue))
         {
+          s = "";
           for (var i = 0; i < aValue.length; ++i)
-            elem.appendItem(aValue[i]);
+          {
+            if (s.length > 0)
+              s += '\n';
+            s += aValue[i];
+          }
         }
+        // fallthru
+      case "menulist":
+        elem.value = (s) ? s : "";
         break;
     }
   }
 }
 
 
-// Returns a Boolean (for checkboxes), a string (textbox and menulist), or an
-// array of strings (listbox).
+// Returns a Boolean (for checkboxes) or a string (textbox and menulist).
 // Leading and trailing white space is trimmed from strings.
 function getElemValue(aID, aDefaultValue)
 {
@@ -510,19 +553,6 @@ function getElemValue(aID, aDefaultValue)
       case "menulist":
         rv = elem.value;
         break;
-      case "listbox":
-        rv = elem.checked;
-        if (elem.itemCount > 0)
-        {
-          rv = [];
-          for (var i = 0; i < elem.itemCount; ++i)
-          {
-            var item = elem.getItemAtIndex(i);
-            if (item.label)
-              rv.push(item.label.trim());
-          }
-        }
-        break;
     }
   }
 
diff --git a/src/chrome/content/network-settings.xul b/src/chrome/content/network-settings.xul
index e1d839e..5daabac 100644
--- a/src/chrome/content/network-settings.xul
+++ b/src/chrome/content/network-settings.xul
@@ -110,22 +110,21 @@
               oncommand="toggleElemUI(this);" />
     <groupbox id="bridgeSpecificSettings">
       <hbox>
-        <textbox id="addBridgeText" style="width: 320px" />
-        <button id="addBridgeBtn" label="&addButton;" oncommand="AddBridge();"
-                style="width: 20px !important" />
-      </hbox>
-      <hbox>
-        <listbox id="bridgeList" rows="4" style="width: 320px" />
+        <vbox flex="1">
+          <label value="&torsettings.useBridges.label;" control="bridgeList"/>
+          <textbox id="bridgeList" multiline="true" rows="4" />
+        </vbox>
+<!--
         <vbox>
-          <button id="deleteBridge" label="&deleteButton;" style="width: 20px"
-                  oncommand="DeleteBridge();"/>
-          <button id="copyBridgeList" label="&todo;" style="width: 20px"
+          <button id="copyBridgeList" label="Copy TODO" style="width: 20px"
                   oncommand="copyBridgeList();"/>
+          <button id="pasteBridgeList" label="Paste TODO" style="width: 20px"
+                  oncommand="pasteBridgeList();"/>
+          <button id="howToFindBridges" label="How can I find bridges? TODO" style="width: 20px"
+                    oncommand="findBridgeList();"/>
         </vbox>
-      </hbox>
-<!--
-      <a href="TODO">How can I find bridges?</a>
 -->
+      </hbox>
     </groupbox>
   </vbox>
   </vbox>
diff --git a/src/chrome/locale/en/network-settings.dtd b/src/chrome/locale/en/network-settings.dtd
index 1fc15bb..5d5fa99 100644
--- a/src/chrome/locale/en/network-settings.dtd
+++ b/src/chrome/locale/en/network-settings.dtd
@@ -17,7 +17,4 @@
 <!ENTITY torsettings.firewall.checkbox "My firewall only lets me connect to certain ports">
 <!ENTITY torsettings.firewall.allowedPorts "Allowed Ports:">
 <!ENTITY torsettings.useBridges.checkbox "My ISP blocks connections to the Tor network">
-
-<!ENTITY addButton "+">
-<!ENTITY deleteButton "-">
-<!ENTITY todo "TODO">
+<!ENTITY torsettings.useBridges.label "Enter one or more bridge relays in the form address:port.">
diff --git a/src/chrome/locale/en/torcontroller.properties b/src/chrome/locale/en/torcontroller.properties
index 88882db..9331ecf 100644
--- a/src/chrome/locale/en/torcontroller.properties
+++ b/src/chrome/locale/en/torcontroller.properties
@@ -19,6 +19,7 @@ torlauncher.ensure_tor_is_running=Please ensure that Tor is running.
 
 torlauncher.error_proxy_addr_missing=You must specify both an IP address or hostname and a port number to configure Tor to use a proxy to access the Internet.
 torlauncher.error_proxy_type_missing=You must select the proxy type.
+torlauncher.error_bridges_missing=You must specify one or more bridges.
 
 torlauncher.connect=Connect
 torlauncher.quit=Quit



More information about the tor-commits mailing list