Exemplo n.º 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);
}
Exemplo n.º 2
0
/**
 * 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);
        }
    }
}