mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-07 04:53:37 -04:00
Show IP of the document in the status bar.
config options: ui.show_ip (0/1) default 0 status.showip-text - colors
This commit is contained in:
parent
d2513cdfbb
commit
0ec2f8eaa8
@ -18,6 +18,8 @@
|
||||
|
||||
#include "bfu/leds.h"
|
||||
#include "config/options.h"
|
||||
#include "document/document.h"
|
||||
#include "document/view.h"
|
||||
#include "intl/gettext/libintl.h"
|
||||
#include "main/module.h"
|
||||
#include "main/timer.h"
|
||||
@ -63,6 +65,8 @@ enum led_option {
|
||||
LEDS_CLOCK_FORMAT,
|
||||
LEDS_CLOCK_ALIAS,
|
||||
|
||||
LEDS_SHOW_IP_ENABLE,
|
||||
|
||||
LEDS_PANEL_TREE,
|
||||
LEDS_PANEL_ENABLE,
|
||||
|
||||
@ -82,9 +86,14 @@ static struct option_info led_options[] = {
|
||||
N_("Format string for the digital clock. See the strftime(3) "
|
||||
"manpage for details.")),
|
||||
|
||||
|
||||
/* Compatibility alias. Added: 2004-04-22, 0.9.CVS. */
|
||||
INIT_OPT_ALIAS("ui.timer", "clock", 0, "ui.clock"),
|
||||
|
||||
INIT_OPT_BOOL("ui", N_("Show IP"),
|
||||
"show_ip", 0, 0,
|
||||
N_("Whether to display IP of the document in the status bar.")),
|
||||
|
||||
|
||||
INIT_OPT_TREE("ui", N_("LEDs"),
|
||||
"leds", 0,
|
||||
@ -102,6 +111,7 @@ static struct option_info led_options[] = {
|
||||
#define get_leds_clock_enable() get_opt_leds(LEDS_CLOCK_ENABLE).number
|
||||
#define get_leds_clock_format() get_opt_leds(LEDS_CLOCK_FORMAT).string
|
||||
#define get_leds_panel_enable() get_opt_leds(LEDS_PANEL_ENABLE).number
|
||||
#define get_leds_show_ip_enable() get_opt_leds(LEDS_SHOW_IP_ENABLE).number
|
||||
|
||||
void
|
||||
init_leds(struct module *module)
|
||||
@ -167,6 +177,25 @@ draw_timer(struct terminal *term, int xpos, int ypos, struct color_pair *color)
|
||||
return length;
|
||||
}
|
||||
|
||||
static int
|
||||
draw_show_ip(struct session *ses, int xpos, int ypos, struct color_pair *color)
|
||||
{
|
||||
|
||||
if (ses->doc_view && ses->doc_view->document && ses->doc_view->document->ip) {
|
||||
struct terminal *term = ses->tab->term;
|
||||
unsigned char *s = ses->doc_view->document->ip;
|
||||
int length = strlen(s);
|
||||
int i;
|
||||
|
||||
for (i = length - 1; i >= 0; i--)
|
||||
draw_char(term, xpos - (length - i), ypos, s[i], 0, color);
|
||||
|
||||
return length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
static int
|
||||
draw_clock(struct terminal *term, int xpos, int ypos, struct color_pair *color)
|
||||
@ -233,6 +262,12 @@ draw_leds(struct session *ses)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (get_leds_show_ip_enable()) {
|
||||
struct color_pair *color = get_bfu_color(term, "status.showip-text");
|
||||
|
||||
if (color) term->leds_length += draw_show_ip(ses, xpos - term->leds_length, ypos, color);
|
||||
}
|
||||
|
||||
/* We must shift the whole thing by one char to left, because we don't
|
||||
* draft the char in the right-down corner :(. */
|
||||
|
||||
|
@ -1199,10 +1199,15 @@ static struct option_info config_options_info[] = {
|
||||
"status",
|
||||
N_("Status bar colors.")),
|
||||
|
||||
INIT_OPT_COLORS(".status", N_("Status bar show ip"),
|
||||
"showip-text", "black", "white", "black", "white",
|
||||
N_("Status bar show ip text colors.")),
|
||||
|
||||
INIT_OPT_COLORS(".status", N_("Generic status bar"),
|
||||
"status-bar", "black", "white", "black", "white",
|
||||
N_("Generic status bar colors.")),
|
||||
|
||||
|
||||
INIT_OPT_COLORS(".status", N_("Status bar text"),
|
||||
"status-text", "black", "white", "black", "white",
|
||||
N_("Status bar text colors.")),
|
||||
|
@ -10,6 +10,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "cache/cache.h"
|
||||
@ -24,6 +28,7 @@
|
||||
#include "document/refresh.h"
|
||||
#include "main/module.h"
|
||||
#include "main/object.h"
|
||||
#include "network/dns.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "terminal/draw.h"
|
||||
#include "util/color.h"
|
||||
@ -35,6 +40,46 @@
|
||||
|
||||
static INIT_LIST_OF(struct document, format_cache);
|
||||
|
||||
/* DNS callback. */
|
||||
static void
|
||||
found_dns(void *data, struct sockaddr_storage *addr, int addrlen)
|
||||
{
|
||||
#ifdef HAVE_INET_NTOP
|
||||
unsigned char buf[64];
|
||||
const unsigned char *res;
|
||||
struct sockaddr *s;
|
||||
unsigned char **ip = (unsigned char **)data;
|
||||
void *src;
|
||||
|
||||
if (!ip || !addr) return;
|
||||
s = (struct sockaddr *)addr;
|
||||
if (s->sa_family == AF_INET6) {
|
||||
src = &(((struct sockaddr_in6 *)s)->sin6_addr.s6_addr);
|
||||
} else {
|
||||
src = &(((struct sockaddr_in *)s)->sin_addr.s_addr);
|
||||
}
|
||||
res = inet_ntop(s->sa_family, src, buf, 64);
|
||||
if (res) {
|
||||
*ip = stracpy(res);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
get_ip(struct document *document)
|
||||
{
|
||||
#ifdef HAVE_INET_NTOP
|
||||
struct uri *uri = document->uri;
|
||||
char tmp;
|
||||
|
||||
if (!uri || !uri->host || !uri->hostlen) return;
|
||||
tmp = uri->host[uri->hostlen];
|
||||
uri->host[uri->hostlen] = 0;
|
||||
find_host(uri->host, &document->querydns, found_dns, &document->ip, 0);
|
||||
uri->host[uri->hostlen] = tmp;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct document *
|
||||
init_document(struct cache_entry *cached, struct document_options *options)
|
||||
{
|
||||
@ -44,6 +89,8 @@ init_document(struct cache_entry *cached, struct document_options *options)
|
||||
|
||||
document->uri = get_uri_reference(cached->uri);
|
||||
|
||||
get_ip(document);
|
||||
|
||||
object_lock(cached);
|
||||
document->cache_id = cached->cache_id;
|
||||
document->cached = cached;
|
||||
@ -121,6 +168,8 @@ done_document(struct document *document)
|
||||
object_unlock(document->cached);
|
||||
|
||||
if (document->uri) done_uri(document->uri);
|
||||
if (document->querydns) kill_dns_request(&document->querydns);
|
||||
mem_free_if(document->ip);
|
||||
mem_free_if(document->title);
|
||||
if (document->frame_desc) free_frameset_desc(document->frame_desc);
|
||||
if (document->refresh) done_document_refresh(document->refresh);
|
||||
|
@ -208,6 +208,9 @@ struct document {
|
||||
|
||||
struct uri *uri;
|
||||
|
||||
/* for obtaining IP */
|
||||
void *querydns;
|
||||
unsigned char *ip;
|
||||
/** The title of the document. The charset of this string is
|
||||
* document.options.cp. */
|
||||
unsigned char *title;
|
||||
|
Loading…
Reference in New Issue
Block a user