diff options
author | teor <teor2345@gmail.com> | 2016-11-04 16:28:33 +1100 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2016-11-18 13:35:54 +1100 |
commit | 1d1d37bbc672f28ac481511df3a5dc4c9c732ed0 (patch) | |
tree | 0971c02263fb1e2f675446de74c72b5d56e17902 /src | |
parent | 8bdedab8da25382aa5f33297bedddfa4b8715c43 (diff) | |
download | tor-1d1d37bbc672f28ac481511df3a5dc4c9c732ed0.tar.gz tor-1d1d37bbc672f28ac481511df3a5dc4c9c732ed0.zip |
Refactor rend_service_check_dir_and_add
Make the function flatter, and prepare for #20559.
No behaviour change.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/rendservice.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/or/rendservice.c b/src/or/rendservice.c index cf71db59ba..d4d2405cc8 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -450,27 +450,34 @@ rend_service_port_config_free(rend_service_port_config_t *p) * If <b>validate_only</b> is true, free the service. * If <b>service</b> is NULL, ignore it, and return 0. * Returns 0 on success, and -1 on failure. - * Takes ownership of <b>service</b>. + * Takes ownership of <b>service</b>, either freeing it, or adding it to the + * global service list. */ static int rend_service_check_dir_and_add(const or_options_t *options, rend_service_t *service, int validate_only) { - if (service) { /* register the one we just finished parsing */ - if (rend_service_check_private_dir(options, service, !validate_only) - < 0) { - rend_service_free(service); - return -1; - } + if (!service) { + /* It is ok for a service to be NULL, this means there are no services */ + return 0; + } - if (validate_only) - rend_service_free(service); - else - rend_add_service(service); + if (rend_service_check_private_dir(options, service, !validate_only) + < 0) { + rend_service_free(service); + return -1; } - return 0; + if (validate_only) { + rend_service_free(service); + return 0; + } else { + /* rend_add_service takes ownership, either adding or freeing the service + */ + rend_add_service(service); + return 0; + } } /** Set up rend_service_list, based on the values of HiddenServiceDir and |