diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-28 20:50:51 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-28 21:06:28 +0200 |
commit | 9653c35fb9a4398942ecb305835a95fbd87c433a (patch) | |
tree | 2db576e71cd89557592715d64ecb4fb4a46f8c66 /src/server | |
parent | dbf2e0e831ebaf8a0e6f375a8f423f87280e7862 (diff) | |
download | chawan-9653c35fb9a4398942ecb305835a95fbd87c433a.tar.gz |
buffer, pager, config: add meta-refresh + misc fixes
* buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/buffer.nim | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 984ed826..e27e42e0 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -1,4 +1,4 @@ -from std/strutils import split, toUpperAscii, find +from std/strutils import split, toUpperAscii, find, AllChars import std/macros import std/nativesockets @@ -62,7 +62,8 @@ type bcReadCanceled, bcClick, bcFindNextLink, bcFindPrevLink, bcFindNthLink, bcFindRevNthLink, bcFindNextMatch, bcFindPrevMatch, bcGetLines, bcUpdateHover, bcGotoAnchor, bcCancel, bcGetTitle, bcSelect, bcClone, - bcFindPrevParagraph, bcFindNextParagraph, bcMarkURL, bcToggleImages + bcFindPrevParagraph, bcFindNextParagraph, bcMarkURL, bcToggleImages, + bcCheckRefresh BufferState = enum bsLoadingPage, bsLoadingResources, bsLoaded @@ -131,7 +132,7 @@ type BufferConfig* = object userstyle*: string - referer_from*: bool + refererFrom*: bool styling*: bool scripting*: bool images*: bool @@ -140,6 +141,7 @@ type charsetOverride*: Charset protocol*: Table[string, ProtocolConfig] autofocus*: bool + metaRefresh*: MetaRefresh proc getFromOpaque[T](opaque: pointer; res: var T) = let opaque = cast[InterfaceOpaque](opaque) @@ -704,6 +706,52 @@ proc gotoAnchor*(buffer: Buffer): GotoAnchorResult {.proxy.} = ) return GotoAnchorResult(found: false) +type CheckRefreshResult* = object + # n is timeout in millis. -1 => not found + n*: int + # url == nil => self + url*: URL + +proc checkRefresh*(buffer: Buffer): CheckRefreshResult {.proxy.} = + if buffer.document == nil: + return CheckRefreshResult(n: -1) + let element = buffer.document.findMetaRefresh() + if element == nil: + return CheckRefreshResult(n: -1) + let s = element.attr(satContent) + var i = s.skipBlanks(0) + let s0 = s.until(AllChars - AsciiDigit, i) + let x = parseUInt32(s0, allowSign = false) + if s0 != "": + if x.isNone and (i >= s.len or s[i] != '.'): + return CheckRefreshResult(n: -1) + var n = int(x.get(0) * 1000) + i = s.skipBlanks(i + s0.len) + if i < s.len and s[i] == '.': + inc i + let s1 = s.until(AllChars - AsciiDigit, i) + if s1 != "": + n += int(parseUInt32(s1, allowSign = false).get(0)) + i = s.skipBlanks(i + s1.len) + if i >= s.len: # just reload this page + return CheckRefreshResult(n: n) + if s[i] notin {',', ';'}: + return CheckRefreshResult(n: -1) + i = s.skipBlanks(i + 1) + if s.startsWithIgnoreCase("url=", i): + i = s.skipBlanks(i + "url=".len) + var q = false + if i < s.len and s[i] in {'"', '\''}: + q = true + inc i + var s2 = s.substr(i) + if q and s2.len > 0 and s[^1] in {'"', '\''}: + s2.setLen(s2.high) + let url = buffer.document.parseURL(s2) + if url.isNone: + return CheckRefreshResult(n: -1) + return CheckRefreshResult(n: n, url: url.get) + proc do_reshape(buffer: Buffer) = if buffer.document == nil: return # not parsed yet, nothing to render |