mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-01 22:48:25 +00:00
[MINOR] acl: ignore empty lines and comments in pattern files
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.
This commit is contained in:
parent
b337b532de
commit
58215a01af
@ -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
|
||||
|
||||
|
15
src/acl.c
15
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;
|
||||
|
Loading…
Reference in New Issue
Block a user