From a50a01da45a8fb6a4d6ee419fc1ad240b1f0dee5 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi

Date: Mon, 16 Nov 2020 08:33:35 +0200

Subject: [PATCH 1/1] Remember redirected URLs as visited

"visited.txt" will now remember URLs that were redirects, but those are not shown in the UI as part of the history. This fixes the issue where redirected URLs were not being shown as visited links in the UI.

Beware if downgrading Lagrange: URLs in the history will get prefixed with "0000 ". Might be a good idea to switch to a forwards compatible format like JSON for these files.


src/ui/documentwidget.c | 2 ++

src/ui/window.c | 2 +-

src/visited.c | 22 +++++++++++++++++-----

src/visited.h | 11 ++++++++---

4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c

index 3fc7e841..40f34db4 100644

--- a/src/ui/documentwidget.c

+++ b/src/ui/documentwidget.c

@@ -41,6 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#include "scrollwidget.h"

#include "util.h"

#include "visbuf.h"

+#include "visited.h"

#include <the_Foundation/file.h>

#include <the_Foundation/fileinfo.h>

@@ -1051,6 +1052,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {

                 else if (equalCase_Rangecc(urlScheme_String(dstUrl),

                                            cstr_Rangecc(urlScheme_String(d->mod.url)))) {

                     /* Redirects with the same scheme are automatic. */

                     postCommandf_App(

                         "open redirect:%d url:%s", d->redirectCount + 1, cstr_String(dstUrl));

                 }

diff --git a/src/ui/window.c b/src/ui/window.c

index a69dd7db..ba6ee869 100644

--- a/src/ui/window.c

+++ b/src/ui/window.c

@@ -254,7 +254,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {

         if (equal_Command(cmd, "document.changed")) {

             iInputWidget *url = findWidget_App("url");

             const iString *urlStr = collect_String(suffix_Command(cmd, "url"));

             postCommand_App("visited.changed"); /* sidebar will update */

             setText_InputWidget(url, urlStr);

             updateTextCStr_LabelWidget(reloadButton, reloadCStr_);

diff --git a/src/visited.c b/src/visited.c

index e9dc9b94..b339198e 100644

--- a/src/visited.c

+++ b/src/visited.c

@@ -34,6 +34,7 @@ static const size_t maxAgeVisited_Visited_ = 3600 * 24 * 30; /* one month */

void init_VisitedUrl(iVisitedUrl *d) {

 initCurrent_Time(&d->when);

 init_String(&d->url);

}

void deinit_VisitedUrl(iVisitedUrl *d) {

@@ -81,13 +82,14 @@ void save_Visited(const iVisited *d, const char *dirPath) {

         iDate date;

         init_Date(&date, &item->when);

         format_String(line,

                       date.year,

                       date.month,

                       date.day,

                       date.hour,

                       date.minute,

                       date.second,

                       cstr_String(&item->url));

         writeData_File(f, cstr_String(line), size_String(line));

     }

@@ -106,11 +108,16 @@ void load_Visited(iVisited *d, const char *dirPath) {

     iTime          now;

     initCurrent_Time(&now);

     while (nextSplit_Rangecc(src, "\n", &line)) {

         int y, m, D, H, M, S;

         sscanf(line.start, "%04d-%02d-%02dT%02d:%02d:%02d ", &y, &m, &D, &H, &M, &S);

         if (!y) break;

         iVisitedUrl item;

         init_VisitedUrl(&item);

         init_Time(

             &item.when,

@@ -118,7 +125,7 @@ void load_Visited(iVisited *d, const char *dirPath) {

         if (secondsSince_Time(&now, &item.when) > maxAgeVisited_Visited_) {

             continue; /* Too old. */

         }

         insert_SortedArray(&d->visited, &item);

     }

     unlock_Mutex(d->mtx);

@@ -147,10 +154,11 @@ static size_t find_Visited_(const iVisited *d, const iString *url) {

 return pos;

}

-void visitUrl_Visited(iVisited *d, const iString *url) {

+void visitUrl_Visited(iVisited *d, const iString *url, uint16_t visitFlags) {

 if (isEmpty_String(url)) return;

 iVisitedUrl visit;

 init_VisitedUrl(&visit);

 set_String(&visit.url, url);

 size_t pos;

 lock_Mutex(d->mtx);

@@ -158,6 +166,7 @@ void visitUrl_Visited(iVisited *d, const iString *url) {

     iVisitedUrl *old = at_SortedArray(&d->visited, pos);

     if (cmpNewer_VisitedUrl_(&visit, old)) {

         old->when = visit.when;

         unlock_Mutex(d->mtx);

         deinit_VisitedUrl(&visit);

         return;

@@ -200,7 +209,10 @@ const iArray *list_Visited(const iVisited *d, size_t count) {

 iPtrArray *urls = collectNew_PtrArray();

 iGuardMutex(d->mtx, {

     iConstForEach(Array, i, &d->visited.values) {

     }

 });

 sort_Array(urls, cmpWhenDescending_VisitedUrlPtr_);

diff --git a/src/visited.h b/src/visited.h

index 5a34d008..d9eb02b6 100644

--- a/src/visited.h

+++ b/src/visited.h

@@ -32,8 +32,13 @@ iDeclareType(VisitedUrl)

iDeclareTypeConstruction(VisitedUrl)

struct Impl_VisitedUrl {

+};

+enum iVisitedUrlFlag {

};

iDeclareType(Visited)

@@ -44,7 +49,7 @@ void load_Visited (iVisited *, const char *dirPath);

void save_Visited (const iVisited *, const char *dirPath);

iTime urlVisitTime_Visited (const iVisited *, const iString *url);

-void visitUrl_Visited (iVisited *, const iString url); / adds URL to the visited URLs set */

+void visitUrl_Visited (iVisited *, const iString url, uint16_t visitFlags); / adds URL to the visited URLs set */

void removeUrl_Visited (iVisited *, const iString *url);

const iPtrArray * list_Visited (const iVisited , size_t count); / returns collected */

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.17/patch/a50a01da45a8fb6a4d6ee419fc1ad240b1f0dee5.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
75.466965 milliseconds
Gemini-to-HTML Time
4.438386 milliseconds

This content has been proxied by September (ba2dc).