Example #1
0
/**
 * 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);
}
Example #2
0
/**
 * Same as watcher_register() but a path, i.e. a (dir, base) tuple is
 * given instead of a complete filename.
 */
void
watcher_register_path(const file_path_t *fp, watcher_cb_t cb, void *udata)
{
	char *path;

	path = make_pathname(fp->dir, fp->name);
	watcher_register(path, cb, udata);
	HFREE_NULL(path);
}
Example #3
0
static void
spam_retrieve_from_file(FILE *f, const char *path, const char *filename)
{
	char *pathname;

	g_assert(f);
	g_assert(path);
	g_assert(filename);

	pathname = make_pathname(path, filename);
	watcher_register(pathname, spam_changed, NULL);
	HFREE_NULL(pathname);
	spam_load(f);
}
Example #4
0
/**
 * 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);
}
Example #5
0
/**
 * 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);
}