diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-29 18:27:37 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-29 18:43:22 +0100 |
commit | aa2e19429c2e5ed42a21470c36635f6543b129fb (patch) | |
tree | ff45d52ec207db6d868ed368258d04ebd1e25aed /src/config/config.nim | |
parent | e60c82ec37b69ce82f40de5f66f079a9a0aee6be (diff) | |
download | chawan-aa2e19429c2e5ed42a21470c36635f6543b129fb.tar.gz |
cookie: add persistent cookies, misc refactoring/fixes
Mostly compatible with other browsers/tools that follow the Netscape/curl format. Cookie jars are represented by prepending "jar@" to the host part, but *only* if the target jar is different than the domain. Hopefully, other software at least does not choke on this convention. (At least curl seems to simply ignore the entries.) Also, I've moved cookies.nim to config so that code for local files parsed at startup remains in one place.
Diffstat (limited to 'src/config/config.nim')
-rw-r--r-- | src/config/config.nim | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index 690014b5..734a3a04 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -5,6 +5,7 @@ import std/tables import chagashi/charset import config/chapath +import config/cookie import config/mailcap import config/mimetypes import config/toml @@ -21,7 +22,6 @@ import monoucha/tojs import server/headers import types/cell import types/color -import types/cookie import types/jscolor import types/opt import types/url @@ -56,11 +56,16 @@ type frtData = "data" frtMailto = "mailto" + CookieMode* = enum + cmNone = "false" + cmReadOnly = "true" + cmSave = "save" + SiteConfig* = ref object url*: Option[Regex] host*: Option[Regex] rewrite_url*: Option[JSValueFunction] - cookie*: Option[bool] + cookie*: Option[CookieMode] share_cookie_jar*: Option[string] referer_from*: Option[bool] scripting*: Option[ScriptingMode] @@ -113,6 +118,7 @@ type bookmark* {.jsgetset.}: ChaPathResolved history_file*: ChaPathResolved history_size* {.jsgetset.}: int32 + cookie_file*: ChaPathResolved download_dir* {.jsgetset.}: ChaPathResolved w3m_cgi_compat* {.jsgetset.}: bool copy_cmd* {.jsgetset.}: string @@ -161,7 +167,7 @@ type styling* {.jsgetset.}: bool scripting* {.jsgetset.}: ScriptingMode images* {.jsgetset.}: bool - cookie* {.jsgetset.}: bool + cookie* {.jsgetset.}: CookieMode referer_from* {.jsgetset.}: bool autofocus* {.jsgetset.}: bool meta_refresh* {.jsgetset.}: MetaRefresh @@ -333,6 +339,8 @@ proc parseConfigValue(ctx: var ConfigParser; x: var ColorMode; v: TomlValue; k: string) proc parseConfigValue(ctx: var ConfigParser; x: var ScriptingMode; v: TomlValue; k: string) +proc parseConfigValue(ctx: var ConfigParser; x: var CookieMode; v: TomlValue; + k: string) proc parseConfigValue[T](ctx: var ConfigParser; x: var Option[T]; v: TomlValue; k: string) proc parseConfigValue(ctx: var ConfigParser; x: var ARGBColor; v: TomlValue; @@ -497,6 +505,17 @@ proc parseConfigValue(ctx: var ConfigParser; x: var ScriptingMode; v: TomlValue; raise newException(ValueError, "unknown scripting mode '" & v.s & "' for key " & k) +proc parseConfigValue(ctx: var ConfigParser; x: var CookieMode; v: TomlValue; + k: string) = + typeCheck(v, {tvtString, tvtBoolean}, k) + if v.t == tvtBoolean: + x = if v.b: cmReadOnly else: cmNone + elif v.s == "save": + x = cmSave + else: + raise newException(ValueError, "unknown cookie mode '" & v.s & + "' for key " & k) + proc parseConfigValue(ctx: var ConfigParser; x: var ARGBColor; v: TomlValue; k: string) = typeCheck(v, tvtString, k) |