diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-13 00:04:50 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-13 00:04:50 +0100 |
commit | d9e430c8147c8c2d81b4ca5405786269b2cfc94d (patch) | |
tree | 91ddb6edbedc6e8310fedc13106b8b3bdcec2cdc /src/ips | |
parent | 7a3fb32bff44a581d6926bfaf5f070f8ef062338 (diff) | |
download | chawan-d9e430c8147c8c2d81b4ca5405786269b2cfc94d.tar.gz |
Add all sorts of config options and cookies
Diffstat (limited to 'src/ips')
-rw-r--r-- | src/ips/forkserver.nim | 14 | ||||
-rw-r--r-- | src/ips/serialize.nim | 20 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/ips/forkserver.nim b/src/ips/forkserver.nim index eb850ea0..e8904354 100644 --- a/src/ips/forkserver.nim +++ b/src/ips/forkserver.nim @@ -12,6 +12,7 @@ import io/window import ips/serialize import ips/serversocket import types/buffersource +import types/cookie import utils/twtstr type @@ -28,10 +29,11 @@ type ostream: Stream children: seq[(Pid, Pid)] -proc newFileLoader*(forkserver: ForkServer, defaultHeaders: HeaderList = DefaultHeaders, filter = newURLFilter()): FileLoader = +proc newFileLoader*(forkserver: ForkServer, defaultHeaders: HeaderList = DefaultHeaders, filter = newURLFilter(), cookiejar: CookieJar = nil): FileLoader = forkserver.ostream.swrite(FORK_LOADER) forkserver.ostream.swrite(defaultHeaders) forkserver.ostream.swrite(filter) + forkserver.ostream.swrite(cookiejar) forkserver.ostream.flush() forkserver.istream.sread(result) @@ -45,7 +47,7 @@ proc removeChild*(forkserver: Forkserver, pid: Pid) = forkserver.ostream.swrite(pid) forkserver.ostream.flush() -proc forkLoader(ctx: var ForkServerContext, defaultHeaders: HeaderList, filter: URLFilter): FileLoader = +proc forkLoader(ctx: var ForkServerContext, defaultHeaders: HeaderList, filter: URLFilter, cookiejar: CookieJar): FileLoader = var pipefd: array[2, cint] if pipe(pipefd) == -1: raise newException(Defect, "Failed to open pipe.") @@ -56,7 +58,7 @@ proc forkLoader(ctx: var ForkServerContext, defaultHeaders: HeaderList, filter: ctx.children.setLen(0) zeroMem(addr ctx, sizeof(ctx)) discard close(pipefd[0]) # close read - runFileLoader(pipefd[1], defaultHeaders, filter) + runFileLoader(pipefd[1], defaultHeaders, filter, cookiejar) assert false let readfd = pipefd[0] # get read discard close(pipefd[1]) # close write @@ -77,7 +79,7 @@ proc forkBuffer(ctx: var ForkServerContext): Pid = ctx.istream.sread(config) ctx.istream.sread(attrs) ctx.istream.sread(mainproc) - let loader = ctx.forkLoader(DefaultHeaders, config.filter) #TODO make this configurable + let loader = ctx.forkLoader(DefaultHeaders, config.filter, config.cookiejar) #TODO make this configurable let pid = fork() if pid == 0: for i in 0 ..< ctx.children.len: ctx.children[i] = (Pid(0), Pid(0)) @@ -109,9 +111,11 @@ proc runForkServer() = of FORK_LOADER: var defaultHeaders: HeaderList var filter: URLFilter + var cookiejar: CookieJar ctx.istream.sread(defaultHeaders) ctx.istream.sread(filter) - let loader = ctx.forkLoader(defaultHeaders, filter) + ctx.istream.sread(cookiejar) + let loader = ctx.forkLoader(defaultHeaders, filter, cookiejar) ctx.ostream.swrite(loader) ctx.children.add((loader.process, Pid(-1))) of LOAD_CONFIG: diff --git a/src/ips/serialize.nim b/src/ips/serialize.nim index 73320b27..ed35371a 100644 --- a/src/ips/serialize.nim +++ b/src/ips/serialize.nim @@ -139,7 +139,10 @@ func slen*(b: bool): int = return sizeof(uint8) proc swrite*(stream: Stream, url: Url) = - stream.swrite(url.serialize()) + if url != nil: + stream.swrite(url.serialize()) + else: + stream.swrite("") proc sread*(stream: Stream, url: var Url) = var s: string @@ -215,14 +218,21 @@ func slen*(obj: object): int = result += slen(f) proc swrite*(stream: Stream, obj: ref object) = - stream.swrite(obj[]) + stream.swrite(obj != nil) + if obj != nil: + stream.swrite(obj[]) proc sread*(stream: Stream, obj: var ref object) = - new(obj) - stream.sread(obj[]) + var n: bool + stream.sread(n) + if n: + new(obj) + stream.sread(obj[]) func slen*(obj: ref object): int = - slen(obj[]) + result = slen(obj != nil) + if obj != nil: + result += slen(obj[]) proc swrite*(stream: Stream, part: MimePart) = stream.swrite(part.isFile) |