]>
git.ipfire.org Git - people/ms/strongswan.git/blob - scripts/settings-test.c
2 * Copyright (C) 2014 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 #include <settings/settings_types.h>
27 * Defined in libstrongswan but not part of the public API
29 bool settings_parser_parse_file(void *this, char *name
);
32 * Recursively print the section and all subsections/settings
34 static void print_section(section_t
*section
, int level
)
41 for (i
= 0; i
< level
* 2 && i
< sizeof(indent
) - 2; i
+= 2)
48 for (i
= 0; i
< array_count(section
->kv_order
); i
++)
50 array_get(section
->kv_order
, i
, &kv
);
51 printf("%s%s = %s\n", indent
, kv
->key
, kv
->value
);
53 for (i
= 0; i
< array_count(section
->sections_order
); i
++)
55 array_get(section
->sections_order
, i
, &sub
);
56 printf("%s%s {\n", indent
, sub
->name
);
57 print_section(sub
, level
+ 1);
58 printf("%s}\n", indent
);
62 static void usage(FILE *out
, char *name
)
64 fprintf(out
, "Test strongswan.conf parser\n\n");
65 fprintf(out
, "%s [OPTIONS]\n\n", name
);
66 fprintf(out
, "Options:\n");
67 fprintf(out
, " -h, --help print this help.\n");
68 fprintf(out
, " -d, --debug enables debugging of the parser.\n");
69 fprintf(out
, " -f, --file=FILE config file to load (default STDIN).\n");
73 int main(int argc
, char *argv
[])
77 /* don't load strongswan.conf */
78 library_init("", "settings-test");
79 atexit(library_deinit
);
81 dbg_default_set_level(3);
85 struct option long_opts
[] = {
86 {"help", no_argument
, NULL
, 'h' },
87 {"debug", no_argument
, NULL
, 'd' },
88 {"file", required_argument
, NULL
, 'f' },
91 switch (getopt_long(argc
, argv
, "hdf:", long_opts
, NULL
))
96 usage(stdout
, argv
[0]);
99 setenv("DEBUG_SETTINGS_PARSER", "1", TRUE
);
105 usage(stderr
, argv
[0]);
113 section_t
*root
= settings_section_create(strdup("root"));
115 settings_parser_parse_file(root
, file
);
117 print_section(root
, 0);
119 settings_section_destroy(root
, NULL
);
123 usage(stderr
, argv
[0]);