about summary refs log tree commit diff stats
path: root/src/loader
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* fflush() before forksbptato2024-03-281-0/+2
| | | | | seems like a good idea, especially because CGI uses stdout as the IPC mechanism
* 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
* js: proper distinction between Opt/Optionbptato2024-03-242-18/+17
| | | | | | | | | | | | | | | | until now, this had very strange (and inconsistent) semantics: * err() was used for exception propagation, but also as a null value * Option accepted undefined as a none value, but not null * Opt and Option were used interchangeably (and mostly randomly) Now, Result is always used for error reporting, and err(nil) means JS_EXCEPTION. (Opt is a special case of Result where we don't care about the error type, and is not used in JS.) Option on the other hand means "nullable variation of normally non-nullable type", and translates to JS_NULL. In JS we mainly use it for turning strings nullable.
* cgi: reset SIGCHLD handler in childrenbptato2024-03-241-0/+4
| | | | this was causing problems in git.cgi
* io: derive DynStream from RootObj (not Stream)bptato2024-03-244-74/+76
| | | | | | | | 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-212-14/+23
| | | | | | | 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-212-7/+8
| | | | no reason to do it separately in setupEnv
* main: set CHA_LIBEXEC_DIR env var at startupbptato2024-03-192-10/+6
| | | | This way, we can use it everywhere (e.g. in mailcap).
* cgi: set cwd to CGI dirbptato2024-03-191-3/+7
| | | | | for w3m and real CGI compatibility; also, it makes more sense than using whatever directory the user happened to be in when starting the browser
* config: clean up/simplifybptato2024-03-172-20/+12
| | | | | | | | | * Parse the default config at runtime. There's no significant performance difference, but this makes it much less painful to write config code. * Add better error reporting * Make fromJS2 easier to use * Unquote ChaPaths while parsing config
* io: add BuferedWriterbptato2024-03-162-58/+76
| | | | | | | | | | 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.
* cgi: fix broken pipe handlingbptato2024-03-141-1/+8
| | | | | if the socket is closed before the loader could send all header data, we must destroy the parser to avoid sending a result twice.
* Move around some modulesbptato2024-03-142-2/+2
| | | | | | | | * 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-142-3/+2
| | | | | Setting istream to nil was preventing finishCycle from unregistering & closing it.
* loader: fix nil deref in parseHeadersbptato2024-03-131-1/+1
|
* client: fix blocking reads on container connectionbptato2024-03-122-29/+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-122-49/+31
| | | | | | | 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-116-440/+659
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* cgi: do not eat first word of the error messagebptato2024-03-071-1/+1
| | | | whoops
* cgi: pass system error message after execl failurebptato2024-03-071-1/+2
|
* 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...)
* cgi: fix regression in header handlingbptato2024-03-021-5/+8
| | | | it's a good idea to use the return value, but it must substitute atEnd.
* posixstream: add readLine implementationbptato2024-03-021-6/+4
| | | | | slightly more efficient, but more importantly does not choke on NUL and weird \r\n
* loader: fix early return in handleReadbptato2024-02-272-30/+29
| | | | | | | | 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-262-104/+105
| | | | | | | | | | | | | | | | | | | | * 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-253-5/+30
| | | | | | | | 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-222-11/+9
| | | | | | 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. :(
* loader: fix crash on file redirection inputsbptato2024-02-152-16/+60
| | | | | | | | cha -d <some-file was crashing loader, because it was trying to register the regular file in the selector. this patch fixes the problem, but the control flow of loader looks like spaghetti now
* Various refactorings & fixesbptato2024-02-142-68/+6
| | | | | | | | * disallow Stream interface usage on non-blocking PosixStreams * do not read estream of forkserver byte-by-byte (it's slow) * do not call writeData with a zero len in formdata * do not quote numbers in mailcap quoteFile * remove some unused stuff
* loader: fix delOutput bug, remove ErrorWouldBlockbptato2024-02-131-20/+10
|
* loader: fixes & improvementsbptato2024-02-132-121/+79
| | | | | | | | * factor out pushBuffer to make loadFromCache async * fix incorrect cache path * replace rewind with loadFromCache (it does the same thing except actually works) * remove rewindImpl callback, rewind in buffer instead
* stricter typingbptato2024-02-121-3/+4
|
* Add pager.externFilterSourcebptato2024-02-121-5/+13
| | | | useful for filtering stuff through commands like rdrview
* Remove CLONE BufferSource; cache document sources in tmpdirbptato2024-02-126-89/+197
| | | | | | | | | | | | | | | | | | | | | | | At last all BufferSources are unified. To achieve the same effect as the previous CLONE source type, we now use the "fromcache" flag in Request. This *forces* the document to be streamed from the disk; if the file no longer exists for some reason, an error is returned (i.e. the document is not re-downloaded). For a document to be cached, it has to be the main document of the buffer (i.e. no additional resources requested with fetch()), and also not an x-htmloutput HTML file (for those, the original source is saved). The result is that toggleSource now always returns the actual source for e.g. markdown files, not the HTML-transformed version. Also, it is now possible to view the source of a document that is still being downloaded. buffer.sstream has almost been eliminated; it still exists, but only as a pseudo-buffer to interface with EncoderStream and DecoderStream. It no longer holds the entire source of a buffer at any point, and is cleared as soon as the buffer is completely loaded.
* simplify newLoaderBufferbptato2024-02-111-4/+3
|