Re: URL field / Loading page images / Refreshing DNS cache
Johannes Hofmann <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jul 06, 2016 at 10:28:04AM +0200, Johannes Hofmann wrote: > On Tue, Jul 05, 2016 at 04:53:45PM -0400, John Gaffney wrote: > > First, a huge thanks to all the Dillo team for their efforts: I just > > switched from 3.0.5 to the current snapshot to try out the mbedtls > > changes, and I am wowed not only by this, but by all the improvements > > in rendering, etc. Great work! > > > > A few suggestions, all very minor, that might be added to the back of > > the development queue: > > > > In the current snapshot, the navigation bar has changed, and the URL > > field does not seem to be taking into account font_factor -- with the > > result that the window is smaller than the font height. You can test > > this by setting, e.g., font_factor=2.0 in your dillorc (most > > dramatically for a tiny panel with small icons). The issue seems to > > be with this factor not being taken into account when bh and lh are > > set in make_panel() in ui.cc. > > > > As far as I can see, one can use the context menu to download > > individual images on a page, or use the panel to toggle image > > loading. But if one wants not to download images in general, but to > > download all the images for some one page (e.g., a weather forecast > > page), then one has to toggle downloading of images on and then off > > again. Maybe a command could be added to KeysCommand_t in keys.hh, > > bound by default to something like Ctrl-i in keys.cc, with a > > corresponding call to a_Html_load_images() in handle() in ui.cc? > > > > To make the switch to the current snapshot, I had, sadly, to terminate > > an instance of 3.0.5 that had been running continuously for 90 days > > without any issues. But to get that much up time it was necessary to > > add a little code so that SIGUSR1 would call a_Dns_freeall() and > > a_Dns_init(), otherwise (unless I am missing something) Dillo will > > persist in using the cached lookup indefinitely and not detect when > > the IP address has changed. So maybe some sort of key binding could > > be added that would flush the cache when needed? > > good point. However I'd like to avoid another key-binding and rather > do the right thing automatically. > I could think of a general DNS entry timeout of a couple of seconds. > In many cases DNS responses are cached at OS-level too respecting > lifetime values given by the server. Firefox has an option to configure the DNS cache expiration (network.dnsCacheExpiration). Attached patch implements a similar feature for Dillo. Cheers, Johannes _______________________________________________ Dillo-dev mailing list [email protected] http://lists.dillo.org/cgi-bin/mailman/listinfo/dillo-dev
dns_cache_expiration.diff
(text/plain, 4.2 KB)
diff -r ff7b186fdf93 dillorc
--- a/dillorc Fri Jul 08 01:19:56 2016 +0000
+++ b/dillorc Fri Jul 08 16:11:03 2016 +0200
@@ -228,6 +228,9 @@
# http_user_agent="Wget/1.13.4 (linux-gnu)"
#The default is "Dillo/"+current_version_number
+# Set the time in seconds for which DNS results should be cached.
+#dns_cache_expiration=300
+
#-------------------------------------------------------------------------
# COLORS SECTION
#-------------------------------------------------------------------------
diff -r ff7b186fdf93 src/dns.c
--- a/src/dns.c Fri Jul 08 01:19:56 2016 +0000
+++ b/src/dns.c Fri Jul 08 16:11:03 2016 +0200
@@ -36,10 +36,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include "msg.h"
#include "dns.h"
#include "list.h"
+#include "prefs.h"
#include "IO/iowatch.hh"
@@ -70,6 +72,7 @@
typedef struct {
char *hostname; /* host name for cache */
Dlist *addr_list; /* addresses of host */
+ time_t resolve_time; /* time when we resolved the hostname */
} GDnsCache;
typedef struct {
@@ -166,10 +169,33 @@
a_List_add(dns_cache, dns_cache_size, dns_cache_size_max);
dns_cache[dns_cache_size].hostname = dStrdup(hostname);
dns_cache[dns_cache_size].addr_list = addr_list;
+ dns_cache[dns_cache_size].resolve_time = time(NULL);
++dns_cache_size;
_MSG("Cache objects: %d\n", dns_cache_size);
}
+static const GDnsCache* Dns_cache_find(const char *hostname)
+{
+ const GDnsCache *result = NULL;
+ time_t now = time(NULL);
+ int i;
+
+ for (i = 0; i < dns_cache_size; i++) {
+ if (now - dns_cache[i].resolve_time > prefs.dns_cache_expiration) {
+ MSG("Dns_cache_find: remove timed out entry for %s\n", dns_cache[i].hostname);
+ a_List_remove(dns_cache, i, dns_cache_size);
+ i--;
+ continue;
+ }
+
+ if (!dStrAsciiCasecmp(hostname, dns_cache[i].hostname)) {
+ result = &dns_cache[i];
+ break;
+ }
+ }
+
+ return result;
+}
/*
* Initializer function
@@ -371,18 +397,16 @@
void a_Dns_resolve(const char *hostname, DnsCallback_t cb_func, void *cb_data)
{
int i, channel;
+ const GDnsCache* cached_result;
if (!hostname)
return;
/* check for cache hit. */
- for (i = 0; i < dns_cache_size; i++)
- if (!dStrAsciiCasecmp(hostname, dns_cache[i].hostname))
- break;
-
- if (i < dns_cache_size) {
+ cached_result = Dns_cache_find(hostname);
+ if (cached_result) {
/* already resolved, call the Callback immediately. */
- cb_func(0, dns_cache[i].addr_list, cb_data);
+ cb_func(0, cached_result->addr_list, cb_data);
} else if ((i = Dns_queue_find(hostname)) != -1) {
/* hit in queue, but answer hasn't come back yet. */
diff -r ff7b186fdf93 src/prefs.c
--- a/src/prefs.c Fri Jul 08 01:19:56 2016 +0000
+++ b/src/prefs.c Fri Jul 08 16:11:03 2016 +0200
@@ -68,6 +68,7 @@
prefs.http_referer = dStrdup(PREFS_HTTP_REFERER);
prefs.http_strict_transport_security = TRUE;
prefs.http_user_agent = dStrdup(PREFS_HTTP_USER_AGENT);
+ prefs.dns_cache_expiration = 300;
prefs.limit_text_width = FALSE;
prefs.adjust_min_width = TRUE;
prefs.adjust_table_min_width = TRUE;
diff -r ff7b186fdf93 src/prefs.h
--- a/src/prefs.h Fri Jul 08 01:19:56 2016 +0000
+++ b/src/prefs.h Fri Jul 08 16:11:03 2016 +0200
@@ -40,6 +40,7 @@
int ypos;
char *http_language;
int32_t http_max_conns;
+ int32_t dns_cache_expiration;
DilloUrl *http_proxy;
char *http_proxyuser;
char *http_referer;
diff -r ff7b186fdf93 src/prefsparser.cc
--- a/src/prefsparser.cc Fri Jul 08 01:19:56 2016 +0000
+++ b/src/prefsparser.cc Fri Jul 08 16:11:03 2016 +0200
@@ -174,6 +174,7 @@
{ "http_strict_transport_security",&prefs.http_strict_transport_security,
PREFS_BOOL, 0 },
{ "http_user_agent", &prefs.http_user_agent, PREFS_STRING, 0 },
+ { "dns_cache_expiration", &prefs.dns_cache_expiration, PREFS_INT32, 0 },
{ "limit_text_width", &prefs.limit_text_width, PREFS_BOOL, 0 },
{ "adjust_min_width", &prefs.adjust_min_width, PREFS_BOOL, 0 },
{ "adjust_table_min_width", &prefs.adjust_table_min_width, PREFS_BOOL, 0 },