@@ -35,33 +35,37 @@ static GeoIP *geoip6;
3535#endif
3636
3737
38- void geoip_reinit () {
38+ void geoip_reinit (int v ) {
3939#ifdef USE_GEOIP
40- if (geoip4 )
41- GeoIP_delete (geoip4 );
42- if (geoip6 )
43- GeoIP_delete (geoip6 );
44- /* Get the file paths directly, so that we can offer more useful diagnostic
45- * messages in case we fail to open it. Calling GeoIP_db_avail() ensures that
46- * the GeoIPDBFileName variable has been initialized. */
47- if (!GeoIPDBFileName )
48- GeoIP_db_avail (GEOIP_COUNTRY_EDITION );
49- const char * f4 = GeoIPDBFileName [GEOIP_COUNTRY_EDITION ];
50- const char * f6 = GeoIPDBFileName [GEOIP_COUNTRY_EDITION_V6 ];
51-
52- /* The '16' flag is GEOIP_SILENCE, but it's a fairly new option and not
53- * defined in older versions. Just pass it along directly, ABI compatibility
54- * should ensure this works with both old and new versions.
55- * Also perform a g_file_test() first to ensure we're not opening
56- * non-existing files. GeoIP versions that do not support GEOIP_SILENCE will
57- * throw error messages on stdout, which screws up our ncurses UI, so
58- * catching the most common error here is worth it. */
59- geoip4 = g_file_test (f4 , G_FILE_TEST_EXISTS ) ? GeoIP_open (f4 , 16 | GEOIP_MEMORY_CACHE ) : NULL ;
60- geoip6 = g_file_test (f6 , G_FILE_TEST_EXISTS ) ? GeoIP_open (f6 , 16 | GEOIP_MEMORY_CACHE ) : NULL ;
61- if (!geoip4 )
62- ui_mf (uit_main_tab , 0 , "Unable to open '%s', no country codes will be displayed for IPv4 addresses." , f4 );
63- if (!geoip6 )
64- ui_mf (uit_main_tab , 0 , "Unable to open '%s', no country codes will be displayed for IPv6 addresses." , f6 );
40+ GeoIP * * var = v == 4 ? & geoip4 : & geoip6 ;
41+ if (* var ) {
42+ GeoIP_delete (* var );
43+ * var = NULL ;
44+ }
45+
46+ const char * fn = var_get (0 , v == 4 ? VAR_geoip_cc4 : VAR_geoip_cc6 );
47+ if (!fn ) {
48+ /* Get the file paths directly, so that we can offer more useful diagnostic
49+ * messages in case we fail to open it. Calling GeoIP_db_avail() ensures that
50+ * the GeoIPDBFileName variable has been initialized. */
51+ if (!GeoIPDBFileName )
52+ GeoIP_db_avail (GEOIP_COUNTRY_EDITION );
53+ fn = GeoIPDBFileName [v == 4 ? GEOIP_COUNTRY_EDITION : GEOIP_COUNTRY_EDITION_V6 ];
54+ }
55+
56+ if (strcmp (fn , "disabled" ) != 0 ) {
57+ /* The '16' flag is GEOIP_SILENCE, but it's a fairly new option and not
58+ * defined in older versions. Just pass it along directly, ABI compatibility
59+ * should ensure this works with both old and new versions.
60+ * Also perform a g_file_test() first to ensure we're not opening
61+ * non-existing files. GeoIP versions that do not support GEOIP_SILENCE
62+ * will throw error messages on stdout/stderr, which screws up our ncurses
63+ * UI, so catching the most common error here is worth it. */
64+ * var = g_file_test (fn , G_FILE_TEST_EXISTS ) ? GeoIP_open (fn , 16 | GEOIP_MEMORY_CACHE ) : NULL ;
65+ if (!* var )
66+ ui_mf (NULL , 0 , "Can't open '%s', no country codes will be displayed for IPv%d addresses." , fn , v );
67+ }
68+
6569 geoip_available = geoip4 || geoip6 ;
6670#endif
6771}
0 commit comments