]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] acl: ignore empty lines and comments in pattern files
authorWilly Tarreau <w@1wt.eu>
Thu, 13 May 2010 20:07:43 +0000 (22:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 May 2010 20:10:02 +0000 (22:10 +0200)
Most often, pattern files used by ACLs will be produced by tools
which emit some comments (eg: geolocation lists). It's very annoying
to have to clean the files before using them, and it does not make
much sense to be able to support patterns we already can't input in
the config file. So this patch makes the pattern file loader skip
lines beginning with a sharp and the empty ones, and strips leading
spaces and tabs.

doc/configuration.txt
src/acl.c

index 1ca54fe80948d790ee2a99934dfc96399a2c9cc7..93914a57031c4569899d5cc63cf81f8fb42832f2 100644 (file)
@@ -5893,8 +5893,15 @@ The following ACL flags are currently supported :
 The "-f" flag is special as it loads all of the lines it finds in the file
 specified in argument and loads all of them before continuing. It is even
 possible to pass multiple "-f" arguments if the patterns are to be loaded from
-multiple files. Also, note that the "-i" flag applies to subsequent entries and
-not to entries loaded from files preceeding it. For instance :
+multiple files. Empty lines as well as lines beginning with a sharp ('#') will
+be ignored. All leading spaces and tabs will be stripped. If it is absolutely
+needed to insert a valid pattern beginning with a sharp, just prefix it with a
+space so that it is not taken for a comment. Depending on the data type and
+match method, haproxy may load the lines into a binary tree, allowing very fast
+lookups. This is true for IPv4 and exact string matching. In this case,
+duplicates will automatically be removed. Also, note that the "-i" flag applies
+to subsequent entries and not to entries loaded from files preceeding it. For
+instance :
 
     acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst  test
 
index f548c175667c49bc4d2a57342f6e8b0f0391d192..adf44941cbb6cde46224dc1c7ff33d0bed8455ca 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -770,11 +770,24 @@ static int acl_read_patterns_from_file(   struct acl_keyword *aclkw,
         */
        opaque = 0;
        pattern = NULL;
-       args[0] = trash;
        args[1] = "";
        while (fgets(trash, sizeof(trash), file) != NULL) {
 
                c = trash;
+
+               /* ignore lines beginning with a dash */
+               if (*c == '#')
+                       continue;
+
+               /* strip leading spaces and tabs */
+               while (*c == ' ' || *c == '\t')
+                       c++;
+
+               /* empty lines are ignored too */
+               if (!*c)
+                       continue;
+
+               args[0] = c;
                while (*c && *c != '\n' && *c != '\r')
                        c++;
                *c = 0;