Esempio n. 1
0
static gboolean
delete_hash_entry(gpointer key, gpointer val, gpointer unused_data)
{
	(void) unused_data;
	/* free the key str (was strdup'd below) */
	G_FREE_NULL(key);
	G_FREE_NULL(val);
	return TRUE;
}
Esempio n. 2
0
/**
 * helper func for stats_display -
 *  does two things:
 *
 *  - clears out aged / infrequent search terms
 *  - sticks the rest of the search terms in clist_search_stats
 *
 */
static gboolean
stats_hash_to_clist(gpointer key, gpointer value, gpointer unused_udata)
{
	gchar *text[3];
	gchar period_tmp[32];
	gchar total_tmp[32];
	struct term_counts *val = value;

	(void) unused_udata;

	/* update counts */
	if (!val->period_cnt)
		val->periods++;
	else
		val->periods = 0;
	val->total_cnt += val->period_cnt;

	/* try to keep the number of infrequent terms down */
	if (
		(1.0 * val->total_cnt / (val->periods + 2.0)) * 100 <
			GUI_PROPERTY(search_stats_delcoef)
	) {
		G_FREE_NULL(key);
		G_FREE_NULL(val);
		return TRUE;
	}

	stat_count++;

	/* update the display */

    /* FIXME: make %8.8d %d and set up custom sort function */
	gm_snprintf(period_tmp, sizeof period_tmp, "%8.8d", (int) val->period_cnt);
	gm_snprintf(total_tmp, sizeof total_tmp, "%8.8d", (int) val->total_cnt);

	text[0] = key;
	text[1] = period_tmp;
	text[2] = total_tmp;

    {
        GtkWidget *clist_search_stats =
            gui_main_window_lookup("clist_search_stats");

        gtk_clist_insert(GTK_CLIST(clist_search_stats), 0, text);
    }

	/* new period begins */
	val->period_cnt = 0;

	return FALSE;
}
Esempio n. 3
0
void
on_entry_dbg_property_pattern_activate(GtkEditable *unused_editable,
	gpointer unused_udata)
{
	static gchar old_pattern[1024];
   	gchar *text;

	(void) unused_editable;
	(void) unused_udata;

	text = STRTRACK(gtk_editable_get_chars(
        GTK_EDITABLE(gui_dlg_prefs_lookup("entry_dbg_property_pattern")),
        0, -1));
	g_strstrip(text);

	if (0 != strcmp(text, old_pattern)) {
		GSList *props;

		g_strlcpy(old_pattern, text, sizeof old_pattern);
		props = gnet_prop_get_by_regex(text, NULL);
		if (!props)
			statusbar_gui_warning(10,
				_("No property name matches the pattern \"%s\"."), text);
		
		dbg_property_show_list(props);
		dbg_property_update_selection();
		gm_slist_free_null(&props);
	}
	G_FREE_NULL(text);
}
Esempio n. 4
0
/**
 * Get a version token for the short version string, base64-encoded.
 *
 * @returns a pointer to static data.
 */
char *
tok_short_version(void)
{
	static time_t last_generated = 0;
	static char *toklevel = NULL;
	time_t now = tm_time();

	/*
	 * We don't generate a new token each time, but only every TOKEN_LIFE
	 * seconds.  The clock skew threshold must be greater than twice that
	 * amount, of course.
	 */

	g_assert(TOKEN_CLOCK_SKEW > 2 * TOKEN_LIFE);

	if (delta_time(now, last_generated) < TOKEN_LIFE)
		return toklevel;

	last_generated = now;

	G_FREE_NULL(toklevel);
	toklevel = tok_generate(now, version_short_string);

	return NOT_LEAKING(toklevel);
}
Esempio n. 5
0
static void
search_stats_notify_word(query_type_t type, const gchar *search,
	const host_addr_t unused_addr, guint16 unused_port)
{
    word_vec_t *wovec;
    guint wocnt;
    guint i;
    gchar *buf;

	(void) unused_addr;
	(void) unused_port;

    if (QUERY_SHA1 == type)
        return;

	buf = g_strdup(search);
   	wocnt = word_vec_make(buf, &wovec);

	if (wocnt != 0) {
		for (i = 0; i < wocnt; i++)
			search_stats_tally(&wovec[i]);

		word_vec_free(wovec, wocnt);
	}

    G_FREE_NULL(buf);
}
Esempio n. 6
0
static void 
thex_upload_free_data(struct thex_upload *ctx)
{
	G_FREE_NULL(ctx->data);
	ctx->offset = 0;
	ctx->size = 0;
}
Esempio n. 7
0
void
on_entry_config_ipv6_trt_prefix_activate(GtkEditable *unused_editable,
		gpointer unused_udata)
{
	const gchar *endptr;
	host_addr_t addr;
   	gchar *text;

	(void) unused_editable;
	(void) unused_udata;
	text = STRTRACK(gtk_editable_get_chars(
        GTK_EDITABLE(gui_dlg_prefs_lookup("entry_config_ipv6_trt_prefix")),
        0, -1));
	g_strstrip(text);
	if (
		string_to_host_addr(text, &endptr, &addr)
			&& '\0' == endptr[0]
			&& host_addr_is_ipv6(addr)
	) {
		gnet_prop_set_ip_val(PROP_IPV6_TRT_PREFIX, addr);
	} else if (0 == strcmp(text, "") || 0 == strcmp(text, "<none>")) {
		gnet_prop_set_ip_val(PROP_IPV6_TRT_PREFIX, zero_host_addr);
	}
	G_FREE_NULL(text);
}
Esempio n. 8
0
static void
host_lookup_callback(const gchar *hostname, gpointer key)
{
	const struct nid *node_id = key;
	gnet_node_info_t info;
	struct node_data *data;
	host_addr_t addr;
	guint16 port;

	if (!ht_pending_lookups)
		goto finish;

	if (!remove_item(ht_pending_lookups, node_id))
		goto finish;

	data = find_node(node_id);
	if (!data)
		goto finish;

	guc_node_fill_info(node_id, &info);
	g_assert(node_id == info.node_id);
	
	addr = info.addr;
	port = info.port;
	guc_node_clear_info(&info);

	WFREE_NULL(data->host, data->host_size);
	
	if (hostname) {
		const gchar *host;
		gchar *to_free;

		if (utf8_is_valid_string(hostname)) {
			to_free = NULL;
			host = hostname;
		} else {
			to_free = locale_to_utf8_normalized(hostname, UNI_NORM_GUI);
			host = to_free;
		}
		
		data->host_size = w_concat_strings(&data->host,
							host, " (",
							host_addr_port_to_string(addr, port), ")",
							(void *) 0);

		G_FREE_NULL(to_free);
	} else {
		statusbar_gui_warning(10,
			_("Reverse lookup for %s failed"), host_addr_to_string(addr));
		data->host_size = w_concat_strings(&data->host,
							host_addr_port_to_string(addr, port),
							(void *) 0);
	}

finish:
	nid_unref(node_id);
}
Esempio n. 9
0
void
on_entry_config_path_activate(GtkEditable *editable, gpointer unused_udata)
{
    gchar *path = STRTRACK(gtk_editable_get_chars(editable, 0, -1));

	(void) unused_udata;
    gnet_prop_set_string(PROP_SHARED_DIRS_PATHS, path);
    G_FREE_NULL(path);
}
Esempio n. 10
0
/**
 * Remove the timeout from the timeout list and free allocated memory.
 */
static void
statusbar_gui_free_timeout(struct statusbar_timeout *t)
{
	g_return_if_fail(t);

	statusbar_gui_remove(t->id);
	sl_statusbar_timeouts = g_slist_remove(sl_statusbar_timeouts, t);
	G_FREE_NULL(t);
}
Esempio n. 11
0
void
on_entry_config_extensions_activate(GtkEditable *editable, gpointer unused_data)
{
    gchar *ext;

	(void) unused_data;
    ext = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
    gnet_prop_set_string(PROP_SCAN_EXTENSIONS, ext);
    G_FREE_NULL(ext);
}
Esempio n. 12
0
void
on_entry_config_socks_username_activate(GtkEditable *editable,
		gpointer unused_udata)
{
   	gchar *text = g_strstrip(STRTRACK(gtk_editable_get_chars(editable, 0, -1)));

	(void) unused_udata;
    gnet_prop_set_string(PROP_SOCKS_USER, text);
    G_FREE_NULL(text);
}
Esempio n. 13
0
void
on_entry_config_netmask_activate(GtkEditable *editable, gpointer unused_data)
{
    gchar *buf;

	(void) unused_data;
    buf = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
    gnet_prop_set_string(PROP_LOCAL_NETMASKS_STRING, buf);
    G_FREE_NULL(buf);
}
Esempio n. 14
0
static void
add_node(void)
{
    GtkEditable *editable = GTK_EDITABLE(gui_main_window_lookup("entry_host"));
    gchar *addr;

    addr = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
    nodes_gui_common_connect_by_name(addr);
    G_FREE_NULL(addr);
    gtk_entry_set_text(GTK_ENTRY(editable), "");
}
Esempio n. 15
0
void
on_entry_host_changed(GtkEditable *editable, gpointer unused_udata)
{
	gchar *e;

	(void) unused_udata;
	e = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
	g_strstrip(e);
	gtk_widget_set_sensitive(gui_main_window_lookup("button_nodes_add"),
        	e[0] != '\0');
	G_FREE_NULL(e);
}
Esempio n. 16
0
void
on_button_config_move_path_clicked(GtkButton *unused_button, void *unused_udata)
{
	char *directory = gnet_prop_get_string(PROP_MOVE_FILE_PATH, NULL, 0);

	(void) unused_button;
	(void) unused_udata;

	directory_chooser_show(DIR_CHOICE_COMPLETE,
		_("Please choose where to move files after successful download"),
		directory);
	G_FREE_NULL(directory);
}
Esempio n. 17
0
void
on_button_config_save_path_clicked(GtkButton *unused_button, void *unused_udata)
{
	char *directory = gnet_prop_get_string(PROP_SAVE_FILE_PATH, NULL, 0);

	(void) unused_button;
	(void) unused_udata;

	directory_chooser_show(DIR_CHOICE_INCOMPLETE,
		_("Please choose where to store files while downloading"),
		directory);
	G_FREE_NULL(directory);
}
Esempio n. 18
0
void
on_entry_server_hostname_changed(GtkEditable *editable, gpointer unused_udata)
{
    gchar *text = STRTRACK(gtk_editable_get_chars(editable, 0, -1));

	(void) unused_udata;
	
	g_strstrip(text);
	gtk_widget_set_sensitive(
        gui_dlg_prefs_lookup("checkbutton_give_server_hostname"),
        strlen(text) > 3);		/* Minimum: "x.cx" */
	G_FREE_NULL(text);
}
Esempio n. 19
0
void
on_button_config_bad_path_clicked(GtkButton *unused_button, void *unused_udata)
{
	char *directory = gnet_prop_get_string(PROP_BAD_FILE_PATH, NULL, 0);

	(void) unused_button;
	(void) unused_udata;

	directory_chooser_show(DIR_CHOICE_CORRUPT,
		_("Please choose where to move corrupted files"),
		directory);
	G_FREE_NULL(directory);
}
Esempio n. 20
0
/**
 * Create a string representation of the magnet resource.
 *
 * @return A newly allocated string via halloc().
 */
char *
magnet_to_string(const struct magnet_resource *res)
{
	GSList *sl;
	str_t *s;

	g_return_val_if_fail(res, NULL);
	
	s = str_new(0);

	if (res->display_name) {
		magnet_append_item(s, TRUE, "dn", res->display_name);
	}
	if (0 != res->size) {
		char buf[UINT64_DEC_BUFLEN];

		uint64_to_string_buf(res->size, buf, sizeof buf);
		magnet_append_item(s, FALSE, "xl", buf);
	}
	if (res->sha1) {
		magnet_append_item(s, FALSE, "xt",
			bitprint_to_urn_string(res->sha1, res->tth));
	}
	if (res->parq_id) {
		magnet_append_item(s, TRUE, "x.parq-id", res->parq_id);
	}
	if (res->vendor) {
		magnet_append_item(s, TRUE, "x.vndr", res->vendor);
	}
	if (res->guid) {
		magnet_append_item(s, TRUE, "x.guid", res->guid);
	}
	if (res->dht) {
		magnet_append_item(s, TRUE, "x.dht", "1");
	}

	for (sl = res->sources; NULL != sl; sl = g_slist_next(sl)) {
		char *url;

		url = magnet_source_to_string(sl->data);
		magnet_append_item(s, TRUE, "xs", url);
		G_FREE_NULL(url);
	}

	for (sl = res->searches; NULL != sl; sl = g_slist_next(sl)) {
		magnet_append_item(s, TRUE, "kt", sl->data);
	}

	return str_s2c_null(&s);
}
Esempio n. 21
0
void
on_entry_config_proxy_hostname_activate(GtkEditable *editable,
		gpointer unused_udata)
{
   	gchar *text = g_strstrip(STRTRACK(gtk_editable_get_chars(editable, 0, -1)));

	(void) unused_udata;
    gnet_prop_set_string(PROP_PROXY_HOSTNAME, text);
	if (text[0] != '\0') {
		guc_adns_resolve(text,
			on_entry_config_proxy_hostname_activate_helper, NULL);
	}
	G_FREE_NULL(text);
}
Esempio n. 22
0
/**
 * Set the internal name of the column without changing the
 * column header widget. (Copy paste internal column_title_new
 * from gtkclist.c)
 *
 * @warning EVIL HACK
 */
void
gtk_clist_set_column_name(GtkCList *clist, int col, const char *title)
{
    if (col >= 0 && col < clist->columns) {
		if (
			NULL == title ||
			NULL == clist->column[col].title ||
			0 != strcmp(clist->column[col].title, title)
		) {
			G_FREE_NULL(clist->column[col].title);
			clist->column[col].title = NOT_LEAKING(g_strdup(title));
		}
	}
}
Esempio n. 23
0
void
on_entry_server_hostname_activate(GtkEditable *unused_editable,
		gpointer unused_udata)
{
   	gchar *text;

	(void) unused_editable;
	(void) unused_udata;
	text = STRTRACK(gtk_editable_get_chars(
        GTK_EDITABLE(gui_dlg_prefs_lookup("entry_server_hostname")),
        0, -1));
	g_strstrip(text);
	gnet_prop_set_string(PROP_SERVER_HOSTNAME, text);
	G_FREE_NULL(text);
}
Esempio n. 24
0
void
on_directory_chooser_response(GtkDialog *dialog, int response_id,
	void *user_data)
{
	if (GTK_RESPONSE_ACCEPT == response_id) {
		enum dir_choice dir_choice = pointer_to_uint(user_data);
		char *pathname;

		pathname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		directory_chooser_handle_result(dir_choice, pathname);
		G_FREE_NULL(pathname);
	}
	gtk_widget_destroy(GTK_WIDGET(dialog));
	directory_chooser = NULL;
}
Esempio n. 25
0
/**
 * Terminate THEX download.
 */
void
thex_download_free(struct thex_download **ptr)
{
	struct thex_download *ctx = *ptr;

	if (ctx) {
		if (ctx->rx) {
			rx_free(ctx->rx);
			ctx->rx = NULL;
		}
		HFREE_NULL(ctx->data);
		G_FREE_NULL(ctx->leaves);
		atom_sha1_free_null(&ctx->sha1);
		atom_tth_free_null(&ctx->tth);
		WFREE(ctx);
		*ptr = NULL;
	}
}
Esempio n. 26
0
/**
 * Removes all memory used by the header_features_add.
 */
static void
header_features_cleanup(xfeature_t xf)
{
	struct features *features;
	GList *cur;

 	features = features_get(xf);
	g_return_if_fail(features);

   	cur = g_list_first(features->list);
	for (/* NOTHING */; NULL != cur; cur = g_list_next(cur)) {
		struct header_x_feature *header = cur->data;

		G_FREE_NULL(header->name);
		WFREE(header);
	}
	gm_list_free_null(&features->list);
}
Esempio n. 27
0
void
on_entry_config_force_ip_changed(GtkEditable *editable, gpointer unused_udata)
{
    gchar *text = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
	const gchar *endptr;
	gboolean sensitive;

	(void) unused_udata;
	g_strstrip(text);
	sensitive = string_to_host_addr(text, &endptr, NULL) && '\0' == endptr[0];
	gtk_widget_set_sensitive(
        gui_dlg_prefs_lookup("checkbutton_config_force_ip"),
		sensitive);
	gtk_widget_set_sensitive(
        gui_dlg_prefs_lookup("checkbutton_config_bind_ipv4"),
		sensitive);
	G_FREE_NULL(text);
}
Esempio n. 28
0
/**
 * Helper func for stats_display -
 *  does two things:
 *
 *  - clears out aged / infrequent search terms
 *  - sticks the rest of the search terms in treeview_search_stats
 */
static bool
stats_hash_to_treeview(const void *key, void *value, void *unused_udata)
{
    struct term_counts *val = value;
    GtkTreeIter iter;
    char *s;

    (void) unused_udata;

    /* update counts */
    val->periods = val->period_cnt ? 0 : (val->periods + 1);
    val->total_cnt += val->period_cnt;

    /* try to keep the number of infrequent terms down */
    if (
        (1.0 * val->total_cnt / (val->periods + 2.0)) * 100 <
        GUI_PROPERTY(search_stats_delcoef)
    ) {
        free_hash_entry(key, value, NULL);
        return TRUE;
    }

    stat_count++;

    /* update the display */

    s = key ? unknown_to_utf8_normalized(key, UNI_NORM_GUI, NULL) : NULL;

    gtk_list_store_append(store_search_stats, &iter);
    gtk_list_store_set(store_search_stats, &iter,
                       0, s,
                       1, (gulong) val->period_cnt,
                       2, (gulong) val->total_cnt,
                       (-1));

    if (key != s) {
        G_FREE_NULL(s);
    }

    /* new period begins */
    val->period_cnt = 0;

    return FALSE;
}
Esempio n. 29
0
void
on_entry_config_ipv6_trt_prefix_changed(GtkEditable *editable,
	gpointer unused_udata)
{
    gchar *text = STRTRACK(gtk_editable_get_chars(editable, 0, -1));
	const gchar *endptr;
	host_addr_t addr;
	gboolean sensitive;

	(void) unused_udata;
	g_strstrip(text);
	sensitive = string_to_host_addr(text, &endptr, &addr)
			&& '\0' == endptr[0]
			&& host_addr_is_ipv6(addr);
	gtk_widget_set_sensitive(
        gui_dlg_prefs_lookup("checkbutton_config_ipv6_trt_enable"),
		sensitive);
	G_FREE_NULL(text);
}
Esempio n. 30
0
void
on_button_config_remove_dir_clicked(GtkButton *unused_button,
	gpointer unused_udata)
{
	GtkTreeView *tv;
	GtkTreeModel *model;
	GtkTreeIter iter;
	GtkTreeSelection *selection;
	pslist_t *sl, *pl_dirs = NULL;
	char *dirs;

	(void) unused_button;
	(void) unused_udata;

	tv = GTK_TREE_VIEW(gui_dlg_prefs_lookup("treeview_shared_dirs"));
	model = gtk_tree_view_get_model(tv);

	if (!gtk_tree_model_get_iter_first(model, &iter))
		return;

	/* Regenerate the string property holding a list of paths */
	selection = gtk_tree_view_get_selection(tv);

	do {
		char *pathname = NULL;

		/* Skip items selected for removal */
		if (gtk_tree_selection_iter_is_selected(selection, &iter))
			continue;

		gtk_tree_model_get(model, &iter, 0, &pathname, (-1));
		pl_dirs = pslist_prepend(pl_dirs, pathname);
	} while (gtk_tree_model_iter_next(model, &iter));

	dirs = dirlist_to_string(pl_dirs);
	gnet_prop_set_string(PROP_SHARED_DIRS_PATHS, dirs);
	HFREE_NULL(dirs);

	PSLIST_FOREACH(pl_dirs, sl) {
		G_FREE_NULL(sl->data);
	}