diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 9 | ||||
-rw-r--r-- | src/gmutil.c | 5 | ||||
-rw-r--r-- | src/gmutil.h | 1 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 15 | ||||
-rw-r--r-- | src/ui/documentwidget.h | 1 |
5 files changed, 25 insertions, 6 deletions
@@ -634,11 +634,10 @@ iBool handleCommand_App(const char *cmd) { | |||
634 | return iTrue; | 634 | return iTrue; |
635 | } | 635 | } |
636 | else if (equal_Command(cmd, "open")) { | 636 | else if (equal_Command(cmd, "open")) { |
637 | const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url"))); | 637 | const iString *url = collectNewCStr_String(suffixPtr_Command(cmd, "url")); |
638 | iUrl parts; | 638 | iUrl parts; |
639 | init_Url(&parts, url); | 639 | init_Url(&parts, url); |
640 | if (equalCase_Rangecc(parts.scheme, "http") || | 640 | if (equalCase_Rangecc(parts.scheme, "http") || equalCase_Rangecc(parts.scheme, "https")) { |
641 | equalCase_Rangecc(parts.scheme, "https")) { | ||
642 | openInDefaultBrowser_App(url); | 641 | openInDefaultBrowser_App(url); |
643 | return iTrue; | 642 | return iTrue; |
644 | } | 643 | } |
@@ -648,8 +647,9 @@ iBool handleCommand_App(const char *cmd) { | |||
648 | } | 647 | } |
649 | iHistory *history = history_DocumentWidget(doc); | 648 | iHistory *history = history_DocumentWidget(doc); |
650 | const iBool isHistory = argLabel_Command(cmd, "history") != 0; | 649 | const iBool isHistory = argLabel_Command(cmd, "history") != 0; |
650 | int redirectCount = argLabel_Command(cmd, "redirect"); | ||
651 | if (!isHistory) { | 651 | if (!isHistory) { |
652 | if (argLabel_Command(cmd, "redirect")) { | 652 | if (redirectCount) { |
653 | replace_History(history, url); | 653 | replace_History(history, url); |
654 | } | 654 | } |
655 | else { | 655 | else { |
@@ -658,6 +658,7 @@ iBool handleCommand_App(const char *cmd) { | |||
658 | } | 658 | } |
659 | visitUrl_Visited(d->visited, url); | 659 | visitUrl_Visited(d->visited, url); |
660 | setInitialScroll_DocumentWidget(doc, argfLabel_Command(cmd, "scroll")); | 660 | setInitialScroll_DocumentWidget(doc, argfLabel_Command(cmd, "scroll")); |
661 | setRedirectCount_DocumentWidget(doc, redirectCount); | ||
661 | setUrlFromCache_DocumentWidget(doc, url, isHistory); | 662 | setUrlFromCache_DocumentWidget(doc, url, isHistory); |
662 | } | 663 | } |
663 | else if (equal_Command(cmd, "document.request.cancelled")) { | 664 | else if (equal_Command(cmd, "document.request.cancelled")) { |
diff --git a/src/gmutil.c b/src/gmutil.c index 41f0dd20..131734b2 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -232,6 +232,11 @@ static const struct { | |||
232 | "Redirect to Non-Gemini URL", | 232 | "Redirect to Non-Gemini URL", |
233 | "The server attempted to redirect us to a non-Gemini URL. Here is the link so you " | 233 | "The server attempted to redirect us to a non-Gemini URL. Here is the link so you " |
234 | "can open it manually if appropriate."} }, | 234 | "can open it manually if appropriate."} }, |
235 | { tooManyRedirects_GmStatusCode, | ||
236 | { 0x27a0, /* dashed arrow */ | ||
237 | "Too Many Redirects", | ||
238 | "You may be stuck in a redirection loop. The next redirected URL is below if you " | ||
239 | "want to continue manually."} }, | ||
235 | { temporaryFailure_GmStatusCode, | 240 | { temporaryFailure_GmStatusCode, |
236 | { 0x1f50c, /* electric plug */ | 241 | { 0x1f50c, /* electric plug */ |
237 | "Temporary Failure", | 242 | "Temporary Failure", |
diff --git a/src/gmutil.h b/src/gmutil.h index dc73ce6e..2c017af4 100644 --- a/src/gmutil.h +++ b/src/gmutil.h | |||
@@ -34,6 +34,7 @@ enum iGmStatusCode { | |||
34 | clientSide_GmStatusCode = -100, | 34 | clientSide_GmStatusCode = -100, |
35 | invalidRedirect_GmStatusCode, | 35 | invalidRedirect_GmStatusCode, |
36 | nonGeminiRedirect_GmStatusCode, | 36 | nonGeminiRedirect_GmStatusCode, |
37 | tooManyRedirects_GmStatusCode, | ||
37 | invalidHeader_GmStatusCode, | 38 | invalidHeader_GmStatusCode, |
38 | unsupportedMimeType_GmStatusCode, | 39 | unsupportedMimeType_GmStatusCode, |
39 | failedToOpenFile_GmStatusCode, | 40 | failedToOpenFile_GmStatusCode, |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 7f76a436..b954040a 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -183,6 +183,7 @@ struct Impl_DocumentWidget { | |||
183 | int certFlags; | 183 | int certFlags; |
184 | iDate certExpiry; | 184 | iDate certExpiry; |
185 | iString * certSubject; | 185 | iString * certSubject; |
186 | int redirectCount; | ||
186 | iBool selecting; | 187 | iBool selecting; |
187 | iRangecc selectMark; | 188 | iRangecc selectMark; |
188 | iRangecc foundMark; | 189 | iRangecc foundMark; |
@@ -221,6 +222,7 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
221 | d->isRequestUpdated = iFalse; | 222 | d->isRequestUpdated = iFalse; |
222 | d->media = new_ObjectList(); | 223 | d->media = new_ObjectList(); |
223 | d->doc = new_GmDocument(); | 224 | d->doc = new_GmDocument(); |
225 | d->redirectCount = 0; | ||
224 | d->initNormScrollY = 0; | 226 | d->initNormScrollY = 0; |
225 | d->scrollY = 0; | 227 | d->scrollY = 0; |
226 | d->smoothScroll = 0; | 228 | d->smoothScroll = 0; |
@@ -512,6 +514,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode | |||
512 | if (meta) { | 514 | if (meta) { |
513 | switch (code) { | 515 | switch (code) { |
514 | case nonGeminiRedirect_GmStatusCode: | 516 | case nonGeminiRedirect_GmStatusCode: |
517 | case tooManyRedirects_GmStatusCode: | ||
515 | appendFormat_String(src, "\n=> %s\n", cstr_String(meta)); | 518 | appendFormat_String(src, "\n=> %s\n", cstr_String(meta)); |
516 | break; | 519 | break; |
517 | case failedToOpenFile_GmStatusCode: | 520 | case failedToOpenFile_GmStatusCode: |
@@ -750,6 +753,10 @@ void setInitialScroll_DocumentWidget(iDocumentWidget *d, float normScrollY) { | |||
750 | d->initNormScrollY = normScrollY; | 753 | d->initNormScrollY = normScrollY; |
751 | } | 754 | } |
752 | 755 | ||
756 | void setRedirectCount_DocumentWidget(iDocumentWidget *d, int count) { | ||
757 | d->redirectCount = count; | ||
758 | } | ||
759 | |||
753 | iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { | 760 | iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { |
754 | return d->state == fetching_RequestState || d->state == receivedPartialResponse_RequestState; | 761 | return d->state == fetching_RequestState || d->state == receivedPartialResponse_RequestState; |
755 | } | 762 | } |
@@ -849,8 +856,12 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { | |||
849 | else { | 856 | else { |
850 | /* Only accept redirects that use gemini scheme. */ | 857 | /* Only accept redirects that use gemini scheme. */ |
851 | const iString *dstUrl = absoluteUrl_String(d->mod.url, meta_GmRequest(d->request)); | 858 | const iString *dstUrl = absoluteUrl_String(d->mod.url, meta_GmRequest(d->request)); |
852 | if (equalCase_Rangecc(urlScheme_String(dstUrl), "gemini")) { | 859 | if (d->redirectCount >= 5) { |
853 | postCommandf_App("open redirect:1 url:%s", cstr_String(dstUrl)); | 860 | showErrorPage_DocumentWidget_(d, tooManyRedirects_GmStatusCode, dstUrl); |
861 | } | ||
862 | else if (equalCase_Rangecc(urlScheme_String(dstUrl), "gemini")) { | ||
863 | postCommandf_App( | ||
864 | "open redirect:%d url:%s", d->redirectCount + 1, cstr_String(dstUrl)); | ||
854 | } | 865 | } |
855 | else { | 866 | else { |
856 | showErrorPage_DocumentWidget_(d, nonGeminiRedirect_GmStatusCode, dstUrl); | 867 | showErrorPage_DocumentWidget_(d, nonGeminiRedirect_GmStatusCode, dstUrl); |
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h index ec97a58a..5a3125af 100644 --- a/src/ui/documentwidget.h +++ b/src/ui/documentwidget.h | |||
@@ -45,5 +45,6 @@ const iString * bookmarkTitle_DocumentWidget (const iDocumentWidget *); | |||
45 | void setUrl_DocumentWidget (iDocumentWidget *, const iString *url); | 45 | void setUrl_DocumentWidget (iDocumentWidget *, const iString *url); |
46 | void setUrlFromCache_DocumentWidget (iDocumentWidget *, const iString *url, iBool isFromCache); | 46 | void setUrlFromCache_DocumentWidget (iDocumentWidget *, const iString *url, iBool isFromCache); |
47 | void setInitialScroll_DocumentWidget (iDocumentWidget *, float normScrollY); /* set after content received */ | 47 | void setInitialScroll_DocumentWidget (iDocumentWidget *, float normScrollY); /* set after content received */ |
48 | void setRedirectCount_DocumentWidget (iDocumentWidget *, int count); | ||
48 | 49 | ||
49 | void updateSize_DocumentWidget (iDocumentWidget *); | 50 | void updateSize_DocumentWidget (iDocumentWidget *); |