/** * Loads the spam.txt into memory. * * The selected file will then be monitored and a reloading will occur * shortly after a modification. */ static void spam_retrieve(void) { file_path_t fp[4]; FILE *f; int idx; char *tmp; unsigned length = 0; file_path_set(&fp[length++], settings_config_dir(), spam_text_file); file_path_set(&fp[length++], PRIVLIB_EXP, spam_text_file); #ifndef OFFICIAL_BUILD file_path_set(&fp[length++], PACKAGE_EXTRA_SOURCE_DIR, spam_text_file); #endif /* !OFFICIAL_BUILD */ tmp = get_folder_path(PRIVLIB_PATH, NULL); if (tmp != NULL) file_path_set(&fp[length++], tmp, spam_text_file); g_assert(length <= G_N_ELEMENTS(fp)); f = file_config_open_read_norename_chosen(spam_what, fp, length, &idx); if (f != NULL) { spam_retrieve_from_file(f, fp[idx].dir, fp[idx].name); fclose(f); } HFREE_NULL(tmp); }
/** * Loads the geo-ip.txt into memory. * * Choosing the first file we find among the several places we look at, * typically: * * -# ~/.gtk-gnutella/geo-ip.txt * -# /usr/share/gtk-gnutella/geo-ip.txt * -# /home/src/gtk-gnutella/geo-ip.txt * * The selected file will then be monitored and a reloading will occur * shortly after a modification. */ static void gip_retrieve(unsigned n) { FILE *f; int idx; char *filename; file_path_t fp[4]; unsigned length; length = settings_file_path_load(fp, gip_source[n].file, SFP_DFLT); g_assert(length <= N_ITEMS(fp)); f = file_config_open_read_norename_chosen( gip_source[n].what, fp, length, &idx); if (NULL == f) return; filename = make_pathname(fp[idx].dir, fp[idx].name); watcher_register(filename, gip_changed, uint_to_pointer(n)); HFREE_NULL(filename); gip_load(f, n); fclose(f); }
/** * Loads the geo-ip.txt into memory. * * Choosing the first file we find among the several places we look at, * typically: * * -# ~/.gtk-gnutella/geo-ip.txt * -# /usr/share/gtk-gnutella/geo-ip.txt * -# /home/src/gtk-gnutella/geo-ip.txt * * The selected file will then be monitored and a reloading will occur * shortly after a modification. */ static void gip_retrieve(unsigned n) { FILE *f; int idx; char *filename; file_path_t fp[4]; unsigned length = 0; char *tmp; file_path_set(&fp[length++], settings_config_dir(), gip_source[n].file); tmp = get_folder_path(PRIVLIB_PATH, NULL); if (tmp != NULL) file_path_set(&fp[length++], tmp, gip_source[n].file); file_path_set(&fp[length++], PRIVLIB_EXP, gip_source[n].file); #ifndef OFFICIAL_BUILD file_path_set(&fp[length++], PACKAGE_EXTRA_SOURCE_DIR, gip_source[n].file); #endif g_assert(length <= G_N_ELEMENTS(fp)); f = file_config_open_read_norename_chosen(gip_source[n].what, fp, length, &idx); if (NULL == f) goto done; filename = make_pathname(fp[idx].dir, fp[idx].name); watcher_register(filename, gip_changed, uint_to_pointer(n)); HFREE_NULL(filename); gip_load(f, n); fclose(f); done: HFREE_NULL(tmp); }
/** * Loads the bogons.txt into memory. * * Choosing the first file we find among the several places we look at, * typically: * * -# ~/.gtk-gnutella/bogons.txt * -# /usr/share/gtk-gnutella/bogons.txt * -# PACKAGE_EXTRA_SOURCE_DIR/bogons.txt * * The selected file will then be monitored and a reloading will occur * shortly after a modification. */ static G_GNUC_COLD void bogons_retrieve(void) { FILE *f; int idx; char *filename; file_path_t fp[4]; unsigned length = 0; char *tmp; file_path_set(&fp[length++], settings_config_dir(), bogons_file); tmp = get_folder_path(PRIVLIB_PATH, NULL); if (tmp != NULL) file_path_set(&fp[length++], tmp, bogons_file); file_path_set(&fp[length++], PRIVLIB_EXP, bogons_file); #ifndef OFFICIAL_BUILD file_path_set(&fp[length++], PACKAGE_EXTRA_SOURCE_DIR, bogons_file); #endif g_assert(length <= G_N_ELEMENTS(fp)); f = file_config_open_read_norename_chosen(bogons_what, fp, length, &idx); if (NULL == f) goto done; filename = make_pathname(fp[idx].dir, fp[idx].name); watcher_register(filename, bogons_changed, NULL); HFREE_NULL(filename); bogons_load(f); fclose(f); done: HFREE_NULL(tmp); }
/** * Retrieve known GWC URLs. * They are normally saved in ~/.gtk-gnutella/gwcache. */ static void gwc_retrieve(void) { file_path_t fp[4], *fpv; uint len, added; int line, idx; FILE *in; char tmp[1024]; len = settings_file_path_load(fp, gwc_file, SFP_ALL); g_assert(len <= N_ITEMS(fp)); fpv = &fp[0]; retry: g_assert(ptr_cmp(fpv, &fp[N_ITEMS(fp)]) < 0); if (&fp[0] == fpv) in = file_config_open_read_chosen(gwc_what, fpv, len, &idx); else in = file_config_open_read_norename_chosen(gwc_what, fpv, len, &idx); if (NULL == in) return; /* * Retrieve each line, counting the amount of entries added. */ line = 0; added = 0; while (fgets(tmp, sizeof(tmp), in)) { line++; if (tmp[0] == '#') /* Skip comments */ continue; if (tmp[0] == '\n') /* Allow empty lines */ continue; (void) strchomp(tmp, 0); if (gwc_add(tmp)) added++; } fclose(in); /* * Now check whether we added anything from that file, and if we have not * and there are more backup files to open, retry with these fallbacks * instead. */ if (0 == added && UNSIGNED(idx) < len - 1) { g_warning("%s(): nothing loaded from \"%s/%s\", trying fallbacks", G_STRFUNC, fpv[idx].dir, fpv[idx].name); fpv += idx + 1; len -= idx + 1; g_assert(size_is_positive(len)); goto retry; } else { if (GNET_PROPERTY(bootstrap_debug)) { g_debug("%s(): loaded %u URL%s from \"%s/%s\"", G_STRFUNC, added, plural(added), fpv[idx].dir, fpv[idx].name); } } }