about summary refs log tree commit diff stats
path: root/src/loader/loader.nim
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* loader: handle connections where pid/key does not matchbptato2024-03-141-1/+8
| | | | | This can easily happen if a buffer process is killed and/or a new process takes its ID.
* Move around some modulesbptato2024-03-141-1/+1
| | | | | | | | * extern -> gone, runproc absorbed by pager, others moved into io/ * display -> local/ (where else would we display?) * xhr -> html/ * move out WindowAttributes from term, so we don't depend on local from server
* pager: add "open in editor" keybinding (sE)bptato2024-03-141-10/+18
| | | | | | only for source for now, rendered document is a bit more complicated (also, get rid of useless extern/editor module)
* loader: only trap SIGTERMbptato2024-03-141-1/+1
| | | | SIGINT is trapped (well, ignored) by forkserver already.
* loader: fix crash on malformed CGI headersbptato2024-03-141-1/+1
| | | | | Setting istream to nil was preventing finishCycle from unregistering & closing it.
* client: fix blocking reads on container connectionbptato2024-03-121-23/+19
| | | | | | | | | | | | | | | | Sometimes, headers take a while to reach us even after the result has been sent. e.g. echo 'Cha-Control: Connected' sleep 5 echo 'Cha-Control: ControlDone' ^ this froze the UI for 5 seconds, that's certainly not what we want. Since we don't have a proper buffered reader yet, and I don't want to write another disgusting hack like BufStream, we just use a state machine to figure out how much we can read. Sounds bad, but in practice it works just fine since loader's response patterns are very simple.
* loader: remove applyHeadersbptato2024-03-121-38/+4
| | | | | | | Better compute the values we need on-demand at the call sites; this way, we can pass through content type attributes to mailcap too. (Also, remove a bug where applyResponse was called twice.)
* loader: unregister input streams on EOFbptato2024-03-121-2/+2
| | | | if recvData returns 0, it must be treated the same as a broken pipe.
* loader: rework process modelbptato2024-03-111-286/+475
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally we had several loader processes so that the loader did not need asynchronity for loading several buffers at once. Since then, the scope of what loader does has been reduced significantly, and with that loader has become mostly asynchronous. This patch finishes the above work as follows: * We only fork a single loader process for the browser. It is a waste of resources to do otherwise, and would have made future work on a download manager very difficult. * loader becomes (almost) fully async. Now the only sync part is a) processing commands and b) waiting for clients to consume responses. b) is a bit more problematic than a), but should not cause problems unless some other horrible bug exists in a client. (TODO: make it fully async.) This gives us a noticable improvement in CSS loading speed, since all resources can now be queried at once (even before the previous ones are connected). * Buffers now only get processes when the *connection* is finished. So headers, status code, etc. are handled by the client, and the buffer is forked when the loader starts streaming the response body. As a result, mailcap entries can simply dup2 the first UNIX domain socket connection as their stdin. This allows us to remove the ugly (and slow) `canredir' hack, which required us to send file handles on a tour accross the entire codebase. * The "cache" has been reworked somewhat: - Since canredir is gone, buffer-level requests usually start in a suspended state, and are explicitly resumed only after the client could decide whether it wants to cache the response. - Instead of a flag on Request and the URL as the cache key, we now use a global counter and the special `cache:' scheme. * misc fixes: referer_from is now actually respected by buffers (not just the pager), load info display should work slightly better, etc.
* loader: fix crash on cha </dev/nullbptato2024-03-031-1/+3
| | | | | | | | | not a very useful operation, but crashing on it is definitely not the correct reaction (hyperfine does this for example. though in that case it's still better to turn it off, otherwise Chawan will pointlessly open a new buffer for it...)
* loader: fix early return in handleReadbptato2024-02-271-30/+28
| | | | | | | | Ensure that a) dead outputs do not continue to get more data from istream and b) if all outputs are dead, istream is immediately closed. Also, remove that pointless loop in loadStreamRegular (it did nothing that handleRead did not).
* loader: clean up regular file loadingbptato2024-02-261-104/+98
| | | | | | | | | | | | | | | | | | | | * Get rid of sostream hack This is no longer needed, and was in fact causing loadStream to get stuck with redirects on regular files (i.e. the common case of receiving <file on stdin without a -T content type override). * Unify loading from cache and stdin regular file code paths Until now, loadFromCache was completely sync. This is not a huge problem, but it's better to make it async *and* not have two separate procedures for reading regular files. (In fact, loadFromCache had *another* bug related to its output fd not being added to outputMap.) * Extra: remove ansi2html select error handling It was broken, because it didn't handle read events before the error. Also unnecessary, since recvData breaks from the loop on n == 0.
* buffer: fix rewind with mailcap entriesbptato2024-02-251-0/+16
| | | | | | | | Cache mailcap entry output too, then delete it when the buffer can no longer read from it. (Maybe it would be useful to instead preserve it and allow viewSource for HTML output too? Hmm.)
* loader: only add output fd to outputMap map in addFdbptato2024-02-241-3/+4
| | | | | | | | It is a very bad idea to add it before that, because it could be closed for various reasons without being removed from the map. More concretely, this was causing ghost ostream fds to block istream selects in some cases.
* buffer: improve cancel, use _exit, misc cleanupsbptato2024-02-231-3/+3
| | | | | | * cancel resources on cancel() call * call _exit in signal handler (also in loader) * misc cleanups
* Replace Chakasu with Chagashibptato2024-02-221-1/+1
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* so close!bptato2024-02-151-5/+7
| | | | but I forgot to ensure the output stream gets closed. :(