diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-07-13 17:23:37 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-07-13 17:23:37 -0400 |
commit | ef4ea864ea66059f7fd71ac68cfe6067f32149f1 (patch) | |
tree | ef4e15abb8f5b846269479ba7cdc8320602f903d /src/test/test_helpers.c | |
parent | 62d241ad22b173ee908ad9cc2c55f5b10d22c2d9 (diff) | |
parent | 965e3a6628f26d5fb1422fb04aa12e807537a32a (diff) | |
download | tor-ef4ea864ea66059f7fd71ac68cfe6067f32149f1.tar.gz tor-ef4ea864ea66059f7fd71ac68cfe6067f32149f1.zip |
Merge remote-tracking branch 'dgoulet/ticket21979_032_04'
Diffstat (limited to 'src/test/test_helpers.c')
-rw-r--r-- | src/test/test_helpers.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c index 22d9de3f5b..e885d27815 100644 --- a/src/test/test_helpers.c +++ b/src/test/test_helpers.c @@ -7,18 +7,21 @@ */ #define ROUTERLIST_PRIVATE +#define CONFIG_PRIVATE #define CONNECTION_PRIVATE #define MAIN_PRIVATE #include "orconfig.h" #include "or.h" +#include "buffers.h" +#include "config.h" +#include "confparse.h" #include "connection.h" #include "main.h" +#include "nodelist.h" #include "relay.h" #include "routerlist.h" -#include "nodelist.h" -#include "buffers.h" #include "test.h" #include "test_helpers.h" @@ -239,3 +242,38 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose) return NULL; } +/* Helper function to parse a set of torrc options in a text format and return + * a newly allocated or_options_t object containing the configuration. On + * error, NULL is returned indicating that the conf couldn't be parsed + * properly. */ +or_options_t * +helper_parse_options(const char *conf) +{ + int ret = 0; + char *msg = NULL; + or_options_t *opt = NULL; + config_line_t *line = NULL; + + /* Kind of pointless to call this with a NULL value. */ + tt_assert(conf); + + opt = options_new(); + tt_assert(opt); + ret = config_get_lines(conf, &line, 1); + if (ret != 0) { + goto done; + } + ret = config_assign(&options_format, opt, line, 0, &msg); + if (ret != 0) { + goto done; + } + + done: + config_free_lines(line); + if (ret != 0) { + or_options_free(opt); + opt = NULL; + } + return opt; +} + |