From 71a6151083d842b2f5bf04e50239f0bf85d34d2e Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 19 Nov 2013 16:17:55 +0100 Subject: conf-parser: distinguish between multiple sections with the same name Pass on the line on which a section was decleared to the parsers, so they can distinguish between multiple sections (if they chose to). Currently no parsers take advantage of this, but a follow-up patch will do that to distinguish [Address] Address=192.168.0.1/24 Label=one [Address] Address=192.168.0.2/24 Label=two from [Address] Address=192.168.0.1/24 Label=one Address=192.168.0.2/24 Label=two --- src/shared/conf-parser.c | 24 +++++++++++++++++++++--- src/shared/conf-parser.h | 39 +++++++++++++++++++++------------------ src/shared/install.c | 2 ++ src/shared/net-util.c | 3 +++ src/shared/net-util.h | 12 ++++++------ 5 files changed, 53 insertions(+), 27 deletions(-) (limited to 'src/shared') diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 95d64fcca2..1e3cee5beb 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -156,6 +156,7 @@ static int next_assignment(const char *unit, ConfigItemLookup lookup, void *table, const char *section, + unsigned section_line, const char *lvalue, const char *rvalue, bool relaxed, @@ -178,8 +179,8 @@ static int next_assignment(const char *unit, if (r > 0) { if (func) - return func(unit, filename, line, section, lvalue, ltype, - rvalue, data, userdata); + return func(unit, filename, line, section, section_line, + lvalue, ltype, rvalue, data, userdata); return 0; } @@ -202,6 +203,7 @@ static int parse_line(const char* unit, bool relaxed, bool allow_include, char **section, + unsigned *section_line, char *l, void *userdata) { @@ -262,9 +264,11 @@ static int parse_line(const char* unit, free(n); free(*section); *section = NULL; + *section_line = 0; } else { free(*section); *section = n; + *section_line = line; } return 0; @@ -294,6 +298,7 @@ static int parse_line(const char* unit, lookup, table, *section, + *section_line, strstrip(l), strstrip(e), relaxed, @@ -313,7 +318,7 @@ int config_parse(const char *unit, _cleanup_free_ char *section = NULL, *continuation = NULL; _cleanup_fclose_ FILE *ours = NULL; - unsigned line = 0; + unsigned line = 0, section_line = 0; int r; assert(filename); @@ -382,6 +387,7 @@ int config_parse(const char *unit, relaxed, allow_include, §ion, + §ion_line, p, userdata); free(c); @@ -398,6 +404,7 @@ int config_parse(const char *unit, const char *filename, \ unsigned line, \ const char *section, \ + unsigned section_line, \ const char *lvalue, \ int ltype, \ const char *rvalue, \ @@ -434,6 +441,7 @@ int config_parse_bytes_size(const char* unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -465,6 +473,7 @@ int config_parse_bytes_off(const char* unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -493,6 +502,7 @@ int config_parse_bool(const char* unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -522,6 +532,7 @@ int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -562,6 +573,7 @@ int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -607,6 +619,7 @@ int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -663,6 +676,7 @@ int config_parse_path_strv(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -720,6 +734,7 @@ int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -757,6 +772,7 @@ int config_parse_facility(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -787,6 +803,7 @@ int config_parse_level(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -816,6 +833,7 @@ int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 312315b35e..42602b3b08 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -34,6 +34,7 @@ typedef int (*ConfigParserCallback)(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -91,24 +92,24 @@ int config_parse(const char *unit, void *userdata); /* Generic parsers */ -int config_parse_int(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_unsigned(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_long(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_uint64(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_double(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_bytes_size(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_bytes_off(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_bool(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_path_strv(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_sec(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_nsec(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_facility(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_level(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_int(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_unsigned(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_long(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_uint64(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_double(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bytes_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bytes_off(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bool(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_path_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_nsec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_facility(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_level(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int log_syntax_internal(const char *unit, int level, const char *file, unsigned line, const char *func, @@ -126,6 +127,7 @@ int log_syntax_internal(const char *unit, int level, const char *filename, \ unsigned line, \ const char *section, \ + unsigned section_line, \ const char *lvalue, \ int ltype, \ const char *rvalue, \ @@ -154,6 +156,7 @@ int log_syntax_internal(const char *unit, int level, const char *filename, \ unsigned line, \ const char *section, \ + unsigned section_line, \ const char *lvalue, \ int ltype, \ const char *rvalue, \ diff --git a/src/shared/install.c b/src/shared/install.c index 16504eef0f..100ed69744 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -922,6 +922,7 @@ static int config_parse_also(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -957,6 +958,7 @@ static int config_parse_user(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, diff --git a/src/shared/net-util.c b/src/shared/net-util.c index f2fd0819d3..fa89bd904f 100644 --- a/src/shared/net-util.c +++ b/src/shared/net-util.c @@ -87,6 +87,7 @@ int config_parse_ifname(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -127,6 +128,7 @@ int config_parse_ifalias(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, @@ -167,6 +169,7 @@ int config_parse_hwaddr(const char *unit, const char *filename, unsigned line, const char *section, + unsigned section_line, const char *lvalue, int ltype, const char *rvalue, diff --git a/src/shared/net-util.h b/src/shared/net-util.h index d6ca737e7f..c7edfb96f0 100644 --- a/src/shared/net-util.h +++ b/src/shared/net-util.h @@ -36,15 +36,15 @@ bool net_match_config(const struct ether_addr *match_mac, const char *dev_name); int config_parse_hwaddr(const char *unit, const char *filename, unsigned line, - const char *section, const char *lvalue, int ltype, - const char *rvalue, void *data, void *userdata); + const char *section, unsigned section_line, const char *lvalue, + int ltype, const char *rvalue, void *data, void *userdata); int config_parse_ifname(const char *unit, const char *filename, unsigned line, - const char *section, const char *lvalue, int ltype, - const char *rvalue, void *data, void *userdata); + const char *section, unsigned section_line, const char *lvalue, + int ltype, const char *rvalue, void *data, void *userdata); int config_parse_ifalias(const char *unit, const char *filename, unsigned line, - const char *section, const char *lvalue, int ltype, - const char *rvalue, void *data, void *userdata); + const char *section, unsigned section_line, const char *lvalue, + int ltype, const char *rvalue, void *data, void *userdata); int net_parse_inaddr(const char *address, unsigned char *family, void *dst); -- cgit v1.2.3-54-g00ecf