about summary refs log tree commit diff stats
path: root/src/loader/loader.nim
Commit message (Collapse)AuthorAgeFilesLines
* loader, pager: fix fd leaksbptato2024-09-251-0/+2
|
* Replace std/selectors with pollbptato2024-09-231-44/+19
| | | | | | | | | | | | std/selectors uses OS-specific selector APIs, which sounds good in theory (faster than poll!), but sucks for portability in practice. Sure, you can fix portability bugs, but who knows how many there are on untested platforms... poll is standard, so if it works on one computer it should work on all other ones. (I hope.) As a bonus, I rewrote the timeout API for poll, which incidentally fixes setTimeout across forks. Also, SIGWINCH should now work on all platforms (as we self-pipe instead of signalfd/kqueue magic).
* client, forkserver, dynstream: misc refactorings, fixesbptato2024-09-231-0/+2
| | | | | | * fix broken int conversion in dynstream * fix EPIPE handling in forkserver * merge fdmap and connectingContainers into loader map
* loader: mmap intermediate image files, misc refactoringbptato2024-09-221-36/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | * refactor parseHeader * optimize response blob() * add direct "to cache" mode for loader requests which sets stdout to a file, and use it for image processing * move image resizing into a separate process * mmap cache files in between processing steps when possible At last, resize is no longer a part of image decoding. Also, it feels much nicer to keep encoded image data in the same cache as everything else. The mmap operations *should* be more efficient than copying the whole RGBA data through a pipe. In practice, it only makes a difference for loading (well, now just mmapping) the encoded image into the pager, where it singlehandedly speeds up image display by 10x on my test image. For the other steps, the unfortunate fact that "tocache" must delay the next fork/exec in the pipeline until the entire image is processed seems to equal out any wins we might have gotten from skipping a single raw RGBA copy. I have tried moving the delay before the exec (it's possible with yet another pipe), but it didn't help much and made the code much uglier. (Not that tocache didn't, but I can live with this...)
* loader: fix rbtCache racebptato2024-09-151-34/+44
| | | | | | | | | | | | | | | I thought this would work fine, but then images weren't loading. Upon closer inspection I realized we don't necessarily let the image decoder finish reading the entire file on pass 1 (header parsing), which means pass 2 (decoding) can end up reading a partially downloaded cache file. To fix this, we now fall back to streaming mode when an open handle to the cached item still exists. (An alternative would be to wait for the cached item to finish loading, but that's harder to implement and might be slower anyway - the current implementation allows for the decoder to run while an image is still being loaded, but we couldn't do that with the second approach.)
* loader: refactor/move around some procsbptato2024-09-151-429/+317
| | | | | | | | | | | | | | Module boundaries didn't make much sense here either. Specifically: * loader/cgi was originally just one of the many "real" protocols supported by loader, so it was in a separate module (like the other ones). Now it's mostly an "internal" protocol, and it was getting cumbersome to pass all required loader state to loadCGI. * The loader interface has grown quite large, but there is no need for (or advantage in) putting it in the same module as the implementation. Now CGI is handled by loader, and the interface is in the new module "loaderiface".
* loader: improve map interfacebptato2024-09-141-3/+8
| | | | directly accessing map was a bit too error prone
* loader: refactor, misc optimizations & fixesbptato2024-09-141-101/+180
| | | | | | | | * factor out input/output handle tables; use a seq instead * add possibility to directly open cached items onto stdin (mainly an optimization for reading images, which are always cached) * close used handles on local CGI execution * make clone during load work again
* loader, client, buffer: use selectInto (not select)bptato2024-09-031-3/+4
| | | | select allocates. (makes sense, but I never realized...)
* loader: fix crashes with kqueue backendbptato2024-09-031-3/+22
| | | | | | | pain... (also, fix an fd leak, plus a more general bug where we registered empty output handles.)
* loader: fix some fd leaksbptato2024-09-021-7/+24
| | | | + be a bit more paranoid about double closes
* canvas: move to separate CGI scriptbptato2024-09-011-11/+13
| | | | | | | | | | * stream: and passFd is now client-based, and accessible for buffers * Bitmap's width & height is now int, not uint64 * no more non-network Bitmap special case in the pager for canvas I just shoehorned it into the static image model, so it still doesn't render changes after page load. But at least now it doesn't crash the browser.
* loader: fix crash on empty data URLsbptato2024-08-171-1/+8
|
* xhr: more progressbptato2024-08-151-0/+2
| | | | | | | | | | * add responseText, response * add net tests -> currently sync XHR only; should find a way to do async tests... * update monoucha -> simplified & updated some related code that no longer worked properly
* xhr: progressbptato2024-08-131-10/+6
| | | | | | | | | | | | | * fix header case sensitivity issues -> probably still wrong as it discards the original casing. better than nothing, anyway * fix fulfill on generic promises * support standard open() async parameter weirdness * refactor loader response body reading (so bodyRead is no longer mandatory) * actually read response body still missing: response body getters
* loader: move back data URL handlingbptato2024-08-031-3/+48
| | | | | | | data URIs can get megabytes long; however, you can only stuff so many bytes into the envp. (This was thwarting my efforts to view pandoc- generated standalone HTML in Chawan.) So put `data:' back into the loader process.
* Fixes for Nim 2.2bptato2024-07-291-2/+0
| | | | | | | | | * xmlhttprequest: fix missing import * painter: generic tuple workaround * dynstream: merge module with implementations (so it will work with vtables) Not enabling vtables yet since it doesn't work with refc.
* loader: follow redirects in fetch()bptato2024-07-271-4/+21
|
* loader: copy cached items on buffer cloningbptato2024-07-201-2/+11
| | | | | This fixes a bug where cloning buffers with images would crash the browser.
* loader: async status/headers for fetchbptato2024-07-191-21/+35
| | | | | | | | The status code & headers are no longer guaranteed to be sent right after res/outputId, so read them asynchronously instead. (This is pretty much the same code as the buffer connection handler in pager. Hopefully we can merge the two at some point.)
* 32-bit compilation fixesbptato2024-07-131-5/+5
| | | | | | | | It seems registerHandle/unregister doesn't accept cint as handles. Not sure why it even works on 64-bit targets... (maybe some converter weirdness?) Seems best to explicitly cast it away.
* loader: fix fd leaksbptato2024-06-291-0/+2
|
* img, loader: add image resizing, misc fixesbptato2024-06-281-50/+46
| | | | | | | | | | | | | | | * resize images with stb_image_resize * use tee for output handle redirection (redirectToFile blocks) * cache original image files * accept lseek in sandbox * misc stbi fixes For now, I just pulled in stb_image_resize v1. v2 is an extra 150K in size, not sure if it's worth the cost. (Either way, we can always switch later if needed, since the API is almost the same.) Next step: move sixel/kitty encoders to CGI, and cache their output in memory instead of the intermediate RGBA representation.
* misc cleanupsbptato2024-06-221-1/+1
|
* client, pager: fix cached item refcounting bugsbptato2024-06-211-16/+36
|
* loader: better error handlingbptato2024-06-201-18/+24
| | | | we no longer crash on broken codecs. yay
* img, loader: separate out png codec into cgi, misc improvementsbptato2024-06-201-87/+73
| | | | | | | | | | | | | | | * multi-processed and sandboxed PNG decoding & encoding (through local CGI) * improved request body passing (including support for output id as response body) * simplified & faster blob()/text() - now every request starts suspended, and OngoingData.buf has been replaced with loader's buffering capability * image caching: we no longer pull bitmaps from the container after every single getLines call Next steps: replace our bespoke PNG decoder with something more usable, add other decoders, and make them stream.
* Move JS wrapper into Monouchabptato2024-06-031-2/+3
| | | | Operation "modularize Chawan somewhat" part 3
* html: improve Request, derive Client from Windowbptato2024-05-201-11/+11
| | | | | | | * make Client an instance of Window (for less special casing) * misc work on Request & fetch * improve origin comparison (opaque origins of same URLs are now considered the same)
* config: separate tmp dir for sockets, usersbptato2024-05-161-1/+2
| | | | | | | * add $LOGNAME to the tmp directory name, so that tmpdirs of separate users don't conflict * use separate directory for sockets, so that we do not have to give buffers access to all cached pages
* js: refactorbptato2024-05-081-1/+1
| | | | | | | * prefix to-be-separated modules with js * remove dynstreams dependency * untangle from EmptyPromise * move typeptr into tojs
* loader: fix applying config for initial requestbptato2024-05-021-25/+45
| | | | | | Instead of the error-prone method of selectively applying config values only for non-initial requests, add a separate (privileged) loader command which allows specifying a different client config.
* config: add insecure-ssl-no-verify option to siteconfbptato2024-05-011-1/+4
| | | | | | | Equivalent to curl --insecure. Note: unfortunately this does not help if the server is using unsafe legacy renegotiation, you have to allow that in the OpenSSL config.
* url, twtstr: correct number parsingbptato2024-04-181-8/+5
| | | | | | | | | * do not use std's parse*Int; they accept weird stuff that we do not want to accept in any case * fix bug in parseHost where a parseIpv4 failure would result in an empty host * do not use isDigit, isAlphaAscii * improve parse*IntImpl error handling
* sandbox: seccomp support on Linuxbptato2024-04-181-5/+4
| | | | | | | | | | | | | | | | | We use libseccomp, which is now a semi-mandatory dependency on Linux. (You can still build without it, but only if you pass a scary long flag to make.) For this to work I had to disable getTimezoneOffset, which would otherwise call localtime_r which in turn reads in some files from /usr/share/zoneinfo. To allow this we would have to give unrestricted openat(2) access to buffer processes, which is unacceptable. (Giving websites access to the local timezone is a fingerprinting vector so if this ever gets fixed then it should be an opt-in config setting.) This patch also includes misc fixes to buffer cloning, and fixes the LIBEXECDIR override in the makefile so that it is actually useful.
* Update code stylebptato2024-04-171-1/+1
| | | | | | * separate params with ; (semicolon) instead of , (colon) * reduce screaming snake case use * wrap long lines
* loader: constant time key comparisonbptato2024-04-021-1/+13
| | | | | GCC seems to generate something that strongly resembles a constant time comparison, so I guess this should be good enough.
* Add capsicum supportbptato2024-03-281-2/+19
| | | | | | | | | | | | | It's the sandboxing system of FreeBSD. Quite pleasant to work with. (Just trying to figure out the basics with this one before tackling the abomination that is seccomp.) Indeed, the only non-trivial part was getting newSelector to work with Capsicum. Long story short it doesn't, so we use an ugly pointer cast + assignment. But even that is stdlib's "fault", not Capsicum's. This also gets rid of that ugly SocketPath global.
* buffer: fix cancel()bptato2024-03-271-0/+1
| | | | | | | | | | * fix mismatch between return value & read value that would either crash or freeze the browser depending on its mood * add an assertion to detect the above footgun * fix some resource leaks * fix iteration over a table that called a function which altered the table in buffer's cancel() * if user cancels before anything is loaded, destroy the container too
* loader: fix failed doRequest handlingbptato2024-03-251-2/+1
| | | | copy-paste error
* io: derive DynStream from RootObj (not Stream)bptato2024-03-241-64/+68
| | | | | | | | This way they are no longer compatible, but we no longer need them to be compatible anyway. (This also forces us to throw out the old serialize module, and use packet writers everywhere.)
* io: add bufreaderbptato2024-03-211-122/+133
| | | | analogous to bufwriter
* config: add default-headers to siteconfbptato2024-03-211-14/+19
| | | | | | | So long as we have to live with siteconf, let's at least make it useful. Also, rewrite the header overriding logic because while it did work, it only did so accidentally.
* loader: set static CGI env vars in initLoaderContextbptato2024-03-211-0/+8
| | | | no reason to do it separately in setupEnv
* main: set CHA_LIBEXEC_DIR env var at startupbptato2024-03-191-5/+2
| | | | This way, we can use it everywhere (e.g. in mailcap).
* io: add BuferedWriterbptato2024-03-161-49/+64
| | | | | | | | | | Unsurprisingly enough, calling `write` a million times is never going to be very fast. BufferedWriter basically does the same thing as serialize.swrite did, but queues up writes in batches before sending them. TODO: give sread a similar treatment
* pager, loader: add "Save file to" functionalitybptato2024-03-161-19/+53
| | | | | | | As simple as it could be; no download panel yet. Also, remove the xdg-open default mailcap entry; it's better to just save by default.
* loader: add missing flush() callsbptato2024-03-161-1/+4
| | | | | | | Seems wise to flush before e.g. reading. And unwise to enable buffering on tee() even though we disable it on startRequest()
* cgi: fix libexec dir not being setbptato2024-03-161-3/+4
|
* Clean up BufferConfigbptato2024-03-151-2/+3
| | | | | | | | It was defined in the wrong module, and unnecessarily included LoaderClientConfig. Also, referrerPolicy was not being propagated to loader clients because it was (incorrectly) in BufferConfig instead of LoaderClientConfig.