From: Willy Tarreau Date: Thu, 13 May 2010 20:07:43 +0000 (+0200) Subject: [MINOR] acl: ignore empty lines and comments in pattern files X-Git-Tag: v1.4.5~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58215a01af0f2c07561dbe40abf1313105a016aa;p=thirdparty%2Fhaproxy.git [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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 1ca54fe809..93914a5703 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 diff --git a/src/acl.c b/src/acl.c index f548c17566..adf44941cb 100644 --- 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;