Commit af175fa7 authored by Linus Nordberg's avatar Linus Nordberg
Browse files

Duplicate less code.

parent 817ff962
......@@ -482,6 +482,8 @@ static void init_libevent(const or_options_t *options);
static int opt_streq(const char *s1, const char *s2);
static int parse_outbound_addresses(or_options_t *options, int validate_only,
char **msg);
static void config_maybe_load_geoip_files_(const or_options_t *options,
const or_options_t *old_options);
/** Magic value for or_options_t. */
#define OR_OPTIONS_MAGIC 9090909
......@@ -1512,44 +1514,7 @@ options_act(const or_options_t *old_options)
connection_or_update_token_buckets(get_connection_array(), options);
}
/* Maybe load IPv4 geoip file */
if (options->GeoIPFile &&
((!old_options || !opt_streq(old_options->GeoIPFile, options->GeoIPFile))
|| !geoip_is_loaded(AF_INET))) {
/* XXXX Don't use this "<default>" junk; make our filename options
* understand prefixes somehow. -NM */
/* XXXX024 Reload GeoIPFile on SIGHUP. -NM */
char *actual_fname = tor_strdup(options->GeoIPFile);
#ifdef _WIN32
if (!strcmp(actual_fname, "<default>")) {
const char *conf_root = get_windows_conf_root();
tor_free(actual_fname);
tor_asprintf(&actual_fname, "%s\\geoip", conf_root);
}
#endif
geoip_load_file(AF_INET, actual_fname, options);
tor_free(actual_fname);
}
/* And maybe load IPv6 geoip file */
if (options->GeoIPv6File &&
((!old_options || !opt_streq(old_options->GeoIPv6File,
options->GeoIPv6File))
|| !geoip_is_loaded(AF_INET6))) {
/* XXXX Don't use this "<default>" junk; make our filename options
* understand prefixes somehow. See also comment for GeoIPFile. */
/* XXXX024 Reload GeoIPV6File on SIGHUP. See also comment for
* GeoIPFile. */
char *actual_fname = tor_strdup(options->GeoIPv6File);
#ifdef _WIN32
if (!strcmp(actual_fname, "<default>")) {
const char *conf_root = get_windows_conf_root();
tor_free(actual_fname);
tor_asprintf(&actual_fname, "%s\\geoip6", conf_root);
}
#endif
geoip_load_file(AF_INET6, actual_fname, options);
tor_free(actual_fname);
}
config_maybe_load_geoip_files_(options, old_options);
if (options->CellStatistics || options->DirReqStatistics ||
options->EntryStatistics || options->ExitPortStatistics ||
......@@ -5599,3 +5564,38 @@ parse_outbound_addresses(or_options_t *options, int validate_only, char **msg)
return 0;
}
static void
config_load_geoip_file_(sa_family_t family,
char *fname, /* will be freed */
const char *default_fname)
{
(void)default_fname;
/* XXXX Don't use this "<default>" junk; make our filename options
* understand prefixes somehow. -NM */
/* XXXX024 Reload GeoIPFile on SIGHUP. -NM */
#ifdef _WIN32
if (!strcmp(fname, "<default>")) {
const char *conf_root = get_windows_conf_root();
tor_free(fname);
tor_asprintf(&fname, "%s\\%s", conf_root, default_fname);
}
#endif
geoip_load_file(family, fname);
tor_free(fname);
}
static void
config_maybe_load_geoip_files_(const or_options_t *options,
const or_options_t *old_options)
{
if (options->GeoIPFile &&
((!old_options || !opt_streq(old_options->GeoIPFile,
options->GeoIPFile))
|| !geoip_is_loaded(AF_INET)))
config_load_geoip_file_(AF_INET, tor_strdup(options->GeoIPFile), "geoip");
if (options->GeoIPv6File &&
((!old_options || !opt_streq(old_options->GeoIPv6File,
options->GeoIPv6File))
|| !geoip_is_loaded(AF_INET6)))
config_load_geoip_file_(AF_INET6, tor_strdup(options->GeoIPv6File), "geoip6");
}
......@@ -326,11 +326,11 @@ init_geoip_countries(void)
* with '#' (comments).
*/
int
geoip_load_file(sa_family_t family, const char *filename,
const or_options_t *options)
geoip_load_file(sa_family_t family, const char *filename)
{
FILE *f;
const char *msg = "";
const or_options_t *options = get_options();
int severity = options_need_geoip_info(options, &msg) ? LOG_WARN : LOG_INFO;
crypto_digest_t *geoip_digest_env = NULL;
......
......@@ -19,8 +19,7 @@ int geoip_get_country_by_ipv4(uint32_t ipaddr);
int geoip_get_country_by_ipv6(const struct in6_addr *addr);
#endif
int should_record_bridge_info(const or_options_t *options);
int geoip_load_file(sa_family_t family, const char *filename,
const or_options_t *options);
int geoip_load_file(sa_family_t family, const char *filename);
int geoip_get_country_by_addr(const tor_addr_t *addr);
int geoip_get_n_countries(void);
const char *geoip_get_country_name(country_t num);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment