Пример #1
0
/**
 * Adds the given node to the gui.
 */
void
nodes_gui_add_node(gnet_node_info_t *n)
{
    GtkCList *clist_nodes;
	const gchar *titles[c_gnet_num];
	gchar proto_tmp[32];
    gint row;

    g_assert(n != NULL);

   	str_bprintf(proto_tmp, sizeof proto_tmp, "%d.%d",
		n->proto_major, n->proto_minor);

    titles[c_gnet_host]       = host_addr_port_to_string(n->addr, n->port);
    titles[c_gnet_flags]      = "...";
    titles[c_gnet_user_agent] = n->vendor
									? lazy_utf8_to_locale(n->vendor)
									: "...";
    titles[c_gnet_loc]        = iso3166_country_cc(n->country);
    titles[c_gnet_version]    = proto_tmp;
    titles[c_gnet_connected]  = "...";
    titles[c_gnet_uptime]     = "...";
    titles[c_gnet_info]       = "...";

    clist_nodes = GTK_CLIST(gui_main_window_lookup("clist_nodes"));

    row = gtk_clist_append(clist_nodes, (gchar **) titles); /* override const */
    gtk_clist_set_row_data(clist_nodes, row,
		deconstify_gpointer(nid_ref(n->node_id)));
}
Пример #2
0
static void
print_node_info(struct gnutella_shell *sh, const struct gnutella_node *n)
{
	gnet_node_flags_t flags;
	time_delta_t up, con;
	char buf[1024];
	char vendor_escaped[50];
	char uptime_buf[8];
	char contime_buf[8];

	g_return_if_fail(sh);
	g_return_if_fail(n);
	
	if (!node_fill_flags(NODE_ID(n), &flags))
		return;

	con = n->connect_date ? delta_time(tm_time(), n->connect_date) : 0;
	up = n->up_date ? delta_time(tm_time(), n->up_date) : 0;

	{
		const char *vendor;
		char *escaped;
		
		vendor = node_vendor(n);
		escaped = hex_escape(vendor, TRUE);
		clamp_strcpy(vendor_escaped, sizeof vendor_escaped, escaped);
		if (escaped != vendor) {
			HFREE_NULL(escaped);
		}
	}

	clamp_strcpy(uptime_buf, sizeof uptime_buf,
		up > 0 ? compact_time(up) : "?");
	clamp_strcpy(contime_buf, sizeof contime_buf,
		con > 0 ? compact_time(con) : "?");

	gm_snprintf(buf, sizeof buf,
		"%-21.45s %5.1u %s %2.2s %6.6s %6.6s %.50s",
		node_addr(n),
		(unsigned) n->gnet_port,
		node_flags_to_string(&flags),
		iso3166_country_cc(n->country),
		contime_buf,
		uptime_buf,
		vendor_escaped);

	shell_write(sh, buf);
	shell_write(sh, "\n");	/* Terminate line */
}
Пример #3
0
/**
 * Update the row with the given nodeinfo. If row is -1 the row number
 * is determined by the node_id contained in the gnet_node_info_t.
 */
static void
nodes_gui_update_node_info(gnet_node_info_t *n, gint row)
{
    GtkCList *clist = GTK_CLIST(gui_main_window_lookup("clist_nodes"));

    g_assert(n != NULL);

    if (row == -1) {
        row = gtk_clist_find_row_from_data(clist,
					deconstify_gpointer(n->node_id));
    }

    if (row != -1) {
		gchar ver_buf[64];
        gnet_node_status_t status;
        time_t now = tm_time();

        if (guc_node_get_status(n->node_id, &status)) {
			gtk_clist_set_text(clist, row, c_gnet_user_agent,
					n->vendor ? lazy_utf8_to_locale(n->vendor) : "...");

			gtk_clist_set_text(clist, row, c_gnet_loc,
					deconstify_gchar(iso3166_country_cc(n->country)));

			str_bprintf(ver_buf, sizeof ver_buf, "%d.%d",
					n->proto_major, n->proto_minor);
			gtk_clist_set_text(clist, row, c_gnet_version, ver_buf);

			if (status.status == GTA_NODE_CONNECTED)
				gtk_clist_set_text(clist, row, c_gnet_connected,
						short_uptime(delta_time(now, status.connect_date)));

			if (status.up_date)
				gtk_clist_set_text(clist, row, c_gnet_uptime,
						status.up_date
						? short_uptime(delta_time(now, status.up_date)) : "...");

			gtk_clist_set_text(clist, row, c_gnet_info,
					nodes_gui_common_status_str(&status));
		}
    } else {
        g_warning("%s(): no matching row found", G_STRFUNC);
    }
}
Пример #4
0
static void
print_upload_info(struct gnutella_shell *sh,
	const struct gnet_upload_info *info)
{
	char buf[1024];

	g_return_if_fail(sh);
	g_return_if_fail(info);

	str_bprintf(buf, sizeof buf, "%-3.3s %-16.40s %s %s@%s %s%s%s",
		info->encrypted ? "(E)" : "",
		host_addr_to_string(info->addr),
		iso3166_country_cc(info->country),
		compact_size(info->range_end - info->range_start,
			GNET_PROPERTY(display_metric_units)),
		short_size(info->range_start,
			GNET_PROPERTY(display_metric_units)),
		info->name ? "\"" : "<",
		info->name ? info->name : "none",
		info->name ? "\"" : ">");

	shell_write(sh, buf);
	shell_write(sh, "\n");	/* Terminate line */
}
Пример #5
0
static void
cell_renderer(GtkTreeViewColumn *column, GtkCellRenderer *cell, 
	GtkTreeModel *model, GtkTreeIter *iter, gpointer udata)
{
	const struct result_data *data;
    const struct results_set *rs;
	const gchar *text;
	enum c_sr_columns id;

	if (!gtk_tree_view_column_get_visible(column))
		return;

	text = NULL;	/* default to nothing */
	id = GPOINTER_TO_UINT(udata);
	data = get_result_data(model, iter);
    rs = data->record->results_set;

	switch (id) {
	case c_sr_filename:
		text = data->record->utf8_name;
		break;
	case c_sr_ext:
		text = data->record->ext;
		break;
	case c_sr_mime:
		text = mime_type_to_string(mime_type_from_extension(data->record->ext));
		break;
	case c_sr_vendor:
		if (!(ST_LOCAL & rs->status))
			text = vendor_code_get_name(rs->vendor);
		break;
	case c_sr_info:
		text = data->record->info;
		break;
	case c_sr_size:
		text = compact_size(data->record->size, show_metric_units());
		break;
	case c_sr_count:
		text = data->children ? uint32_to_string(1 + data->children) : NULL;
		break;
	case c_sr_loc:
		if (ISO3166_INVALID != rs->country)
			text = iso3166_country_cc(rs->country);
		break;
	case c_sr_charset:
		if (!(ST_LOCAL & rs->status))
			text = data->record->charset;
		break;
	case c_sr_route:
		text = search_gui_get_route(rs);
		break;
	case c_sr_protocol:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = ST_UDP & rs->status ?
				(ST_SR_UDP & rs->status ? N_("UDP (semi-reliable)") : "UDP")
				: "TCP";
		break;
	case c_sr_hops:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = uint32_to_string(rs->hops);
		break;
	case c_sr_ttl:
		if (!((ST_LOCAL | ST_BROWSE) & rs->status))
			text = uint32_to_string(rs->ttl);
		break;
	case c_sr_spam:
		if (SR_SPAM & data->record->flags) {
			text = "S";	/* Spam */
		} else if (ST_SPAM & rs->status) {
			text = "maybe";	/* maybe spam */
		}
		break;
	case c_sr_owned:
		if (SR_OWNED & data->record->flags) {
			text = _("owned");
		} else if (SR_PARTIAL & data->record->flags) {
			text = _("partial");
		} else if (SR_SHARED & data->record->flags) {
			text = _("shared");
		}
		break;
	case c_sr_hostile:
		if (ST_HOSTILE & rs->status) {
			text = "H";
		}
		break;
	case c_sr_sha1:
		if (data->record->sha1) {
			text = sha1_base32(data->record->sha1);
		}
		break;
	case c_sr_ctime:
		if ((time_t) -1 != data->record->create_time) {
			text = timestamp_to_string(data->record->create_time);
		}
		break;
	case c_sr_num:
		g_assert_not_reached();
		break;
	}
	g_object_set(cell,
		"text", text,
		"foreground-gdk", gui_color_get(data->color),
		"background-gdk", gui_color_get(GUI_COLOR_BACKGROUND),
		(void *) 0);
}
Пример #6
0
/**
 * Parse a list entry.
 * @return TRUE when done with input.
 */
static bool
ctl_parse_list_entry(struct ctl_string *s)
{
	struct ctl_tok *tok = ctl_next_token(s);
	GSList *countries = NULL;
	GSList *sl;
	char *opt = NULL;
	unsigned flags;
	bool done = FALSE;

	switch (tok->type) {
	case CTL_TOK_EOF:		done = TRUE; goto out;
	case CTL_TOK_ID:		countries = ctl_parse_country(s, tok); break;
	case CTL_TOK_LBRACE:	countries = ctl_parse_countries(s); break;
	default:				ctl_error(s, tok, "'{' or country"); goto out;
	}

	if (NULL == countries)
		goto out;

	/*
	 * Check presence of options
	 */

	ctl_token_free_null(&tok);
	tok = ctl_next_token(s);

	switch (tok->type) {
	case CTL_TOK_EOF:
	case CTL_TOK_COMMA:
		ctl_unread(s, &tok);
		break;
	case CTL_TOK_COLON:
		opt = ctl_parse_options(s);
		break;
	default:
		ctl_error(s, tok, "',' or ':' or EOF");
		goto out;
	}

	/*
	 * Compute flags.
	 */

	if (NULL == opt) {
		flags = ctl_get_flags('a');
	} else {
		char *p = opt;
		char c;

		flags = 0;

		while ((c = *p++)) {
			unsigned f = ctl_get_flags(c);
			if (0 == f)
				g_warning("CTL ignoring unknown option '%c'", c);
			flags |= f;
		}
	}

	/*
	 * Handle the country list in countries with options in opt.
	 * Nevermind superseding, the latest parsed is the winner.
	 */

	GM_SLIST_FOREACH(countries, sl) {
		unsigned code = pointer_to_uint(sl->data);

		htable_insert(ctl_by_country,
			uint_to_pointer(code), uint_to_pointer(flags));
		ctl_all_flags |= flags;

		if (GNET_PROPERTY(ctl_debug)) {
			g_debug("CTL %s => '%s' (%s)",
				iso3166_country_cc(code), ctl_flags2str(flags),
				iso3166_country_name(code));
		}
	}
Пример #7
0
const char *
guc_download_get_country(const struct download *d)
{
    return iso3166_country_cc(download_country(d));
}
Пример #8
0
/**
 * Convenience routine to return the contry code of an address.
 */
const char *
gip_country_cc(const host_addr_t ha)
{
	return iso3166_country_cc(gip_country(ha));
}
Пример #9
0
static void
update_tooltip(GtkTreeView *tv, GtkTreePath *path)
{
	const struct node_data *data = NULL;
	GtkTreeModel *model;
	GtkTreeIter iter;

	g_assert(tv != NULL);

	if (path) {
		GtkTreeIter parent;
		
		model = gtk_tree_view_get_model(tv);
		if (!gtk_tree_model_get_iter(model, &iter, path)) {
			g_warning("gtk_tree_model_get_iter() failed");
			return;
		}
		if (gtk_tree_model_iter_parent(model, &parent, &iter))
			iter = parent;

		gtk_tree_model_get(model, &iter, 0, &data, (-1));
	}

	if (data && find_node(data->node_id)) {
		gnet_node_info_t info;
		gnet_node_flags_t flags;
		gchar text[1024];

		guc_node_fill_flags(data->node_id, &flags);
		guc_node_fill_info(data->node_id, &info);
		g_assert(info.node_id == data->node_id);

		str_bprintf(text, sizeof text,
			"%s %s\n"
			"%s %s (%s)\n"
			"%s %s (%s)\n"
			"%s %.64s",
			_("Peer:"),
			host_addr_port_to_string(info.gnet_addr, info.gnet_port),
			_("Peermode:"),
			guc_node_peermode_to_string(flags.peermode),
			flags.incoming ? _("incoming") : _("outgoing"),
			_("Country:"),
			iso3166_country_name(info.country),
			iso3166_country_cc(info.country),
			_("Vendor:"),
			info.vendor ? info.vendor : _("Unknown"));

		guc_node_clear_info(&info);
		gtk_tooltips_set_tip(settings_gui_tooltips(),
			GTK_WIDGET(tv), text, NULL);
	} else {
		GtkWidget *w;

		gtk_tooltips_set_tip(settings_gui_tooltips(), GTK_WIDGET(tv),
			_("Move the cursor over a row to see details."), NULL);
		w = settings_gui_tooltips()->tip_window;
		if (w)
			gtk_widget_hide(w);
	}
}