about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-08 21:30:32 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-08 21:47:19 +0200
commitdee468d502a2d2e0aa6ae2f8365c098f72acc0c9 (patch)
tree8700f96705e1e9f12122539c81047b43d6992a8b /src/config
parentbb0605182a3944418f74e1f5269916d4d0298190 (diff)
downloadchawan-dee468d502a2d2e0aa6ae2f8365c098f72acc0c9.tar.gz
pager, buffer: improve forms, protocol config
* refactor form submission
* add options to specify form handling per protocol
* block cross-protocol POST requests
Diffstat (limited to 'src/config')
-rw-r--r--src/config/config.nim21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index 35ca1a17..50173057 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -43,7 +43,13 @@ type
   ActionMap = object
     t: Table[string, string]
 
-  SiteConfig* = object
+  FormRequestType* = enum
+    frtHttp = "http"
+    frtFtp = "ftp"
+    frtData = "data"
+    frtMailto = "mailto"
+
+  SiteConfig* = ref object
     url*: Option[Regex]
     host*: Option[Regex]
     rewrite_url*: Option[JSValueFunction]
@@ -59,7 +65,7 @@ type
     default_headers*: TableRef[string, string]
     insecure_ssl_no_verify*: Option[bool]
 
-  OmniRule* = object
+  OmniRule* = ref object
     match*: Regex
     substitute_url*: Option[JSValueFunction]
 
@@ -131,6 +137,9 @@ type
     force_pixels_per_column* {.jsgetset.}: bool
     force_pixels_per_line* {.jsgetset.}: bool
 
+  ProtocolConfig* = ref object
+    form_request*: FormRequestType
+
   Config* = ref object
     jsctx: JSContext
     jsvfns*: seq[JSValueFunction]
@@ -145,6 +154,7 @@ type
     input* {.jsget.}: InputConfig
     display* {.jsget.}: DisplayConfig
     #TODO getset
+    protocol*: Table[string, ProtocolConfig]
     siteconf*: seq[SiteConfig]
     omnirule*: seq[OmniRule]
     cmd*: CommandConfig
@@ -289,6 +299,8 @@ type ConfigParser = object
 
 proc parseConfigValue(ctx: var ConfigParser; x: var object; v: TomlValue;
   k: string)
+proc parseConfigValue(ctx: var ConfigParser; x: var ref object; v: TomlValue;
+  k: string)
 proc parseConfigValue(ctx: var ConfigParser; x: var bool; v: TomlValue;
   k: string)
 proc parseConfigValue(ctx: var ConfigParser; x: var string; v: TomlValue;
@@ -365,6 +377,11 @@ proc parseConfigValue(ctx: var ConfigParser; x: var object; v: TomlValue;
           fk
         ctx.parseConfigValue(fv, v[kebabk], kkk)
 
+proc parseConfigValue(ctx: var ConfigParser; x: var ref object; v: TomlValue;
+    k: string) =
+  new(x)
+  ctx.parseConfigValue(x[], v, k)
+
 proc parseConfigValue[U, V](ctx: var ConfigParser; x: var Table[U, V];
     v: TomlValue; k: string) =
   typeCheck(v, tvtTable, k)