Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/5ebec852825072e50fb21363f23cf2fcd106425d
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/5ebec852825072e50fb21363f23cf2fcd106425d
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/5ebec852825072e50fb21363f23cf2fcd106425d

The branch, master has been updated
       via  5ebec852825072e50fb21363f23cf2fcd106425d (commit)
       via  0da0dcc342f3c3078b73449c2ead95fee39ec4b8 (commit)
       via  b78887c7c8324178f1dd22faf7a3b818b6682a5d (commit)
       via  670110b171fd7e405447ee1d4df101e4e4e86e60 (commit)
       via  4076cc64d2cee02219b4dfccc46cedb249bf47fa (commit)
      from  ac446f9affb955dffbf3997b86b7c43f5204db11 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=5ebec852825072e50fb21363f23cf2fcd106425d
commit 5ebec852825072e50fb21363f23cf2fcd106425d
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    actually check the generated database files against reference test data

diff --git a/content/urldb.c b/content/urldb.c
index 77351ae..b190da5 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -4301,7 +4301,6 @@ void urldb_save_cookies(const char *filename)
        if (!fp)
                return;
 
-       fprintf(fp, "# >%s\n", filename);
        fprintf(fp, "# NetSurf cookies file.\n"
                "#\n"
                "# Lines starting with a '#' are comments, "
diff --git a/test/data/cookies b/test/data/cookies
index 739618e..fc7a588 100644
--- a/test/data/cookies
+++ b/test/data/cookies
@@ -1,4 +1,3 @@
-# >/home/vince/.config/netsurf/Cookies
 # NetSurf cookies file.
 #
 # Lines starting with a '#' are comments, blank lines are ignored.
diff --git a/test/data/cookies-out b/test/data/cookies-out
new file mode 100644
index 0000000..143925a
--- /dev/null
+++ b/test/data/cookies-out
@@ -0,0 +1,31 @@
+# NetSurf cookies file.
+#
+# Lines starting with a '#' are comments, blank lines are ignored.
+#
+# All lines prior to "Version: 102" are discarded.
+#
+# Version      Domain  Domain from Set-Cookie  Path    Path from Set-Cookie    
Secure  HTTP-Only       Expires Last used       No destroy      Name    Value   
Value was quoted        Scheme  URL     Comment
+Version:       102
+0      www.ccrexplorers.com    0       /       1       0       0       
1499619054      1468082755      0       bb_lastvisit    1468083054      0       
http    http://www.ccrexplorers.com/forumdisplay.php?f=17       
+0      .google.com     1       /       1       0       0       1497632093      
1470493285      0       SID     
DQAAAMoAAACuniK1mc17JMX-o-sfAVqvl0EWP0kiNpQg4lWeslWBnU_km8BK6Eww-1mC6zvnm7Jiv2vft4BOwWiAOmRzN66pbzxGNxKKGzSz2GNdWrcwvuYyQHkevwrtwmKmZGDKsgLljofq6NyNf0AP5xGXfHj18awhbbnymmv5UaDqypGx7FvptGQSMQkj_1hY6NJ5pfmO6LX8ezViJMABtqGPoO8Y8r8-eFRzLlsfbhCqM2OHkDRfoofXJCtIvDMi7Xyzoh6D5PsXbrfFZhcLSlfZpBtP
        0       unused  unused  
+0      .google.com     1       /       1       0       1       1497632093      
1470493285      0       HSID    A1rFmKHX-G1exnHNv       0       unused  unused  
+0      .google.com     1       /       1       1       1       1497632093      
1470493285      0       SSID    A4wVZcYgXrCrwWns8       0       unused  unused  
+0      .google.com     1       /       1       0       0       1497632093      
1470493285      0       APISID  IeJTJt20VmceF7bS/AACvc5cSFPpX8FJMj      0       
unused  unused  
+0      .google.com     1       /       1       1       0       1497632093      
1470493285      0       SAPISID baCIIjpj-o3XQCkH/A-WEZgPvnNnguijDQ      0       
unused  unused  
+0      mail.google.com 0       /       1       1       1       1497632093      
1435272960      0       OSID    
DQAAANsAAABjm3QWm7iyror5Q-r_twvLnU2MeBpDTpzoY-d-4pEomtilsx1VjIp_SphmVJcv084Ilg4o1COlySeuNAVSkeYn6qPyK93aIKN7MOmQxKvYQXIAlPiBAXD7bVX2HoAQpDXKc1BQZUfL2wLIjCwns0NQVGawofTWf8gve_FAwp6hXF9hXHrZRTU9lgt3N0yBpjElda_UiyNkhUIZP27zSS1LpXh7GaYcUgM69IUrczTnfkfIX_XunEaXBT59fmc49pbFEYlMMURG3ydiPjIhGdN9eHO27V9JhxqhuYUryTM8kg
  0       https   
https://mail.google.com/accounts/SetOSID?continue=https%3A%2F%2Faccounts.google.co.uk%2Faccounts%2FSetSID%3Fssdc%3D1%26sidt%3DALWU2ctR9Uxp0qhL0HVYNURm01UOebegtyVV3GH%252BiVgIY9WIfqGs5NmqjVyX2IzkD0jDdGMV%252BgDLYwi9XrR%252FWsOIdwC4OO803V%252FimpsuKeLB7lk3%252FV10vr4C6wTc20A0I3ep6BLOe%252FQZgYJjfrcjzRiV2zT6fOiYXka1QrtyPIugR3R%252FaSWI%252Fau79w9hvBc%252FqqATVRi7F%252FDHv%252Be3cHMLPNOYoKwwUSOA9ORjKsyc5bCpnWM6X%252BrjsfzEEqlV5iui3EPKbBvTvCnfdF7UJjMg4EfWyMhVZaeytZdvGqJ2DfvPNmm2toULDQd4rcAAkfRZJQ95ySI4fq1ifZkfA0dhr7xnBQ0cl3%252BYTdl0yp%252BXjztO8YivQb%252Feip7gihmjfE9yRXoEboirDW8lIscN6cDDsuxzD07npdjHjRUX2wYrG4V3MLI4luH
 
O52mwY%252BHZMN3O681HumCIBYvX%26continue%3Dhttps%253A%252F%252Fmail.google.com%252Fmail%252F%253Fauth%253DDQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk&osidt=ALWU2cvhIheonCPoG5pecDWKf0i1a-AsQKBMvxay9B54taUbBKAxr9vzwWXg2UJDvM3oYcjYFVDxpERiv9sed5ZQXUKh9UPV5epNA25PUuVZwNDOkePm6agrIhUGR9wVz4x7I6-uU0uF4VHDwS1KDpWZvQY6tMw5vti1qF2bVdLMO_UTLcEW9mdV7Oze8OZXWxFsppfVGSxHN8N1rH8xRMCj3A5QjC-OU5h-pS3N4-AI4A5LwrMj_zvtwS0BW5otNhVmt503yBBXKIIkF5i4gGXiQGVVhCFlBeosv7KbWx97PEPTzeqf59R0ZgY9p1cd_jQWi0gYUmTn
       
+0      mail.google.com 0       /mail   1       1       1       1497632094      
1435272960      0       GX      
DQAAAMoAAADuReoJNLFTfcVkka4MpznqQGgtWpCWbF9qPINtXVzsE62rPcFtkl_t5MhqS9Ab1zrEmWlZefvaR2bknrPqFsBfVZAtMoThXQxvoQQ7K2A1XTWfEeX09w0dJvN0A8SXsjAEebTY93dZkJr5fMomABLkbizqoRqSkv6sh4x7Ysat6VGX6m6eTg81aiCjuBHzLwlAKx63On5joEI1qYhXvKF1JMc3oEzaETTv9mw-vXHt_J-YYlPQi_nG4jQKoDFJ-XCx1fjVVGlqBsPj5Pf1-SGT
        0       https   
https://mail.google.com/mail/?auth=DQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk
  
+0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       GAPS    
1:-F43DfTc9MQPBnPFtQw7SBXNDYxGRw:-byarQeQN13vrH8I       0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
+0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       LSID    
mail|o.mail.google.com|s.GB|ss:DQAAAMwAAADuReoJNLFTfcVkka4Mpznq77VRSAgK_50UNJQeyKZS6zdAktvmMi42CsHIKCA_qkMe373-3PwvTioyn8OGHoKi8a2tas-mS1US4KPOXsp6GrewaR6bwkvkAudNj5H97wu9p9uek5EMljgPSIcFHyTRDwGghHc918-Z5-QVQMYswD9fA8DObnL4iFPrYJyYsz2MJcYKOMTdgBc9cutZ-zgRVJLVV1IJiluuTeQb5pjfpX4ROfo8kf4M_boTxfuwO19fn_zp5jT9qdPr4jDBM9lM
 0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
+0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       ACCOUNT_CHOOSER 
AFx_qI5IqJoq6XeRvabQu34G7bErRw0LzimzBZXUqP_9H8Zh2kqTpBc-jooLHKNNCggYdxTq_ENRPogKK0V35Ap5s9N-88xwKmZLX7xXnZ25EBl-8FHjjvfMxKIj2-_xnpyKtWa5fWac
    0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
+0      .giffgaff.com   1       /       1       0       0       1503402870      
1440407964      0       visid_incap_456843      
MSQtdY7lSvK9UJiZDP3daK0S2lUAAAAAQUIPAAAAAAAudOMnRSt1V9mQN5dPPA+R        0       
unused  unused  
+0      .reddit.com     1       /       1       0       1       1499814590      
1468278656      0       __cfduid        
d2c9a13e6ed171f4318aabcf558fcc6661468278590     0       unused  unused  
+0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loid    lLGqu0nblR8T852T20      0       https   
https://www.reddit.com/ 
+0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loidcreated     2016-07-11T23%3A09%3A50.925Z    0       
https   https://www.reddit.com/ 
+0      .google.co.uk   1       /       1       0       0       1497632093      
1468278489      0       SID     
DQAAAMkAAACuniK1mc17JMX-o-sfAVqvl0EWP0kiNpQg4lWeslWBnU_km8BK6Eww-1mC6zvnm7Jiv2vft4BOwWiAOmRzN66pbzxGNxKKGzSz2GNdWrcwvuYyQHkevwrtwmKmZGDKsgLljofq6NyNf0AP5xGXfHj18awhbbnymmv5UaDqypGx7FvptGQSMQkj_1hY6NJ5pflIfSnKeEn0Y2mEVyhc1qUiGcJhVKqIRd6xaGKk7l235kOpqxjGK7I4_jTQaORZbp2-RWozAg7SHESSaOpxQ0ZT
        0       unused  unused  
+0      .google.co.uk   1       /       1       0       1       1497632093      
1468278489      0       HSID    ANVWylWAbjjzFxKxI       0       unused  unused  
+0      .google.co.uk   1       /       1       1       1       1497632093      
1468278489      0       SSID    ANtGv1CSBG3CWbdtr       0       unused  unused  
+0      .google.co.uk   1       /       1       0       0       1497632093      
1468278489      0       APISID  IeJTJt20VmceF7bS/AACvc5cSFPpX8FJMj      0       
unused  unused  
+0      .google.co.uk   1       /       1       1       0       1497632093      
1468278489      0       SAPISID baCIIjpj-o3XQCkH/A-WEZgPvnNnguijDQ      0       
unused  unused  
+0      nir.theregister.co.uk   0       /       1       0       0       
1499814443      0       0       sa      1       0       http    
http://nir.theregister.co.uk/?g=c&g=sa&s=c/front.front  
+0      .bbc.co.uk      1       /       1       0       0       1595541997      
1470493359      0       BBC-UID 
35e7d9a5837b2e9d026d30f521339ac6826814226444c1ee4a2134fef248fe180NetSurf/3.6%20(Linux)
  0       unused  unused  
+0      news.bbc.co.uk  0       /       1       0       0       1500933997      
1469574171      0       BBC-UID 
25a73995333b5e9d8ea88a16a17c7b8beea45e555eb863e913853a4de2dcbdb80NetSurf%2f3%2e6%20%28Linux%29
  0       http    http://news.bbc.co.uk/  
diff --git a/test/data/urldb-out b/test/data/urldb-out
new file mode 100644
index 0000000..6fd2024
--- /dev/null
+++ b/test/data/urldb-out
@@ -0,0 +1,47 @@
+106
+en.wikipedia.org
+2
+http
+
+/wiki/Main_Page
+1
+2100000000
+0
+
+
+https
+
+/wiki/Main_Page
+1
+2100000000
+1
+
+Wikipedia, the free encyclopedia
+slashdot.org
+2
+http
+
+/
+2
+2100000000
+0
+
+
+https
+
+/
+3
+2100000000
+1
+
+Slashdot: News for nerds, stuff that matters
+www.bbc.co.uk
+1
+http
+
+/news/science_and_environment
+1
+2100000000
+1
+
+Science & Environment - BBC News
diff --git a/test/urldbtest.c b/test/urldbtest.c
index 89cf276..6b3f2ac 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -43,13 +43,67 @@
 #include "desktop/gui_internal.h"
 #include "desktop/cookie_manager.h"
 
+/**
+ * url database used as input to test sets
+ */
 const char *test_urldb_path = "test/data/urldb";
+/**
+ * url database used as output reference
+ */
+const char *test_urldb_out_path = "test/data/urldb-out";
+
+/**
+ * cookie database used as input
+ */
 const char *test_cookies_path = "test/data/cookies";
+/**
+ * cookie database used as output reference
+ */
+const char *test_cookies_out_path = "test/data/cookies-out";
 
 const char *wikipedia_url = "http://www.wikipedia.org/";;
 
 struct netsurf_table *guit = NULL;
 
+/**
+ * compare two files contents
+ */
+static int cmp(const char *f1, const char *f2)
+{
+       int res = 0;
+       FILE *fp1;
+       FILE *fp2;
+       int ch1;
+       int ch2;
+
+       fp1 = fopen(f1, "r");
+       if (fp1 == NULL) {
+               return -1;
+       }
+       fp2 = fopen(f2, "r");
+       if (fp2 == NULL) {
+               fclose(fp1);
+               return -1;
+       }
+
+       while (res == 0) {
+               ch1 = fgetc(fp1);
+               ch2 = fgetc(fp2);
+
+               if (ch1 != ch2) {
+                       res = 1;
+               }
+
+               if (ch1 == EOF) {
+                       break;
+               }
+       }
+
+       fclose(fp1);
+       fclose(fp2);
+       return res;
+}
+
 /*************** original test helpers ************/
 
 bool cookie_manager_add(const struct cookie_data *data)
@@ -398,6 +452,9 @@ START_TEST(urldb_session_test)
        res = urldb_save(outnam);
        ck_assert_int_eq(res, NSERROR_OK);
 
+       /* check for the correct answer */
+       ck_assert_int_eq(cmp(outnam, test_urldb_out_path), 0);
+
        /* remove test output */
        unlink(outnam);
 
@@ -405,6 +462,9 @@ START_TEST(urldb_session_test)
        outnam = tmpnam(NULL);
        urldb_save_cookies(outnam);
 
+       /* check for the correct answer */
+       ck_assert_int_eq(cmp(outnam, test_cookies_out_path), 0);
+
        /* remove test output */
        unlink(outnam);
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=0da0dcc342f3c3078b73449c2ead95fee39ec4b8
commit 0da0dcc342f3c3078b73449c2ead95fee39ec4b8
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    remove urldb_add_host and path from public API
    
    The urldb_add_host and urldb_add_path API were only public for the
    urldb test code which was calling them incorrectly in any case as the
    url bloom filters were not updated so serialising and adding data to
    entries was inconsistent.
    
    This also changes the tests to use the urldb_add_url API which is less
    buggy and results in a smaller, cleaner urldb API.

diff --git a/content/urldb.c b/content/urldb.c
index af76183..77351ae 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -2039,6 +2039,180 @@ urldb_parse_cookie(nsurl *url, const char **cookie)
 
 
 /**
+ * Add a path to the database, creating any intermediate entries
+ *
+ * \param scheme URL scheme associated with path
+ * \param port Port number on host associated with path
+ * \param host Host tree node to attach to
+ * \param path_query Absolute path plus query to add (freed)
+ * \param fragment URL fragment, or NULL
+ * \param url URL (fragment ignored)
+ * \return Pointer to leaf node, or NULL on memory exhaustion
+ */
+static struct path_data *
+urldb_add_path(lwc_string *scheme,
+              unsigned int port,
+              const struct host_part *host,
+              char *path_query,
+              lwc_string *fragment,
+              nsurl *url)
+{
+       struct path_data *d, *e;
+       char *buf = path_query;
+       char *segment, *slash;
+       bool match;
+
+       assert(scheme && host && url);
+
+       d = (struct path_data *) &host->paths;
+
+       /* skip leading '/' */
+       segment = buf;
+       if (*segment == '/')
+               segment++;
+
+       /* Process path segments */
+       do {
+               slash = strchr(segment, '/');
+               if (!slash) {
+                       /* last segment */
+                       /* look for existing entry */
+                       for (e = d->children; e; e = e->next)
+                               if (strcmp(segment, e->segment) == 0 &&
+                                   lwc_string_isequal(scheme,
+                                                      e->scheme, &match) ==
+                                   lwc_error_ok &&
+                                   match == true &&
+                                   e->port == port)
+                                       break;
+
+                       d = e ? urldb_add_path_fragment(e, fragment) :
+                               urldb_add_path_node(scheme, port,
+                                                   segment, fragment, d);
+                       break;
+               }
+
+               *slash = '\0';
+
+               /* look for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcmp(segment, e->segment) == 0 &&
+                           lwc_string_isequal(scheme, e->scheme,
+                                              &match) == lwc_error_ok &&
+                           match == true &&
+                           e->port == port)
+                               break;
+
+               d = e ? e : urldb_add_path_node(scheme, port, segment, NULL, d);
+               if (!d)
+                       break;
+
+               segment = slash + 1;
+       } while (1);
+
+       free(path_query);
+
+       if (d && !d->url) {
+               /* Insert defragmented URL */
+               if (nsurl_defragment(url, &d->url) != NSERROR_OK)
+                       return NULL;
+       }
+
+       return d;
+}
+
+
+/**
+ * Add a host to the database, creating any intermediate entries
+ *
+ * \param host Hostname to add
+ * \return Pointer to leaf node, or NULL on memory exhaustion
+ */
+static struct host_part *urldb_add_host(const char *host)
+{
+       struct host_part *d = (struct host_part *) &db_root, *e;
+       struct search_node *s;
+       char buf[256]; /* 256 bytes is sufficient - domain names are
+                       * limited to 255 chars. */
+       char *part;
+
+       assert(host);
+
+       if (urldb__host_is_ip_address(host)) {
+               /* Host is an IP, so simply add as TLD */
+
+               /* Check for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcasecmp(host, e->part) == 0)
+                               /* found => return it */
+                               return e;
+
+               d = urldb_add_host_node(host, d);
+
+               s = urldb_search_insert(search_trees[ST_IP], d);
+               if (!s) {
+                       /* failed */
+                       d = NULL;
+               } else {
+                       search_trees[ST_IP] = s;
+               }
+
+               return d;
+       }
+
+       /* Copy host string, so we can corrupt it */
+       strncpy(buf, host, sizeof buf);
+       buf[sizeof buf - 1] = '\0';
+
+       /* Process FQDN segments backwards */
+       do {
+               part = strrchr(buf, '.');
+               if (!part) {
+                       /* last segment */
+                       /* Check for existing entry */
+                       for (e = d->children; e; e = e->next)
+                               if (strcasecmp(buf, e->part) == 0)
+                                       break;
+
+                       if (e) {
+                               d = e;
+                       } else {
+                               d = urldb_add_host_node(buf, d);
+                       }
+
+                       /* And insert into search tree */
+                       if (d) {
+                               struct search_node **r;
+
+                               r = urldb_get_search_tree_direct(buf);
+                               s = urldb_search_insert(*r, d);
+                               if (!s) {
+                                       /* failed */
+                                       d = NULL;
+                               } else {
+                                       *r = s;
+                               }
+                       }
+                       break;
+               }
+
+               /* Check for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcasecmp(part + 1, e->part) == 0)
+                               break;
+
+               d = e ? e : urldb_add_host_node(part + 1, d);
+               if (!d)
+                       break;
+
+               *part = '\0';
+       } while (1);
+
+       return d;
+}
+
+
+/**
  * Insert a cookie into the database
  *
  * \param c The cookie to insert
@@ -4161,160 +4335,5 @@ void urldb_dump(void)
 }
 
 
-/* exported interface documented in content/urldb.h */
-struct host_part *urldb_add_host(const char *host)
-{
-       struct host_part *d = (struct host_part *) &db_root, *e;
-       struct search_node *s;
-       char buf[256]; /* 256 bytes is sufficient - domain names are
-                       * limited to 255 chars. */
-       char *part;
-
-       assert(host);
-
-       if (urldb__host_is_ip_address(host)) {
-               /* Host is an IP, so simply add as TLD */
-
-               /* Check for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcasecmp(host, e->part) == 0)
-                               /* found => return it */
-                               return e;
-
-               d = urldb_add_host_node(host, d);
-
-               s = urldb_search_insert(search_trees[ST_IP], d);
-               if (!s) {
-                       /* failed */
-                       d = NULL;
-               } else {
-                       search_trees[ST_IP] = s;
-               }
-
-               return d;
-       }
-
-       /* Copy host string, so we can corrupt it */
-       strncpy(buf, host, sizeof buf);
-       buf[sizeof buf - 1] = '\0';
-
-       /* Process FQDN segments backwards */
-       do {
-               part = strrchr(buf, '.');
-               if (!part) {
-                       /* last segment */
-                       /* Check for existing entry */
-                       for (e = d->children; e; e = e->next)
-                               if (strcasecmp(buf, e->part) == 0)
-                                       break;
-
-                       if (e) {
-                               d = e;
-                       } else {
-                               d = urldb_add_host_node(buf, d);
-                       }
-
-                       /* And insert into search tree */
-                       if (d) {
-                               struct search_node **r;
-
-                               r = urldb_get_search_tree_direct(buf);
-                               s = urldb_search_insert(*r, d);
-                               if (!s) {
-                                       /* failed */
-                                       d = NULL;
-                               } else {
-                                       *r = s;
-                               }
-                       }
-                       break;
-               }
-
-               /* Check for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcasecmp(part + 1, e->part) == 0)
-                               break;
-
-               d = e ? e : urldb_add_host_node(part + 1, d);
-               if (!d)
-                       break;
-
-               *part = '\0';
-       } while (1);
-
-       return d;
-}
-
-
-/* exported interface documented in content/urldb.h */
-struct path_data *
-urldb_add_path(lwc_string *scheme,
-              unsigned int port,
-              const struct host_part *host,
-              char *path_query,
-              lwc_string *fragment,
-              nsurl *url)
-{
-       struct path_data *d, *e;
-       char *buf = path_query;
-       char *segment, *slash;
-       bool match;
-
-       assert(scheme && host && url);
-
-       d = (struct path_data *) &host->paths;
 
-       /* skip leading '/' */
-       segment = buf;
-       if (*segment == '/')
-               segment++;
 
-       /* Process path segments */
-       do {
-               slash = strchr(segment, '/');
-               if (!slash) {
-                       /* last segment */
-                       /* look for existing entry */
-                       for (e = d->children; e; e = e->next)
-                               if (strcmp(segment, e->segment) == 0 &&
-                                   lwc_string_isequal(scheme,
-                                                      e->scheme, &match) ==
-                                   lwc_error_ok &&
-                                   match == true &&
-                                   e->port == port)
-                                       break;
-
-                       d = e ? urldb_add_path_fragment(e, fragment) :
-                               urldb_add_path_node(scheme, port,
-                                                   segment, fragment, d);
-                       break;
-               }
-
-               *slash = '\0';
-
-               /* look for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcmp(segment, e->segment) == 0 &&
-                           lwc_string_isequal(scheme, e->scheme,
-                                              &match) == lwc_error_ok &&
-                           match == true &&
-                           e->port == port)
-                               break;
-
-               d = e ? e : urldb_add_path_node(scheme, port, segment, NULL, d);
-               if (!d)
-                       break;
-
-               segment = slash + 1;
-       } while (1);
-
-       free(path_query);
-
-       if (d && !d->url) {
-               /* Insert defragmented URL */
-               if (nsurl_defragment(url, &d->url) != NSERROR_OK)
-                       return NULL;
-       }
-
-       return d;
-}
diff --git a/content/urldb.h b/content/urldb.h
index daa54d6..7230d0b 100644
--- a/content/urldb.h
+++ b/content/urldb.h
@@ -138,29 +138,4 @@ bool urldb_set_cookie(const char *header, struct nsurl 
*url, struct nsurl *refer
 char *urldb_get_cookie(struct nsurl *url, bool include_http_only);
 
 
-/**
- * Add a host to the database, creating any intermediate entries
- *
- * \param host Hostname to add
- * \return Pointer to leaf node, or NULL on memory exhaustion
- */
-struct host_part *urldb_add_host(const char *host);
-
-
-/**
- * Add a path to the database, creating any intermediate entries
- *
- * \param scheme URL scheme associated with path
- * \param port Port number on host associated with path
- * \param host Host tree node to attach to
- * \param path_query Absolute path plus query to add (freed)
- * \param fragment URL fragment, or NULL
- * \param url URL (fragment ignored)
- * \return Pointer to leaf node, or NULL on memory exhaustion
- */
-struct path_data *urldb_add_path(lwc_string *scheme, unsigned int port,
-               const struct host_part *host, char *path_query,
-               lwc_string *fragment, struct nsurl *url);
-
-
 #endif
diff --git a/test/urldbtest.c b/test/urldbtest.c
index bd9fa93..89cf276 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -71,27 +71,6 @@ static nsurl *make_url(const char *url)
        return nsurl;
 }
 
-static char *make_path_query(nsurl *url)
-{
-       size_t len;
-       char *path_query;
-       if (nsurl_get(url, NSURL_PATH | NSURL_QUERY, &path_query, &len) !=
-                       NSERROR_OK) {
-               LOG("failed creating path_query");
-               exit(1);
-       }
-       return path_query;
-}
-
-static lwc_string *make_lwc(const char *str)
-{
-       lwc_string *lwc;
-       if (lwc_intern_string(str, strlen(str), &lwc) != lwc_error_ok) {
-               LOG("failed creating lwc_string");
-               exit(1);
-       }
-       return lwc;
-}
 
 static bool test_urldb_set_cookie(const char *header, const char *url,
                const char *referer)
@@ -208,58 +187,37 @@ START_TEST(urldb_original_test)
        nsurl *urlr;
        char *path_query;
 
-       h = urldb_add_host("127.0.0.1");
-       ck_assert_msg(h != NULL, "failed adding host");
-
-       h = urldb_add_host("intranet");
-       ck_assert_msg(h != NULL, "failed adding host");
-
+       /* ensure title can be set */
        url = make_url("http://intranet/";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url);
-       ck_assert_msg(p != NULL, "failed adding path");
-
-       lwc_string_unref(scheme);
-
+       urldb_add_url(url);
        urldb_set_url_title(url, "foo");
 
        u = urldb_get_url_data(url);
-       assert(u && strcmp(u->title, "foo") == 0);
+       ck_assert(u && strcmp(u->title, "foo") == 0);
        nsurl_unref(url);
 
-       /* Get host entry */
-       h = urldb_add_host("netsurf.strcprstskrzkrk.co.uk");
-       ck_assert_msg(h != NULL, "failed adding host");
-
-       /* Get path entry */
+       /* fragments */
        url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       path_query = make_path_query(url);
-       fragment = make_lwc("zz");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
-
-       lwc_string_unref(fragment);
-
-       fragment = make_lwc("aa");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       lwc_string_unref(fragment);
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#zz?a=b";);
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       fragment = make_lwc("yy");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#aa?a=b";);
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       free(path_query);
-       lwc_string_unref(fragment);
-       lwc_string_unref(scheme);
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#yy?a=b";);
+       ck_assert(urldb_add_url(url) == true);
        nsurl_unref(url);
 
        url = make_url("file:///home/");
-       urldb_add_url(url);
+       ck_assert(urldb_add_url(url) == true);
        nsurl_unref(url);
 
+       /* set cookies on urls */
        url = 
make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2";);
        urldb_set_cookie("mmblah=foo; path=/; expires=Thur, 31-Dec-2099 
00:00:00 GMT\r\n", url, NULL);
        nsurl_unref(url);
@@ -416,6 +374,11 @@ static TCase *urldb_original_case_create(void)
        return tc;
 }
 
+/**
+ * Session basic test case
+ *
+ * The databases are loaded and saved with no manipulation
+ */
 START_TEST(urldb_session_test)
 {
        nserror res;
@@ -439,8 +402,12 @@ START_TEST(urldb_session_test)
        unlink(outnam);
 
        /* write cookies out */
+       outnam = tmpnam(NULL);
        urldb_save_cookies(outnam);
 
+       /* remove test output */
+       unlink(outnam);
+
        /* finalise options */
        res = nsoption_finalise(NULL, NULL);
        ck_assert_int_eq(res, NSERROR_OK);
@@ -448,6 +415,11 @@ START_TEST(urldb_session_test)
 }
 END_TEST
 
+/**
+ * Session more extensive test case
+ *
+ * The databases are loaded and saved with a host and paths added
+ */
 START_TEST(urldb_session_add_test)
 {
        nserror res;
@@ -467,15 +439,12 @@ START_TEST(urldb_session_add_test)
        urldb_load_cookies(test_cookies_path);
 
        /* add something to db */
-       h = urldb_add_host("tree.example.com");
-       ck_assert_msg(h != NULL, "failed adding host");
-
        url = make_url("http://tree.example.com/";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       urldb_add_url(url);
+
+       res = urldb_update_url_visit_data(url);
+       ck_assert_int_eq(res, NSERROR_OK);
 
-       lwc_string_unref(scheme);
        nsurl_unref(url);
 
        /* write database out */
@@ -487,8 +456,12 @@ START_TEST(urldb_session_add_test)
        unlink(outnam);
 
        /* write cookies out */
+       outnam = tmpnam(NULL);
        urldb_save_cookies(outnam);
 
+       /* remove test output */
+       unlink(outnam);
+
        /* finalise options */
        res = nsoption_finalise(NULL, NULL);
        ck_assert_int_eq(res, NSERROR_OK);
@@ -496,7 +469,12 @@ START_TEST(urldb_session_add_test)
 }
 END_TEST
 
-
+/**
+ * Test case to check entire session
+ *
+ * These tests define a session as loading a url database and cookie
+ * database and then saving them back to disc.
+ */
 static TCase *urldb_session_case_create(void)
 {
        TCase *tc;
@@ -818,19 +796,18 @@ static TCase *urldb_cookie_case_create(void)
 }
 
 
-
-
 /**
- * Test urldb_add_host asserting on NULL.
+ * Test urldb_add_url asserting on NULL.
  */
-START_TEST(urldb_api_add_host_assert_test)
+START_TEST(urldb_api_add_url_assert_test)
 {
-       struct host_part *res;
-       res = urldb_add_host(NULL);
-       ck_assert(res == NULL);
+       bool res;
+       res = urldb_add_url(NULL);
+       ck_assert(res == true);
 }
 END_TEST
 
+
 /**
  * test url database finalisation without initialisation.
  */
@@ -850,12 +827,11 @@ static TCase *urldb_api_case_create(void)
        tc = tcase_create("API_checks");
 
        tcase_add_test_raise_signal(tc,
-                                   urldb_api_add_host_assert_test,
+                                   urldb_api_add_url_assert_test,
                                    6);
 
        tcase_add_test(tc, urldb_api_destroy_no_init_test);
 
-
        return tc;
 }
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=b78887c7c8324178f1dd22faf7a3b818b6682a5d
commit b78887c7c8324178f1dd22faf7a3b818b6682a5d
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    make update data api return an result

diff --git a/content/urldb.c b/content/urldb.c
index b578f2c..af76183 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -3033,18 +3033,21 @@ void urldb_set_url_content_type(nsurl *url, 
content_type type)
 
 
 /* exported interface documented in content/urldb.h */
-void urldb_update_url_visit_data(nsurl *url)
+nserror urldb_update_url_visit_data(nsurl *url)
 {
        struct path_data *p;
 
        assert(url);
 
        p = urldb_find_url(url);
-       if (!p)
-               return;
+       if (!p) {
+               return NSERROR_NOT_FOUND;
+       }
 
        p->urld.last_visit = time(NULL);
        p->urld.visits++;
+
+       return NSERROR_OK;
 }
 
 
diff --git a/content/urldb.h b/content/urldb.h
index 9ff3a8d..daa54d6 100644
--- a/content/urldb.h
+++ b/content/urldb.h
@@ -75,8 +75,9 @@ void urldb_set_url_content_type(struct nsurl *url, 
content_type type);
  * Update an URL's visit data
  *
  * \param url The URL to update
+ * \return NSERROR_OK on success or NSERROR_NOT_FOUND if url not in database
  */
-void urldb_update_url_visit_data(struct nsurl *url);
+nserror urldb_update_url_visit_data(struct nsurl *url);
 
 
 /**


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=670110b171fd7e405447ee1d4df101e4e4e86e60
commit 670110b171fd7e405447ee1d4df101e4e4e86e60
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    use robust handling of time_t value (de)serialisation
    
    The previous implementation was wrong on systems where time_t was not
    an int type. This changes urldb to use the portable implementation
    netsurf has available.

diff --git a/content/urldb.c b/content/urldb.c
index 7a17450..b578f2c 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -312,6 +312,27 @@ static struct bloom_filter *url_bloom;
 
 
 /**
+ * write a time_t to a file portably
+ *
+ * \param fp File to write to
+ * \param val the unix time value to output
+ * \return NSERROR_OK on success
+ */
+static nserror urldb_write_timet(FILE *fp, time_t val)
+{
+       int use;
+       char op[32];
+
+       use = nsc_sntimet(op, 32, &val);
+       if (use == 0) {
+               fprintf(fp, "%i\n", (int)val);
+       } else {
+               fprintf(fp, "%.*s\n", use, op);
+       }
+       return NSERROR_OK;
+}
+
+/**
  * Write paths associated with a host
  *
  * \param parent Root of (sub)tree to write
@@ -383,9 +404,14 @@ urldb_write_paths(const struct path_data *parent,
 
                                /** \todo handle fragments? */
 
-                               fprintf(fp, "%i\n%i\n%i\n", p->urld.visits,
-                                       (int)p->urld.last_visit,
-                                       (int)p->urld.type);
+                               /* number of visits */
+                               fprintf(fp, "%i\n", p->urld.visits);
+
+                               /* time entry was last used */
+                               urldb_write_timet(fp, p->urld.last_visit);
+
+                               /* entry type */
+                               fprintf(fp, "%i\n", (int)p->urld.type);
 
                                fprintf(fp, "\n");
 
@@ -2806,10 +2832,13 @@ nserror urldb_load(const char *filename)
                        if (p)
                                p->urld.visits = (unsigned int)atoi(s);
 
-                       if (!fgets(s, MAXIMUM_URL_LENGTH, fp))
+                       /* entry last use time */
+                       if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
                                break;
-                       if (p)
-                               p->urld.last_visit = (time_t)atoi(s);
+                       }
+                       if (p) {
+                               nsc_snptimet(s, strlen(s) - 1, 
&p->urld.last_visit);
+                       }
 
                        if (!fgets(s, MAXIMUM_URL_LENGTH, fp))
                                break;


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=4076cc64d2cee02219b4dfccc46cedb249bf47fa
commit 4076cc64d2cee02219b4dfccc46cedb249bf47fa
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    Change url entry expiry timestamps in test database to far future

diff --git a/test/data/urldb b/test/data/urldb
index 62e0da8..07bf1f5 100644
--- a/test/data/urldb
+++ b/test/data/urldb
@@ -5,7 +5,7 @@ http
 
 /wiki/Main_Page
 1
-1470493303
+2100000000
 0
 
 
@@ -13,7 +13,7 @@ https
 
 /wiki/Main_Page
 1
-1470493304
+2100000000
 1
 
 Wikipedia, the free encyclopedia
@@ -43,7 +43,7 @@ http
 
 /
 2
-1469961837
+2100000000
 0
 
 
@@ -51,7 +51,7 @@ https
 
 /
 3
-1470350373
+2100000000
 1
 
 Slashdot: News for nerds, stuff that matters
@@ -61,7 +61,7 @@ http
 
 /news/science_and_environment
 1
-1470493359
+2100000000
 1
 
 Science & Environment - BBC News


-----------------------------------------------------------------------

Summary of changes:
 content/urldb.c                    |  380 ++++++++++++++++++++----------------
 content/urldb.h                    |   28 +--
 test/data/cookies                  |    1 -
 test/data/{cookies => cookies-out} |   23 +--
 test/data/urldb                    |   10 +-
 test/data/urldb-out                |   47 +++++
 test/urldbtest.c                   |  186 +++++++++++-------
 7 files changed, 388 insertions(+), 287 deletions(-)
 copy test/data/{cookies => cookies-out} (88%)
 create mode 100644 test/data/urldb-out

diff --git a/content/urldb.c b/content/urldb.c
index 7a17450..b190da5 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -312,6 +312,27 @@ static struct bloom_filter *url_bloom;
 
 
 /**
+ * write a time_t to a file portably
+ *
+ * \param fp File to write to
+ * \param val the unix time value to output
+ * \return NSERROR_OK on success
+ */
+static nserror urldb_write_timet(FILE *fp, time_t val)
+{
+       int use;
+       char op[32];
+
+       use = nsc_sntimet(op, 32, &val);
+       if (use == 0) {
+               fprintf(fp, "%i\n", (int)val);
+       } else {
+               fprintf(fp, "%.*s\n", use, op);
+       }
+       return NSERROR_OK;
+}
+
+/**
  * Write paths associated with a host
  *
  * \param parent Root of (sub)tree to write
@@ -383,9 +404,14 @@ urldb_write_paths(const struct path_data *parent,
 
                                /** \todo handle fragments? */
 
-                               fprintf(fp, "%i\n%i\n%i\n", p->urld.visits,
-                                       (int)p->urld.last_visit,
-                                       (int)p->urld.type);
+                               /* number of visits */
+                               fprintf(fp, "%i\n", p->urld.visits);
+
+                               /* time entry was last used */
+                               urldb_write_timet(fp, p->urld.last_visit);
+
+                               /* entry type */
+                               fprintf(fp, "%i\n", (int)p->urld.type);
 
                                fprintf(fp, "\n");
 
@@ -2013,6 +2039,180 @@ urldb_parse_cookie(nsurl *url, const char **cookie)
 
 
 /**
+ * Add a path to the database, creating any intermediate entries
+ *
+ * \param scheme URL scheme associated with path
+ * \param port Port number on host associated with path
+ * \param host Host tree node to attach to
+ * \param path_query Absolute path plus query to add (freed)
+ * \param fragment URL fragment, or NULL
+ * \param url URL (fragment ignored)
+ * \return Pointer to leaf node, or NULL on memory exhaustion
+ */
+static struct path_data *
+urldb_add_path(lwc_string *scheme,
+              unsigned int port,
+              const struct host_part *host,
+              char *path_query,
+              lwc_string *fragment,
+              nsurl *url)
+{
+       struct path_data *d, *e;
+       char *buf = path_query;
+       char *segment, *slash;
+       bool match;
+
+       assert(scheme && host && url);
+
+       d = (struct path_data *) &host->paths;
+
+       /* skip leading '/' */
+       segment = buf;
+       if (*segment == '/')
+               segment++;
+
+       /* Process path segments */
+       do {
+               slash = strchr(segment, '/');
+               if (!slash) {
+                       /* last segment */
+                       /* look for existing entry */
+                       for (e = d->children; e; e = e->next)
+                               if (strcmp(segment, e->segment) == 0 &&
+                                   lwc_string_isequal(scheme,
+                                                      e->scheme, &match) ==
+                                   lwc_error_ok &&
+                                   match == true &&
+                                   e->port == port)
+                                       break;
+
+                       d = e ? urldb_add_path_fragment(e, fragment) :
+                               urldb_add_path_node(scheme, port,
+                                                   segment, fragment, d);
+                       break;
+               }
+
+               *slash = '\0';
+
+               /* look for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcmp(segment, e->segment) == 0 &&
+                           lwc_string_isequal(scheme, e->scheme,
+                                              &match) == lwc_error_ok &&
+                           match == true &&
+                           e->port == port)
+                               break;
+
+               d = e ? e : urldb_add_path_node(scheme, port, segment, NULL, d);
+               if (!d)
+                       break;
+
+               segment = slash + 1;
+       } while (1);
+
+       free(path_query);
+
+       if (d && !d->url) {
+               /* Insert defragmented URL */
+               if (nsurl_defragment(url, &d->url) != NSERROR_OK)
+                       return NULL;
+       }
+
+       return d;
+}
+
+
+/**
+ * Add a host to the database, creating any intermediate entries
+ *
+ * \param host Hostname to add
+ * \return Pointer to leaf node, or NULL on memory exhaustion
+ */
+static struct host_part *urldb_add_host(const char *host)
+{
+       struct host_part *d = (struct host_part *) &db_root, *e;
+       struct search_node *s;
+       char buf[256]; /* 256 bytes is sufficient - domain names are
+                       * limited to 255 chars. */
+       char *part;
+
+       assert(host);
+
+       if (urldb__host_is_ip_address(host)) {
+               /* Host is an IP, so simply add as TLD */
+
+               /* Check for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcasecmp(host, e->part) == 0)
+                               /* found => return it */
+                               return e;
+
+               d = urldb_add_host_node(host, d);
+
+               s = urldb_search_insert(search_trees[ST_IP], d);
+               if (!s) {
+                       /* failed */
+                       d = NULL;
+               } else {
+                       search_trees[ST_IP] = s;
+               }
+
+               return d;
+       }
+
+       /* Copy host string, so we can corrupt it */
+       strncpy(buf, host, sizeof buf);
+       buf[sizeof buf - 1] = '\0';
+
+       /* Process FQDN segments backwards */
+       do {
+               part = strrchr(buf, '.');
+               if (!part) {
+                       /* last segment */
+                       /* Check for existing entry */
+                       for (e = d->children; e; e = e->next)
+                               if (strcasecmp(buf, e->part) == 0)
+                                       break;
+
+                       if (e) {
+                               d = e;
+                       } else {
+                               d = urldb_add_host_node(buf, d);
+                       }
+
+                       /* And insert into search tree */
+                       if (d) {
+                               struct search_node **r;
+
+                               r = urldb_get_search_tree_direct(buf);
+                               s = urldb_search_insert(*r, d);
+                               if (!s) {
+                                       /* failed */
+                                       d = NULL;
+                               } else {
+                                       *r = s;
+                               }
+                       }
+                       break;
+               }
+
+               /* Check for existing entry */
+               for (e = d->children; e; e = e->next)
+                       if (strcasecmp(part + 1, e->part) == 0)
+                               break;
+
+               d = e ? e : urldb_add_host_node(part + 1, d);
+               if (!d)
+                       break;
+
+               *part = '\0';
+       } while (1);
+
+       return d;
+}
+
+
+/**
  * Insert a cookie into the database
  *
  * \param c The cookie to insert
@@ -2806,10 +3006,13 @@ nserror urldb_load(const char *filename)
                        if (p)
                                p->urld.visits = (unsigned int)atoi(s);
 
-                       if (!fgets(s, MAXIMUM_URL_LENGTH, fp))
+                       /* entry last use time */
+                       if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
                                break;
-                       if (p)
-                               p->urld.last_visit = (time_t)atoi(s);
+                       }
+                       if (p) {
+                               nsc_snptimet(s, strlen(s) - 1, 
&p->urld.last_visit);
+                       }
 
                        if (!fgets(s, MAXIMUM_URL_LENGTH, fp))
                                break;
@@ -3004,18 +3207,21 @@ void urldb_set_url_content_type(nsurl *url, 
content_type type)
 
 
 /* exported interface documented in content/urldb.h */
-void urldb_update_url_visit_data(nsurl *url)
+nserror urldb_update_url_visit_data(nsurl *url)
 {
        struct path_data *p;
 
        assert(url);
 
        p = urldb_find_url(url);
-       if (!p)
-               return;
+       if (!p) {
+               return NSERROR_NOT_FOUND;
+       }
 
        p->urld.last_visit = time(NULL);
        p->urld.visits++;
+
+       return NSERROR_OK;
 }
 
 
@@ -4095,7 +4301,6 @@ void urldb_save_cookies(const char *filename)
        if (!fp)
                return;
 
-       fprintf(fp, "# >%s\n", filename);
        fprintf(fp, "# NetSurf cookies file.\n"
                "#\n"
                "# Lines starting with a '#' are comments, "
@@ -4129,160 +4334,5 @@ void urldb_dump(void)
 }
 
 
-/* exported interface documented in content/urldb.h */
-struct host_part *urldb_add_host(const char *host)
-{
-       struct host_part *d = (struct host_part *) &db_root, *e;
-       struct search_node *s;
-       char buf[256]; /* 256 bytes is sufficient - domain names are
-                       * limited to 255 chars. */
-       char *part;
-
-       assert(host);
-
-       if (urldb__host_is_ip_address(host)) {
-               /* Host is an IP, so simply add as TLD */
 
-               /* Check for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcasecmp(host, e->part) == 0)
-                               /* found => return it */
-                               return e;
-
-               d = urldb_add_host_node(host, d);
-
-               s = urldb_search_insert(search_trees[ST_IP], d);
-               if (!s) {
-                       /* failed */
-                       d = NULL;
-               } else {
-                       search_trees[ST_IP] = s;
-               }
 
-               return d;
-       }
-
-       /* Copy host string, so we can corrupt it */
-       strncpy(buf, host, sizeof buf);
-       buf[sizeof buf - 1] = '\0';
-
-       /* Process FQDN segments backwards */
-       do {
-               part = strrchr(buf, '.');
-               if (!part) {
-                       /* last segment */
-                       /* Check for existing entry */
-                       for (e = d->children; e; e = e->next)
-                               if (strcasecmp(buf, e->part) == 0)
-                                       break;
-
-                       if (e) {
-                               d = e;
-                       } else {
-                               d = urldb_add_host_node(buf, d);
-                       }
-
-                       /* And insert into search tree */
-                       if (d) {
-                               struct search_node **r;
-
-                               r = urldb_get_search_tree_direct(buf);
-                               s = urldb_search_insert(*r, d);
-                               if (!s) {
-                                       /* failed */
-                                       d = NULL;
-                               } else {
-                                       *r = s;
-                               }
-                       }
-                       break;
-               }
-
-               /* Check for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcasecmp(part + 1, e->part) == 0)
-                               break;
-
-               d = e ? e : urldb_add_host_node(part + 1, d);
-               if (!d)
-                       break;
-
-               *part = '\0';
-       } while (1);
-
-       return d;
-}
-
-
-/* exported interface documented in content/urldb.h */
-struct path_data *
-urldb_add_path(lwc_string *scheme,
-              unsigned int port,
-              const struct host_part *host,
-              char *path_query,
-              lwc_string *fragment,
-              nsurl *url)
-{
-       struct path_data *d, *e;
-       char *buf = path_query;
-       char *segment, *slash;
-       bool match;
-
-       assert(scheme && host && url);
-
-       d = (struct path_data *) &host->paths;
-
-       /* skip leading '/' */
-       segment = buf;
-       if (*segment == '/')
-               segment++;
-
-       /* Process path segments */
-       do {
-               slash = strchr(segment, '/');
-               if (!slash) {
-                       /* last segment */
-                       /* look for existing entry */
-                       for (e = d->children; e; e = e->next)
-                               if (strcmp(segment, e->segment) == 0 &&
-                                   lwc_string_isequal(scheme,
-                                                      e->scheme, &match) ==
-                                   lwc_error_ok &&
-                                   match == true &&
-                                   e->port == port)
-                                       break;
-
-                       d = e ? urldb_add_path_fragment(e, fragment) :
-                               urldb_add_path_node(scheme, port,
-                                                   segment, fragment, d);
-                       break;
-               }
-
-               *slash = '\0';
-
-               /* look for existing entry */
-               for (e = d->children; e; e = e->next)
-                       if (strcmp(segment, e->segment) == 0 &&
-                           lwc_string_isequal(scheme, e->scheme,
-                                              &match) == lwc_error_ok &&
-                           match == true &&
-                           e->port == port)
-                               break;
-
-               d = e ? e : urldb_add_path_node(scheme, port, segment, NULL, d);
-               if (!d)
-                       break;
-
-               segment = slash + 1;
-       } while (1);
-
-       free(path_query);
-
-       if (d && !d->url) {
-               /* Insert defragmented URL */
-               if (nsurl_defragment(url, &d->url) != NSERROR_OK)
-                       return NULL;
-       }
-
-       return d;
-}
diff --git a/content/urldb.h b/content/urldb.h
index 9ff3a8d..7230d0b 100644
--- a/content/urldb.h
+++ b/content/urldb.h
@@ -75,8 +75,9 @@ void urldb_set_url_content_type(struct nsurl *url, 
content_type type);
  * Update an URL's visit data
  *
  * \param url The URL to update
+ * \return NSERROR_OK on success or NSERROR_NOT_FOUND if url not in database
  */
-void urldb_update_url_visit_data(struct nsurl *url);
+nserror urldb_update_url_visit_data(struct nsurl *url);
 
 
 /**
@@ -137,29 +138,4 @@ bool urldb_set_cookie(const char *header, struct nsurl 
*url, struct nsurl *refer
 char *urldb_get_cookie(struct nsurl *url, bool include_http_only);
 
 
-/**
- * Add a host to the database, creating any intermediate entries
- *
- * \param host Hostname to add
- * \return Pointer to leaf node, or NULL on memory exhaustion
- */
-struct host_part *urldb_add_host(const char *host);
-
-
-/**
- * Add a path to the database, creating any intermediate entries
- *
- * \param scheme URL scheme associated with path
- * \param port Port number on host associated with path
- * \param host Host tree node to attach to
- * \param path_query Absolute path plus query to add (freed)
- * \param fragment URL fragment, or NULL
- * \param url URL (fragment ignored)
- * \return Pointer to leaf node, or NULL on memory exhaustion
- */
-struct path_data *urldb_add_path(lwc_string *scheme, unsigned int port,
-               const struct host_part *host, char *path_query,
-               lwc_string *fragment, struct nsurl *url);
-
-
 #endif
diff --git a/test/data/cookies b/test/data/cookies
index 739618e..fc7a588 100644
--- a/test/data/cookies
+++ b/test/data/cookies
@@ -1,4 +1,3 @@
-# >/home/vince/.config/netsurf/Cookies
 # NetSurf cookies file.
 #
 # Lines starting with a '#' are comments, blank lines are ignored.
diff --git a/test/data/cookies b/test/data/cookies-out
similarity index 88%
copy from test/data/cookies
copy to test/data/cookies-out
index 739618e..143925a 100644
--- a/test/data/cookies
+++ b/test/data/cookies-out
@@ -1,4 +1,3 @@
-# >/home/vince/.config/netsurf/Cookies
 # NetSurf cookies file.
 #
 # Lines starting with a '#' are comments, blank lines are ignored.
@@ -7,32 +6,26 @@
 #
 # Version      Domain  Domain from Set-Cookie  Path    Path from Set-Cookie    
Secure  HTTP-Only       Expires Last used       No destroy      Name    Value   
Value was quoted        Scheme  URL     Comment
 Version:       102
-0      .theguardian.com        1       /       1       0       0       
1476054669      1468278669      0       GU_mvt_id       439080  0       unused  
unused  
-0      .reddit.com     1       /       1       0       1       1499814590      
1468278656      0       __cfduid        
d2c9a13e6ed171f4318aabcf558fcc6661468278590     0       unused  unused  
-0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loid    lLGqu0nblR8T852T20      0       https   
https://www.reddit.com/ 
-0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loidcreated     2016-07-11T23%3A09%3A50.925Z    0       
https   https://www.reddit.com/ 
-0      .giffgaff.com   1       /       1       0       0       1503402870      
1440407964      0       visid_incap_456843      
MSQtdY7lSvK9UJiZDP3daK0S2lUAAAAAQUIPAAAAAAAudOMnRSt1V9mQN5dPPA+R        0       
unused  unused  
+0      www.ccrexplorers.com    0       /       1       0       0       
1499619054      1468082755      0       bb_lastvisit    1468083054      0       
http    http://www.ccrexplorers.com/forumdisplay.php?f=17       
 0      .google.com     1       /       1       0       0       1497632093      
1470493285      0       SID     
DQAAAMoAAACuniK1mc17JMX-o-sfAVqvl0EWP0kiNpQg4lWeslWBnU_km8BK6Eww-1mC6zvnm7Jiv2vft4BOwWiAOmRzN66pbzxGNxKKGzSz2GNdWrcwvuYyQHkevwrtwmKmZGDKsgLljofq6NyNf0AP5xGXfHj18awhbbnymmv5UaDqypGx7FvptGQSMQkj_1hY6NJ5pfmO6LX8ezViJMABtqGPoO8Y8r8-eFRzLlsfbhCqM2OHkDRfoofXJCtIvDMi7Xyzoh6D5PsXbrfFZhcLSlfZpBtP
        0       unused  unused  
 0      .google.com     1       /       1       0       1       1497632093      
1470493285      0       HSID    A1rFmKHX-G1exnHNv       0       unused  unused  
 0      .google.com     1       /       1       1       1       1497632093      
1470493285      0       SSID    A4wVZcYgXrCrwWns8       0       unused  unused  
 0      .google.com     1       /       1       0       0       1497632093      
1470493285      0       APISID  IeJTJt20VmceF7bS/AACvc5cSFPpX8FJMj      0       
unused  unused  
 0      .google.com     1       /       1       1       0       1497632093      
1470493285      0       SAPISID baCIIjpj-o3XQCkH/A-WEZgPvnNnguijDQ      0       
unused  unused  
+0      mail.google.com 0       /       1       1       1       1497632093      
1435272960      0       OSID    
DQAAANsAAABjm3QWm7iyror5Q-r_twvLnU2MeBpDTpzoY-d-4pEomtilsx1VjIp_SphmVJcv084Ilg4o1COlySeuNAVSkeYn6qPyK93aIKN7MOmQxKvYQXIAlPiBAXD7bVX2HoAQpDXKc1BQZUfL2wLIjCwns0NQVGawofTWf8gve_FAwp6hXF9hXHrZRTU9lgt3N0yBpjElda_UiyNkhUIZP27zSS1LpXh7GaYcUgM69IUrczTnfkfIX_XunEaXBT59fmc49pbFEYlMMURG3ydiPjIhGdN9eHO27V9JhxqhuYUryTM8kg
  0       https   
https://mail.google.com/accounts/SetOSID?continue=https%3A%2F%2Faccounts.google.co.uk%2Faccounts%2FSetSID%3Fssdc%3D1%26sidt%3DALWU2ctR9Uxp0qhL0HVYNURm01UOebegtyVV3GH%252BiVgIY9WIfqGs5NmqjVyX2IzkD0jDdGMV%252BgDLYwi9XrR%252FWsOIdwC4OO803V%252FimpsuKeLB7lk3%252FV10vr4C6wTc20A0I3ep6BLOe%252FQZgYJjfrcjzRiV2zT6fOiYXka1QrtyPIugR3R%252FaSWI%252Fau79w9hvBc%252FqqATVRi7F%252FDHv%252Be3cHMLPNOYoKwwUSOA9ORjKsyc5bCpnWM6X%252BrjsfzEEqlV5iui3EPKbBvTvCnfdF7UJjMg4EfWyMhVZaeytZdvGqJ2DfvPNmm2toULDQd4rcAAkfRZJQ95ySI4fq1ifZkfA0dhr7xnBQ0cl3%252BYTdl0yp%252BXjztO8YivQb%252Feip7gihmjfE9yRXoEboirDW8lIscN6cDDsuxzD07npdjHjRUX2wYrG4V3MLI4luH
 
O52mwY%252BHZMN3O681HumCIBYvX%26continue%3Dhttps%253A%252F%252Fmail.google.com%252Fmail%252F%253Fauth%253DDQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk&osidt=ALWU2cvhIheonCPoG5pecDWKf0i1a-AsQKBMvxay9B54taUbBKAxr9vzwWXg2UJDvM3oYcjYFVDxpERiv9sed5ZQXUKh9UPV5epNA25PUuVZwNDOkePm6agrIhUGR9wVz4x7I6-uU0uF4VHDwS1KDpWZvQY6tMw5vti1qF2bVdLMO_UTLcEW9mdV7Oze8OZXWxFsppfVGSxHN8N1rH8xRMCj3A5QjC-OU5h-pS3N4-AI4A5LwrMj_zvtwS0BW5otNhVmt503yBBXKIIkF5i4gGXiQGVVhCFlBeosv7KbWx97PEPTzeqf59R0ZgY9p1cd_jQWi0gYUmTn
       
+0      mail.google.com 0       /mail   1       1       1       1497632094      
1435272960      0       GX      
DQAAAMoAAADuReoJNLFTfcVkka4MpznqQGgtWpCWbF9qPINtXVzsE62rPcFtkl_t5MhqS9Ab1zrEmWlZefvaR2bknrPqFsBfVZAtMoThXQxvoQQ7K2A1XTWfEeX09w0dJvN0A8SXsjAEebTY93dZkJr5fMomABLkbizqoRqSkv6sh4x7Ysat6VGX6m6eTg81aiCjuBHzLwlAKx63On5joEI1qYhXvKF1JMc3oEzaETTv9mw-vXHt_J-YYlPQi_nG4jQKoDFJ-XCx1fjVVGlqBsPj5Pf1-SGT
        0       https   
https://mail.google.com/mail/?auth=DQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk
  
 0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       GAPS    
1:-F43DfTc9MQPBnPFtQw7SBXNDYxGRw:-byarQeQN13vrH8I       0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
 0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       LSID    
mail|o.mail.google.com|s.GB|ss:DQAAAMwAAADuReoJNLFTfcVkka4Mpznq77VRSAgK_50UNJQeyKZS6zdAktvmMi42CsHIKCA_qkMe373-3PwvTioyn8OGHoKi8a2tas-mS1US4KPOXsp6GrewaR6bwkvkAudNj5H97wu9p9uek5EMljgPSIcFHyTRDwGghHc918-Z5-QVQMYswD9fA8DObnL4iFPrYJyYsz2MJcYKOMTdgBc9cutZ-zgRVJLVV1IJiluuTeQb5pjfpX4ROfo8kf4M_boTxfuwO19fn_zp5jT9qdPr4jDBM9lM
 0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
 0      accounts.google.com     0       /       1       1       1       
1497632093      0       0       ACCOUNT_CHOOSER 
AFx_qI5IqJoq6XeRvabQu34G7bErRw0LzimzBZXUqP_9H8Zh2kqTpBc-jooLHKNNCggYdxTq_ENRPogKK0V35Ap5s9N-88xwKmZLX7xXnZ25EBl-8FHjjvfMxKIj2-_xnpyKtWa5fWac
    0       https   
https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1
   
-0      mail.google.com 0       /       1       1       1       1497632093      
1435272960      0       OSID    
DQAAANsAAABjm3QWm7iyror5Q-r_twvLnU2MeBpDTpzoY-d-4pEomtilsx1VjIp_SphmVJcv084Ilg4o1COlySeuNAVSkeYn6qPyK93aIKN7MOmQxKvYQXIAlPiBAXD7bVX2HoAQpDXKc1BQZUfL2wLIjCwns0NQVGawofTWf8gve_FAwp6hXF9hXHrZRTU9lgt3N0yBpjElda_UiyNkhUIZP27zSS1LpXh7GaYcUgM69IUrczTnfkfIX_XunEaXBT59fmc49pbFEYlMMURG3ydiPjIhGdN9eHO27V9JhxqhuYUryTM8kg
  0       https   
https://mail.google.com/accounts/SetOSID?continue=https%3A%2F%2Faccounts.google.co.uk%2Faccounts%2FSetSID%3Fssdc%3D1%26sidt%3DALWU2ctR9Uxp0qhL0HVYNURm01UOebegtyVV3GH%252BiVgIY9WIfqGs5NmqjVyX2IzkD0jDdGMV%252BgDLYwi9XrR%252FWsOIdwC4OO803V%252FimpsuKeLB7lk3%252FV10vr4C6wTc20A0I3ep6BLOe%252FQZgYJjfrcjzRiV2zT6fOiYXka1QrtyPIugR3R%252FaSWI%252Fau79w9hvBc%252FqqATVRi7F%252FDHv%252Be3cHMLPNOYoKwwUSOA9ORjKsyc5bCpnWM6X%252BrjsfzEEqlV5iui3EPKbBvTvCnfdF7UJjMg4EfWyMhVZaeytZdvGqJ2DfvPNmm2toULDQd4rcAAkfRZJQ95ySI4fq1ifZkfA0dhr7xnBQ0cl3%252BYTdl0yp%252BXjztO8YivQb%252Feip7gihmjfE9yRXoEboirDW8lIscN6cDDsuxzD07npdjHjRUX2wYrG4V3MLI4luH
 
O52mwY%252BHZMN3O681HumCIBYvX%26continue%3Dhttps%253A%252F%252Fmail.google.com%252Fmail%252F%253Fauth%253DDQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk&osidt=ALWU2cvhIheonCPoG5pecDWKf0i1a-AsQKBMvxay9B54taUbBKAxr9vzwWXg2UJDvM3oYcjYFVDxpERiv9sed5ZQXUKh9UPV5epNA25PUuVZwNDOkePm6agrIhUGR9wVz4x7I6-uU0uF4VHDwS1KDpWZvQY6tMw5vti1qF2bVdLMO_UTLcEW9mdV7Oze8OZXWxFsppfVGSxHN8N1rH8xRMCj3A5QjC-OU5h-pS3N4-AI4A5LwrMj_zvtwS0BW5otNhVmt503yBBXKIIkF5i4gGXiQGVVhCFlBeosv7KbWx97PEPTzeqf59R0ZgY9p1cd_jQWi0gYUmTn
       
-0      mail.google.com 0       /mail   1       1       1       1497632094      
1435272960      0       GX      
DQAAAMoAAADuReoJNLFTfcVkka4MpznqQGgtWpCWbF9qPINtXVzsE62rPcFtkl_t5MhqS9Ab1zrEmWlZefvaR2bknrPqFsBfVZAtMoThXQxvoQQ7K2A1XTWfEeX09w0dJvN0A8SXsjAEebTY93dZkJr5fMomABLkbizqoRqSkv6sh4x7Ysat6VGX6m6eTg81aiCjuBHzLwlAKx63On5joEI1qYhXvKF1JMc3oEzaETTv9mw-vXHt_J-YYlPQi_nG4jQKoDFJ-XCx1fjVVGlqBsPj5Pf1-SGT
        0       https   
https://mail.google.com/mail/?auth=DQAAAL8AAABzUu3D7vQTObQbtiQU-X_6NnwgrsDnQe_7yXrUrFrniwP5j04Q9jVgc203CAd7rwHnO0tvXTI8MSlRISJz3tGutyOc_uw5khR4FHviJuyTEuxKJZPUmQXnIWxZf_CQoJXGGaxn1kT0scUyrxiBjTfXllUWBVa5iuEzL2lgbAINKmSlLmyg3BaTFb-l0nmDdqGznAJMDgspYtD8iBTcPnOWpGkHXUVtkE0C6KK_3z1eULl0wEne4aU0LNJhlhUa8Xk
  
-0      www.ccrexplorers.com    0       /       1       0       0       
1499619054      1468082755      0       bb_lastvisit    1468083054      0       
http    http://www.ccrexplorers.com/forumdisplay.php?f=17       
-0      .theregister.co.uk      1       /       1       0       1       
1471944077      1468278443      0       __cfduid        
dbda67dd4386142349a936c252ebac7391440408077     0       unused  unused  
-0      nir.theregister.co.uk   0       /       1       0       0       
1470697643      0       0       c       1/front.front.578426ab  0       http    
http://nir.theregister.co.uk/?g=c&g=sa&s=c/front.front  
-0      nir.theregister.co.uk   0       /       1       0       0       
1499814443      0       0       sa      1       0       http    
http://nir.theregister.co.uk/?g=c&g=sa&s=c/front.front  
-0      .regmedia.co.uk 1       /       1       0       1       1471944079      
1468278443      0       __cfduid        
d82e13431caf77499b09ccf54c21999941440408079     0       unused  unused  
+0      .giffgaff.com   1       /       1       0       0       1503402870      
1440407964      0       visid_incap_456843      
MSQtdY7lSvK9UJiZDP3daK0S2lUAAAAAQUIPAAAAAAAudOMnRSt1V9mQN5dPPA+R        0       
unused  unused  
+0      .reddit.com     1       /       1       0       1       1499814590      
1468278656      0       __cfduid        
d2c9a13e6ed171f4318aabcf558fcc6661468278590     0       unused  unused  
+0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loid    lLGqu0nblR8T852T20      0       https   
https://www.reddit.com/ 
+0      www.reddit.com  0       /       1       1       0       1531350591      
1468278656      0       loidcreated     2016-07-11T23%3A09%3A50.925Z    0       
https   https://www.reddit.com/ 
 0      .google.co.uk   1       /       1       0       0       1497632093      
1468278489      0       SID     
DQAAAMkAAACuniK1mc17JMX-o-sfAVqvl0EWP0kiNpQg4lWeslWBnU_km8BK6Eww-1mC6zvnm7Jiv2vft4BOwWiAOmRzN66pbzxGNxKKGzSz2GNdWrcwvuYyQHkevwrtwmKmZGDKsgLljofq6NyNf0AP5xGXfHj18awhbbnymmv5UaDqypGx7FvptGQSMQkj_1hY6NJ5pflIfSnKeEn0Y2mEVyhc1qUiGcJhVKqIRd6xaGKk7l235kOpqxjGK7I4_jTQaORZbp2-RWozAg7SHESSaOpxQ0ZT
        0       unused  unused  
 0      .google.co.uk   1       /       1       0       1       1497632093      
1468278489      0       HSID    ANVWylWAbjjzFxKxI       0       unused  unused  
 0      .google.co.uk   1       /       1       1       1       1497632093      
1468278489      0       SSID    ANtGv1CSBG3CWbdtr       0       unused  unused  
 0      .google.co.uk   1       /       1       0       0       1497632093      
1468278489      0       APISID  IeJTJt20VmceF7bS/AACvc5cSFPpX8FJMj      0       
unused  unused  
 0      .google.co.uk   1       /       1       1       0       1497632093      
1468278489      0       SAPISID baCIIjpj-o3XQCkH/A-WEZgPvnNnguijDQ      0       
unused  unused  
-0      .google.co.uk   1       /       1       0       1       1484089690      
0       0       NID     
81=BGSfpwd63LrhVNUii2KYHfuyCUKzQv2Zg2ik1H_byGynWUgd9_q-kY48oCRapIewLtzMNYtf2KzYBk0_5OoAtNrD-0YSqXDzKalLWfQ8Vxwyywy79YDvAaX_3tprJzjp
     0       unused  unused  
+0      nir.theregister.co.uk   0       /       1       0       0       
1499814443      0       0       sa      1       0       http    
http://nir.theregister.co.uk/?g=c&g=sa&s=c/front.front  
 0      .bbc.co.uk      1       /       1       0       0       1595541997      
1470493359      0       BBC-UID 
35e7d9a5837b2e9d026d30f521339ac6826814226444c1ee4a2134fef248fe180NetSurf/3.6%20(Linux)
  0       unused  unused  
 0      news.bbc.co.uk  0       /       1       0       0       1500933997      
1469574171      0       BBC-UID 
25a73995333b5e9d8ea88a16a17c7b8beea45e555eb863e913853a4de2dcbdb80NetSurf%2f3%2e6%20%28Linux%29
  0       http    http://news.bbc.co.uk/  
-0      en.wikipedia.org        0       /       1       1       1       
1473249600      1470493303      0       WMF-Last-Access 06-Aug-2016     0       
http    http://en.wikipedia.org/wiki/Main_Page  
diff --git a/test/data/urldb b/test/data/urldb
index 62e0da8..07bf1f5 100644
--- a/test/data/urldb
+++ b/test/data/urldb
@@ -5,7 +5,7 @@ http
 
 /wiki/Main_Page
 1
-1470493303
+2100000000
 0
 
 
@@ -13,7 +13,7 @@ https
 
 /wiki/Main_Page
 1
-1470493304
+2100000000
 1
 
 Wikipedia, the free encyclopedia
@@ -43,7 +43,7 @@ http
 
 /
 2
-1469961837
+2100000000
 0
 
 
@@ -51,7 +51,7 @@ https
 
 /
 3
-1470350373
+2100000000
 1
 
 Slashdot: News for nerds, stuff that matters
@@ -61,7 +61,7 @@ http
 
 /news/science_and_environment
 1
-1470493359
+2100000000
 1
 
 Science & Environment - BBC News
diff --git a/test/data/urldb-out b/test/data/urldb-out
new file mode 100644
index 0000000..6fd2024
--- /dev/null
+++ b/test/data/urldb-out
@@ -0,0 +1,47 @@
+106
+en.wikipedia.org
+2
+http
+
+/wiki/Main_Page
+1
+2100000000
+0
+
+
+https
+
+/wiki/Main_Page
+1
+2100000000
+1
+
+Wikipedia, the free encyclopedia
+slashdot.org
+2
+http
+
+/
+2
+2100000000
+0
+
+
+https
+
+/
+3
+2100000000
+1
+
+Slashdot: News for nerds, stuff that matters
+www.bbc.co.uk
+1
+http
+
+/news/science_and_environment
+1
+2100000000
+1
+
+Science & Environment - BBC News
diff --git a/test/urldbtest.c b/test/urldbtest.c
index bd9fa93..6b3f2ac 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -43,13 +43,67 @@
 #include "desktop/gui_internal.h"
 #include "desktop/cookie_manager.h"
 
+/**
+ * url database used as input to test sets
+ */
 const char *test_urldb_path = "test/data/urldb";
+/**
+ * url database used as output reference
+ */
+const char *test_urldb_out_path = "test/data/urldb-out";
+
+/**
+ * cookie database used as input
+ */
 const char *test_cookies_path = "test/data/cookies";
+/**
+ * cookie database used as output reference
+ */
+const char *test_cookies_out_path = "test/data/cookies-out";
 
 const char *wikipedia_url = "http://www.wikipedia.org/";;
 
 struct netsurf_table *guit = NULL;
 
+/**
+ * compare two files contents
+ */
+static int cmp(const char *f1, const char *f2)
+{
+       int res = 0;
+       FILE *fp1;
+       FILE *fp2;
+       int ch1;
+       int ch2;
+
+       fp1 = fopen(f1, "r");
+       if (fp1 == NULL) {
+               return -1;
+       }
+       fp2 = fopen(f2, "r");
+       if (fp2 == NULL) {
+               fclose(fp1);
+               return -1;
+       }
+
+       while (res == 0) {
+               ch1 = fgetc(fp1);
+               ch2 = fgetc(fp2);
+
+               if (ch1 != ch2) {
+                       res = 1;
+               }
+
+               if (ch1 == EOF) {
+                       break;
+               }
+       }
+
+       fclose(fp1);
+       fclose(fp2);
+       return res;
+}
+
 /*************** original test helpers ************/
 
 bool cookie_manager_add(const struct cookie_data *data)
@@ -71,27 +125,6 @@ static nsurl *make_url(const char *url)
        return nsurl;
 }
 
-static char *make_path_query(nsurl *url)
-{
-       size_t len;
-       char *path_query;
-       if (nsurl_get(url, NSURL_PATH | NSURL_QUERY, &path_query, &len) !=
-                       NSERROR_OK) {
-               LOG("failed creating path_query");
-               exit(1);
-       }
-       return path_query;
-}
-
-static lwc_string *make_lwc(const char *str)
-{
-       lwc_string *lwc;
-       if (lwc_intern_string(str, strlen(str), &lwc) != lwc_error_ok) {
-               LOG("failed creating lwc_string");
-               exit(1);
-       }
-       return lwc;
-}
 
 static bool test_urldb_set_cookie(const char *header, const char *url,
                const char *referer)
@@ -208,58 +241,37 @@ START_TEST(urldb_original_test)
        nsurl *urlr;
        char *path_query;
 
-       h = urldb_add_host("127.0.0.1");
-       ck_assert_msg(h != NULL, "failed adding host");
-
-       h = urldb_add_host("intranet");
-       ck_assert_msg(h != NULL, "failed adding host");
-
+       /* ensure title can be set */
        url = make_url("http://intranet/";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url);
-       ck_assert_msg(p != NULL, "failed adding path");
-
-       lwc_string_unref(scheme);
-
+       urldb_add_url(url);
        urldb_set_url_title(url, "foo");
 
        u = urldb_get_url_data(url);
-       assert(u && strcmp(u->title, "foo") == 0);
+       ck_assert(u && strcmp(u->title, "foo") == 0);
        nsurl_unref(url);
 
-       /* Get host entry */
-       h = urldb_add_host("netsurf.strcprstskrzkrk.co.uk");
-       ck_assert_msg(h != NULL, "failed adding host");
-
-       /* Get path entry */
+       /* fragments */
        url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       path_query = make_path_query(url);
-       fragment = make_lwc("zz");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
-
-       lwc_string_unref(fragment);
-
-       fragment = make_lwc("aa");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       lwc_string_unref(fragment);
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#zz?a=b";);
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       fragment = make_lwc("yy");
-       p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#aa?a=b";);
+       ck_assert(urldb_add_url(url) == true);
+       nsurl_unref(url);
 
-       free(path_query);
-       lwc_string_unref(fragment);
-       lwc_string_unref(scheme);
+       url = 
make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#yy?a=b";);
+       ck_assert(urldb_add_url(url) == true);
        nsurl_unref(url);
 
        url = make_url("file:///home/");
-       urldb_add_url(url);
+       ck_assert(urldb_add_url(url) == true);
        nsurl_unref(url);
 
+       /* set cookies on urls */
        url = 
make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2";);
        urldb_set_cookie("mmblah=foo; path=/; expires=Thur, 31-Dec-2099 
00:00:00 GMT\r\n", url, NULL);
        nsurl_unref(url);
@@ -416,6 +428,11 @@ static TCase *urldb_original_case_create(void)
        return tc;
 }
 
+/**
+ * Session basic test case
+ *
+ * The databases are loaded and saved with no manipulation
+ */
 START_TEST(urldb_session_test)
 {
        nserror res;
@@ -435,12 +452,22 @@ START_TEST(urldb_session_test)
        res = urldb_save(outnam);
        ck_assert_int_eq(res, NSERROR_OK);
 
+       /* check for the correct answer */
+       ck_assert_int_eq(cmp(outnam, test_urldb_out_path), 0);
+
        /* remove test output */
        unlink(outnam);
 
        /* write cookies out */
+       outnam = tmpnam(NULL);
        urldb_save_cookies(outnam);
 
+       /* check for the correct answer */
+       ck_assert_int_eq(cmp(outnam, test_cookies_out_path), 0);
+
+       /* remove test output */
+       unlink(outnam);
+
        /* finalise options */
        res = nsoption_finalise(NULL, NULL);
        ck_assert_int_eq(res, NSERROR_OK);
@@ -448,6 +475,11 @@ START_TEST(urldb_session_test)
 }
 END_TEST
 
+/**
+ * Session more extensive test case
+ *
+ * The databases are loaded and saved with a host and paths added
+ */
 START_TEST(urldb_session_add_test)
 {
        nserror res;
@@ -467,15 +499,12 @@ START_TEST(urldb_session_add_test)
        urldb_load_cookies(test_cookies_path);
 
        /* add something to db */
-       h = urldb_add_host("tree.example.com");
-       ck_assert_msg(h != NULL, "failed adding host");
-
        url = make_url("http://tree.example.com/";);
-       scheme = nsurl_get_component(url, NSURL_SCHEME);
-       p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url);
-       ck_assert_msg(p != NULL, "failed adding path");
+       urldb_add_url(url);
+
+       res = urldb_update_url_visit_data(url);
+       ck_assert_int_eq(res, NSERROR_OK);
 
-       lwc_string_unref(scheme);
        nsurl_unref(url);
 
        /* write database out */
@@ -487,8 +516,12 @@ START_TEST(urldb_session_add_test)
        unlink(outnam);
 
        /* write cookies out */
+       outnam = tmpnam(NULL);
        urldb_save_cookies(outnam);
 
+       /* remove test output */
+       unlink(outnam);
+
        /* finalise options */
        res = nsoption_finalise(NULL, NULL);
        ck_assert_int_eq(res, NSERROR_OK);
@@ -496,7 +529,12 @@ START_TEST(urldb_session_add_test)
 }
 END_TEST
 
-
+/**
+ * Test case to check entire session
+ *
+ * These tests define a session as loading a url database and cookie
+ * database and then saving them back to disc.
+ */
 static TCase *urldb_session_case_create(void)
 {
        TCase *tc;
@@ -818,19 +856,18 @@ static TCase *urldb_cookie_case_create(void)
 }
 
 
-
-
 /**
- * Test urldb_add_host asserting on NULL.
+ * Test urldb_add_url asserting on NULL.
  */
-START_TEST(urldb_api_add_host_assert_test)
+START_TEST(urldb_api_add_url_assert_test)
 {
-       struct host_part *res;
-       res = urldb_add_host(NULL);
-       ck_assert(res == NULL);
+       bool res;
+       res = urldb_add_url(NULL);
+       ck_assert(res == true);
 }
 END_TEST
 
+
 /**
  * test url database finalisation without initialisation.
  */
@@ -850,12 +887,11 @@ static TCase *urldb_api_case_create(void)
        tc = tcase_create("API_checks");
 
        tcase_add_test_raise_signal(tc,
-                                   urldb_api_add_host_assert_test,
+                                   urldb_api_add_url_assert_test,
                                    6);
 
        tcase_add_test(tc, urldb_api_destroy_no_init_test);
 
-
        return tc;
 }
 


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to