call to cfg_register_section() with the three arguments at stage
STG_REGISTER.
+ You can only register a section once, but you can register post callbacks
+ multiple time for this section with REGISTER_CONFIG_SECTION_POST().
+
+- REGISTER_CONFIG_SECTION_POST(name, post)
+
+ Registers a function which will be called after a section is parsed. This is
+ the same as the <post> argument in REGISTER_CONFIG_SECTION(), the difference
+ is that it allows to register multiple <post> callbacks and to register them
+ elsewhere in the code.
+
- REGISTER_PER_THREAD_ALLOC(fct)
Registers a call to register_per_thread_alloc(fct) at stage STG_REGISTER.
#define REGISTER_CONFIG_SECTION(name, parse, post) \
INITCALL3(STG_REGISTER, cfg_register_section, (name), (parse), (post))
+/* simplified way to define a post section parser */
+#define REGISTER_CONFIG_POST_SECTION(name, post) \
+ INITCALL3(STG_REGISTER, cfg_register_section, (name), NULL, (post))
+
#define REGISTER_CONFIG_POSTPARSER(name, parser) \
INITCALL2(STG_REGISTER, cfg_register_postparser, (name), (parser))
/* if a word is in sections list, is_sect = 1 */
list_for_each_entry(sect, §ions, list) {
- if (strcmp(args[0], sect->section_name) == 0) {
+ /* look for a section_name, but also a section_parser, because there might be
+ * only a post_section_parser */
+ if (strcmp(args[0], sect->section_name) == 0 &&
+ sect->section_parser) {
is_sect = 1;
break;
}
/* detect section start */
list_for_each_entry(ics, §ions, list) {
- if (strcmp(args[0], ics->section_name) == 0) {
+ if (strcmp(args[0], ics->section_name) == 0 && ics->section_parser) {
cursection = ics->section_name;
pcs = cs;
cs = ics;
}
}
- if (pcs && pcs->post_section_parser) {
+ if (pcs) {
+ struct cfg_section *psect;
int status;
- /* don't call post_section_parser in MODE_DISCOVERY */
- if (global.mode & MODE_DISCOVERY)
- goto section_parser;
- status = pcs->post_section_parser();
- err_code |= status;
- if (status & ERR_FATAL)
- fatal++;
+ /* look for every post_section_parser for the previous section name */
+ list_for_each_entry(psect, §ions, list) {
+ if (strcmp(pcs->section_name, psect->section_name) == 0 &&
+ psect->post_section_parser) {
- if (err_code & ERR_ABORT)
- goto err;
+ /* don't call post_section_parser in MODE_DISCOVERY */
+ if (global.mode & MODE_DISCOVERY)
+ goto section_parser;
+
+ status = psect->post_section_parser();
+ err_code |= status;
+ if (status & ERR_FATAL)
+ fatal++;
+
+ if (err_code & ERR_ABORT)
+ goto err;
+ }
+ }
}
pcs = NULL;
ha_free(&global.cfg_curr_section);
/* call post_section_parser of the last section when there is no more lines */
- if (cs && cs->post_section_parser) {
+ if (cs) {
+ struct cfg_section *psect;
+
/* don't call post_section_parser in MODE_DISCOVERY */
- if (!(global.mode & MODE_DISCOVERY))
- err_code |= cs->post_section_parser();
+ if (!(global.mode & MODE_DISCOVERY)) {
+ list_for_each_entry(psect, §ions, list) {
+ if (strcmp(cs->section_name, psect->section_name) == 0 &&
+ psect->post_section_parser) {
+
+ err_code |= cs->post_section_parser();
+ }
+ }
+ }
}
if (nested_cond_lvl) {
{
struct cfg_section *cs;
- list_for_each_entry(cs, §ions, list) {
- if (strcmp(cs->section_name, section_name) == 0) {
- ha_alert("register section '%s': already registered.\n", section_name);
- return 0;
+ if (section_parser) {
+ /* only checks if we register a section parser, not a post section callback */
+ list_for_each_entry(cs, §ions, list) {
+ if (strcmp(cs->section_name, section_name) == 0 && cs->section_parser) {
+ ha_alert("register section '%s': already registered.\n", section_name);
+ return 0;
+ }
}
}