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

[or-cvs] r23866: {arm} Display and validation for multiline torrc entries. fix: err (in arm/trunk: . src/interface src/util)



Author: atagar
Date: 2010-11-28 00:03:03 +0000 (Sun, 28 Nov 2010)
New Revision: 23866

Modified:
   arm/trunk/README
   arm/trunk/src/interface/configPanel.py
   arm/trunk/src/interface/controller.py
   arm/trunk/src/interface/torrcPanel.py
   arm/trunk/src/util/torConfig.py
Log:
Display and validation for multiline torrc entries.
fix: error in parsing single line csv values (wasn't stripping internal spaces)



Modified: arm/trunk/README
===================================================================
--- arm/trunk/README	2010-11-27 21:55:13 UTC (rev 23865)
+++ arm/trunk/README	2010-11-28 00:03:03 UTC (rev 23866)
@@ -122,8 +122,8 @@
       connPanel.py           - (page 2) displays information on tor connections
       descriptorPopup.py     - (popup) displays connection descriptor data
       
-      configFilePanel.py     - (page 3) displays torrc/armrc and validation
-      configStatePanel.py    - editor panel for the tor and arm config states
+      configPanel.py         - (page 3) editor panel for the tor configuration
+      torrcPanel.py          - (page 4) displays torrc and validation
     
     util/
       __init__.py

Modified: arm/trunk/src/interface/configPanel.py
===================================================================
--- arm/trunk/src/interface/configPanel.py	2010-11-27 21:55:13 UTC (rev 23865)
+++ arm/trunk/src/interface/configPanel.py	2010-11-28 00:03:03 UTC (rev 23866)
@@ -101,7 +101,7 @@
     
     return [self.get(field) for field in argTypes]
 
-class ConfigStatePanel(panel.Panel):
+class ConfigPanel(panel.Panel):
   """
   Renders a listing of the tor or arm configuration state, allowing options to
   be selected and edited.

Modified: arm/trunk/src/interface/controller.py
===================================================================
--- arm/trunk/src/interface/controller.py	2010-11-27 21:55:13 UTC (rev 23865)
+++ arm/trunk/src/interface/controller.py	2010-11-28 00:03:03 UTC (rev 23866)
@@ -517,8 +517,8 @@
   
   panels["conn"] = connPanel.ConnPanel(stdscr, conn, isBlindMode)
   panels["control"] = ControlPanel(stdscr, isBlindMode)
-  panels["config"] = configPanel.ConfigStatePanel(stdscr, configPanel.TOR_STATE, config)
-  panels["torrc"] = torrcPanel.ConfigFilePanel(stdscr, torrcPanel.TORRC, config)
+  panels["config"] = configPanel.ConfigPanel(stdscr, configPanel.TOR_STATE, config)
+  panels["torrc"] = torrcPanel.TorrcPanel(stdscr, torrcPanel.TORRC, config)
   
   # provides error if pid coulnd't be determined (hopefully shouldn't happen...)
   if not torPid: log.log(log.WARN, "Unable to resolve tor pid, abandoning connection listing")

Modified: arm/trunk/src/interface/torrcPanel.py
===================================================================
--- arm/trunk/src/interface/torrcPanel.py	2010-11-27 21:55:13 UTC (rev 23865)
+++ arm/trunk/src/interface/torrcPanel.py	2010-11-28 00:03:03 UTC (rev 23866)
@@ -13,7 +13,7 @@
 
 TORRC, ARMRC = range(1, 3) # configuration file types that can  be displayed
 
-class ConfigFilePanel(panel.Panel):
+class TorrcPanel(panel.Panel):
   """
   Renders the current torrc or armrc with syntax highlighting in a scrollable
   area.
@@ -111,6 +111,7 @@
       locationLabel = " (%s)" % confLocation if confLocation else ""
       self.addstr(0, 0, "%s Configuration File%s:" % (sourceLabel, locationLabel), curses.A_STANDOUT)
     
+    isMultiline = False # set if we're in the middle of a multiline torrc entry
     for lineNumber in range(0, len(renderedContents)):
       lineText = renderedContents[lineNumber]
       lineText = lineText.rstrip() # remove ending whitespace
@@ -133,14 +134,23 @@
       # splits the option and argument, preserving any whitespace around them
       strippedLine = lineText.strip()
       optionIndex = strippedLine.find(" ")
-      if optionIndex == -1:
-        lineComp["option"][0] = lineText # no argument provided
+      if isMultiline:
+        # part of a multiline entry started on a previous line so everything
+        # is part of the argument
+        lineComp["argument"][0] = lineText
+      elif optionIndex == -1:
+        # no argument provided
+        lineComp["option"][0] = lineText
       else:
         optionText = strippedLine[:optionIndex]
         optionEnd = lineText.find(optionText) + len(optionText)
         lineComp["option"][0] = lineText[:optionEnd]
         lineComp["argument"][0] = lineText[optionEnd:]
       
+      # flags following lines as belonging to this multiline entry if it ends
+      # with a slash
+      if strippedLine: isMultiline = strippedLine.endswith("\\")
+      
       # gets the correction
       if lineNumber in corrections:
         lineIssue, lineIssueMsg = corrections[lineNumber]

Modified: arm/trunk/src/util/torConfig.py
===================================================================
--- arm/trunk/src/util/torConfig.py	2010-11-27 21:55:13 UTC (rev 23865)
+++ arm/trunk/src/util/torConfig.py	2010-11-28 00:03:03 UTC (rev 23866)
@@ -333,14 +333,27 @@
     contents - torrc contents
   """
   
-  # TODO: needs to recognize tor's new multiline values
+  conn = torTools.getConn()
+  issuesFound, seenOptions = {}, []
+  
+  # Strips comments and collapses multiline multi-line entries, for more
+  # information see:
   # https://trac.torproject.org/projects/tor/ticket/1929
+  strippedContents, multilineBuffer = [], ""
+  for line in _stripComments(contents):
+    if not line: strippedContents.append("")
+    else:
+      line = multilineBuffer + line
+      multilineBuffer = ""
+      
+      if line.endswith("\\"):
+        multilineBuffer = line[:-1]
+        strippedContents.append("")
+      else:
+        strippedContents.append(line.strip())
   
-  conn = torTools.getConn()
-  contents = _stripComments(contents)
-  issuesFound, seenOptions = {}, []
-  for lineNumber in range(len(contents) - 1, -1, -1):
-    lineText = contents[lineNumber]
+  for lineNumber in range(len(strippedContents) - 1, -1, -1):
+    lineText = strippedContents[lineNumber]
     if not lineText: continue
     
     lineComp = lineText.split(None, 1)
@@ -367,6 +380,14 @@
     # issues GETCONF to get the values tor's currently configured to use
     torValues = conn.getOption(option, [], True)
     
+    # Some singleline entries are lists, in which case tor provides csv values
+    # without spaces, such as:
+    # lolcat1,lolcat2,cutebunny,extracutebunny,birthdaynode
+    # so we need to strip spaces in comma separated values.
+    
+    if "," in value:
+      value = ",".join([val.strip() for val in value.split(",")])
+    
     # multiline entries can be comma separated values (for both tor and conf)
     valueList = [value]
     if option in getMultilineParameters():