From Evan Huus:

Don't initialize GeoIP from epan_init(), as we probably haven't loaded the
preferences for it yet (thanks to it's new use of the UAT framework).

Instead, register a post_update callback with UAT and load it there. As a
bonus, this also means that applying GeoIP preferences no longer requires
restarting Wireshark - everything should Just Work with the new databases right
away.

Fixes bug 7446.

svn path=/trunk/; revision=43604
This commit is contained in:
Guy Harris 2012-07-08 01:17:19 +00:00
parent 659cf0527a
commit 10fa9baef2
3 changed files with 64 additions and 15 deletions

View File

@ -120,10 +120,6 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
#ifdef HAVE_LUA
wslua_init(cb, client_data);
#endif
#ifdef HAVE_GEOIP
geoip_db_init();
#endif
}
void

View File

@ -137,6 +137,62 @@ static void geoip_db_path_free_cb(void* p) {
g_free(m->path);
}
/* called every time the user presses "Apply" or "OK in the list of
* GeoIP directories, and also once on startup */
static void geoip_db_post_update_cb(void) {
GeoIP *gi;
guint i;
/* If we have old data, clear out the whole thing
* and start again. TODO: Just update the ones that
* have changed for efficiency's sake. */
if (geoip_dat_arr) {
/* skip the last two, as they are fake */
for (i = 0; i < geoip_db_num_dbs() - 2; i++) {
gi = g_array_index(geoip_dat_arr, GeoIP *, i);
if (gi) {
GeoIP_delete(gi);
}
}
/* don't use GeoIP_delete() on the two fake
* databases as they weren't created by GeoIP_new()
* or GeoIP_open() */
gi = g_array_index(geoip_dat_arr, GeoIP *, i);
if (gi) {
free(gi);
}
gi = g_array_index(geoip_dat_arr, GeoIP *, i+1);
if (gi) {
free(gi);
}
/* finally, free the array itself */
g_array_free(geoip_dat_arr, TRUE);
}
/* allocate the array */
geoip_dat_arr = g_array_new(FALSE, FALSE, sizeof(GeoIP *));
/* Walk all the directories */
for (i = 0; i < num_geoip_db_paths; i++) {
if (geoip_db_paths[i].path) {
geoip_dat_scan_dir(geoip_db_paths[i].path);
}
}
/* add fake databases for latitude and longitude
* (using "City" in reality) */
/* latitude */
gi = g_malloc(sizeof (GeoIP));
gi->databaseType = WS_LAT_FAKE_EDITION;
g_array_append_val(geoip_dat_arr, gi);
/* longitude */
gi = g_malloc(sizeof (GeoIP));
gi->databaseType = WS_LON_FAKE_EDITION;
g_array_append_val(geoip_dat_arr, gi);
}
/**
* Initialize GeoIP lookups
*/
@ -161,18 +217,16 @@ geoip_db_pref_init(module_t *nameres)
geoip_db_path_copy_cb,
NULL,
geoip_db_path_free_cb,
NULL,
geoip_db_post_update_cb,
geoip_db_paths_fields);
prefs_register_uat_preference(nameres,
"geoip_db_paths",
"GeoIP database directories",
"Search paths for GeoIP address mapping databases.\n"
"Wireshark will look in each directory for files beginning\n"
"with \"Geo\" and ending with \".dat\".\n"
"You must restart Wireshark for these changes to take\n"
"effect.",
geoip_db_paths_uat);
prefs_register_uat_preference(nameres,
"geoip_db_paths",
"GeoIP database directories",
"Search paths for GeoIP address mapping databases.\n"
"Wireshark will look in each directory for files beginning\n"
"with \"Geo\" and ending with \".dat\".",
geoip_db_paths_uat);
}
void

View File

@ -39,7 +39,6 @@
/**
* Init function called from epan.h
*/
extern void geoip_db_init(void);
extern void geoip_db_pref_init(module_t *nameres);
/**