]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Revert "conf: Add support for escaping dots in section/option names"
authorTobias Brunner <tobias@strongswan.org>
Tue, 15 Oct 2024 10:44:02 +0000 (12:44 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 15 Oct 2024 10:59:41 +0000 (12:59 +0200)
This reverts commit 84a3077e780e7b25bf536da42a583bdc18448362.

Support for dots in names of settings was removed quite a while ago and
now the \. sequence caused `SyntaxWarning: invalid escape sequence`.

conf/format-options.py

index b36e28671cb178f0d272c3420be9bd527a0b34f2..e0fa180552ca169d8f714e31aec51bb06327cba2 100755 (executable)
@@ -55,14 +55,6 @@ man pages) the following format can be used:
 
 full.section.name.include files/to/include
        Description of this include statement
-
-Dots in section/option names may be escaped with a backslash.  For instance,
-with the following section description
-
-charon.filelog./var/log/daemon\.log {}
-       Section to define logging into /var/log/daemon.log
-
-/var/log/daemon.log will be the name of the last section.
 """
 
 import sys
@@ -74,10 +66,10 @@ from functools import cmp_to_key, total_ordering
 @total_ordering
 class ConfigOption:
        """Representing a configuration option or described section in strongswan.conf"""
-       def __init__(self, path, default = None, section = False, commented = False, include = False):
-               self.path = path
-               self.name = path[-1]
-               self.fullname = '.'.join(path)
+       def __init__(self, fullname, default = None, section = False, commented = False, include = False):
+               self.path = fullname.split('.')
+               self.name = self.path[-1]
+               self.fullname = fullname
                self.default = default
                self.section = section
                self.commented = commented
@@ -141,8 +133,7 @@ class Parser:
                if m:
                        if self.__current:
                                self.__add_option(self.__current)
-                       path = self.__split_name(m.group('name'))
-                       self.__current = ConfigOption(path, m.group('default'),
+                       self.__current = ConfigOption(m.group('name'), m.group('default'),
                                                                                  commented = not m.group('assign'))
                        return
                # section definition
@@ -150,8 +141,7 @@ class Parser:
                if m:
                        if self.__current:
                                self.__add_option(self.__current)
-                       path = self.__split_name(m.group('name'))
-                       self.__current = ConfigOption(path, section = True,
+                       self.__current = ConfigOption(m.group('name'), section = True,
                                                                                  commented = m.group('comment'))
                        return
                # include definition
@@ -159,8 +149,7 @@ class Parser:
                if m:
                        if self.__current:
                                self.__add_option(self.__current)
-                       path = self.__split_name(m.group('name'))
-                       self.__current = ConfigOption(path, m.group('pattern'), include = True)
+                       self.__current = ConfigOption(m.group('name'), m.group('pattern'), include = True)
                        return
                # paragraph separator
                m = re.match(r'^\s*$', line)
@@ -171,10 +160,6 @@ class Parser:
                if m and self.__current:
                        self.__current.add(m.group('text'))
 
-       def __split_name(self, name):
-               """Split the given full name in a list of section/option names"""
-               return [x.replace('\.', '.') for x in re.split(r'(?<!\\)\.', name)]
-
        def __add_option(self, option):
                """Adds the given option to the abstract storage"""
                option.desc = [desc for desc in option.desc if len(desc)]
@@ -194,12 +179,14 @@ class Parser:
                """Searches/Creates the option (section) based on a list of section names"""
                option = None
                options = self.options
-               for i, name in enumerate(path, 1):
+               fullname = ""
+               for name in path:
+                       fullname += '.' + name if len(fullname) else name
                        option = next((x for x in options if x.name == name and x.section), None)
                        if not option:
                                if not create:
                                        break
-                               option = ConfigOption(path[:i], section = True)
+                               option = ConfigOption(fullname, section = True)
                                options.append(option)
                                if self.sort:
                                        options.sort()
@@ -208,7 +195,7 @@ class Parser:
 
        def get_option(self, name):
                """Retrieves the option with the given name"""
-               return self.__get_option(self.__split_name(name))
+               return self.__get_option(name.split('.'))
 
 class TagReplacer:
        """Replaces formatting tags in text"""