starter: Ingore %default conn and ca sections
authorTobias Brunner <tobias@strongswan.org>
Thu, 26 Jun 2014 10:23:05 +0000 (12:23 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 26 Jun 2014 10:23:05 +0000 (12:23 +0200)
src/starter/parser/conf_parser.c
src/starter/tests/suites/test_parser.c

index 119e379..6d1c54d 100644 (file)
@@ -292,12 +292,20 @@ static dictionary_t *section_dictionary_create(private_conf_parser_t *parser,
 
 static bool conn_filter(void *unused, section_t **section, char **name)
 {
+       if (streq((*section)->name, "%default"))
+       {
+               return FALSE;
+       }
        *name = (*section)->name;
        return TRUE;
 }
 
 static bool ca_filter(void *unused, void *key, char **name, section_t **section)
 {
+       if (streq((*section)->name, "%default"))
+       {
+               return FALSE;
+       }
        *name = (*section)->name;
        return TRUE;
 }
@@ -326,6 +334,10 @@ METHOD(conf_parser_t, get_section, dictionary_t*,
 {
        section_t *section = NULL;
 
+       if (name && streq(name, "%default"))
+       {
+               return NULL;
+       }
        switch (type)
        {
                case CONF_PARSER_CONFIG_SETUP:
index 684bc2a..26a41ba 100644 (file)
@@ -372,6 +372,49 @@ START_TEST(test_refcounting)
 }
 END_TEST
 
+START_TEST(test_default)
+{
+       enumerator_t *enumerator;
+       dictionary_t *dict;
+       char *name;
+
+       create_parser(chunk_from_str(
+               "conn %default\n"
+               "       key=valdef\n"
+               "       unset=set\n"
+               "conn A\n"
+               "       key=vala\n"
+               "       unset=\n"
+               "conn B\n"
+               "       keyb=valb\n"
+               ""));
+
+       ck_assert(parser->parse(parser));
+       dict = parser->get_section(parser, CONF_PARSER_CONN, "%default");
+       ck_assert(!dict);
+       enumerator = parser->get_sections(parser, CONF_PARSER_CONN);
+       ck_assert(enumerator);
+       ck_assert(enumerator->enumerate(enumerator, &name));
+       ck_assert_str_eq("A", name);
+       ck_assert(enumerator->enumerate(enumerator, &name));
+       ck_assert_str_eq("B", name);
+       ck_assert(!enumerator->enumerate(enumerator, &name));
+       enumerator->destroy(enumerator);
+
+       dict = parser->get_section(parser, CONF_PARSER_CONN, "A");
+       ck_assert(dict);
+       ck_assert_str_eq("vala", dict->get(dict, "key"));
+       ck_assert(!dict->get(dict, "unset"));
+       dict->destroy(dict);
+       dict = parser->get_section(parser, CONF_PARSER_CONN, "B");
+       ck_assert(dict);
+       ck_assert_str_eq("valdef", dict->get(dict, "key"));
+       ck_assert_str_eq("valb", dict->get(dict, "keyb"));
+       ck_assert_str_eq("set", dict->get(dict, "unset"));
+       dict->destroy(dict);
+}
+END_TEST
+
 START_TEST(test_also)
 {
        dictionary_t *dict;
@@ -517,6 +560,11 @@ Suite *parser_suite_create()
        tcase_add_test(tc, test_refcounting);
        suite_add_tcase(s, tc);
 
+       tc = tcase_create("%default");
+       tcase_add_checked_fixture(tc, NULL, teardown_parser);
+       tcase_add_test(tc, test_default);
+       suite_add_tcase(s, tc);
+
        tc = tcase_create("also=");
        tcase_add_checked_fixture(tc, NULL, teardown_parser);
        tcase_add_test(tc, test_also);