about summary refs log tree commit diff stats
path: root/src/server
Commit message (Collapse)AuthorAgeFilesLines
* sandbox: add OpenBSD pledge/unveil supportbptato2024-04-032-5/+7
| | | | | | | | | | | | pledge is a bit more fine-grained than Capsicum's capability mode, so the buffer & http ("network") sandboxes are now split up into two parts. I applied the same hack as in FreeBSD for overriding the buffer selector kqueue, because a) I didn't want to request sysctl promise b) I'm not sure if it would even work and c) if it breaks on OpenBSD, then it's broken on FreeBSD too, so there's a greater chance of discovering the bug.
* buffer: fix markURL in plaintextbptato2024-03-291-3/+31
| | | | | | | We must HTML escape data, or the fragment parser will parse plain text as markup. (However, just running htmlEscape() on data is not enough; that would also mark <, ', etc. as &gt, &apos. So we only escape after the regex is executed.)
* fflush() before forksbptato2024-03-281-0/+6
| | | | | seems like a good idea, especially because CGI uses stdout as the IPC mechanism
* Add capsicum supportbptato2024-03-282-13/+40
| | | | | | | | | | | | | 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-12/+20
| | | | | | | | | | * 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
* buffer: fix getTitle never returning in some casesbptato2024-03-241-0/+2
|
* client, forkserver: remove useless codebptato2024-03-241-1/+0
|
* js: proper distinction between Opt/Optionbptato2024-03-241-6/+6
| | | | | | | | | | | | | | | | 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.
* buffer: fix clonebptato2024-03-241-7/+8
|
* io: derive DynStream from RootObj (not Stream)bptato2024-03-242-65/+53
| | | | | | | | 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.)
* bufreader: add initPacketReaderbptato2024-03-241-3/+1
|
* buffer: form fixes & improvementsbptato2024-03-241-45/+72
| | | | | | | * fall back to text for unimplemented input types * add custom prompt to all text-like input types * show min/max for range * fix accidental override of repaint
* io: add bufreaderbptato2024-03-212-66/+56
| | | | analogous to bufwriter
* catom: at -> satbptato2024-03-211-8/+8
| | | | just for consistency
* buffer: send title during load + other title stuffbptato2024-03-211-7/+20
| | | | | | | * send title to pager as soon as it's available * expose `title' to DOM * rename undocumented `getTitle' js function to `title' getter in Container
* buffer: also buffer input readsbptato2024-03-211-38/+49
| | | | this is buffer reading from pager
* buffer: also buffer reads for packetsbptato2024-03-201-12/+16
| | | | | Since we know the length of packets, we can also read them in in one call. Though I really wish we could do this without the StringStream.
* buffer: add markURLbptato2024-03-191-2/+44
| | | | Useful when browsing plaintext files; w3m has it too.
* Move SIGCHLD ignore call to forkserverbptato2024-03-171-0/+1
| | | | seems like it confuses popen()
* forkserver: set process titles for processesbptato2024-03-171-0/+4
| | | | | this is unfortunately truncated on Linux, but I don't care enough to hack around this
* io: add BuferedWriterbptato2024-03-162-41/+53
| | | | | | | | | | 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
* Clean up BufferConfigbptato2024-03-151-0/+9
| | | | | | | | 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.
* Move around some modulesbptato2024-03-142-3/+3
| | | | | | | | * 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
* rudimentary support for <video>, <audio>bptato2024-03-131-7/+22
| | | | | we just treat them as img tags. lazy, but works suprisingly well -- so long as the server sends us a Content-Type, anyway.
* loader: rework process modelbptato2024-03-112-282/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* buffer: fix bug of eating chars before invalid UTF-8bptato2024-03-051-2/+2
| | | | | | | using this API is suffering (`n' is the last *valid* character ever since the validator API got fixed, so it must be included in the slice.)
* strwidth, renderdocument: small refactoringbptato2024-03-031-1/+1
| | | | | | * put attrs pointer in state * simplify width() * use unsigned int as ptint to avoid UB
* buffer: improve/fix onload return valuesbptato2024-03-031-6/+12
| | | | | | | | | Only report when bytesRead has changed, otherwise we get unnecessary load requests. (This means -2 return value no longer exists; it did not work correctly anyway.) Also, fix the race condition that broke onload returns when onload happened before client requested load.
* buffer: do not incrementally display in headless modebptato2024-03-021-3/+4
|
* buffer, client: fix deadlock with send() callsbptato2024-02-291-13/+20
| | | | | | | | | | This is an ancient bug, but it got much easier to trigger with mouse scrolling support so it's time to fix it. (The bug itself was that since both the client and buffer ends of the controlling stream are blocking, they could get stuck when both were trying to send() data to the other end but the buffer was full. So now we set the client end to non-blocking.)
* buffer: add image viewer supportbptato2024-02-271-22/+39
|
* misc refactoringsbptato2024-02-271-19/+18
| | | | | | * rename buffer enums * fix isAscii for char 0x80 * remove dead code from URL
* buffer: reset prevStyled in switchCharset, reshapebptato2024-02-271-3/+5
| | | | | | | | reshape must do a render from zero, as it's a last resort for users to fixup the page on a rendering bug. switchCharset must reset prevStyled for obvious reasons (it refers to a dead document).
* buffer: clean up onload, fix console updatebptato2024-02-261-17/+11
| | | | | | | | | | | | * reduce onload result size to a single int * clean up mess that was the container onload handler This fixes automatic refresh in console. Before, the client would only request a screen update after receiving the number of bytes read, but before the screen was actually reshaped (which obviously resulted in a race condition). Now, "I've reshaped the document" is a separate response (and is the only occasion where the screen is updated before the final render).
* term: improve pixels-per-column/line detectionbptato2024-02-252-2/+2
| | | | | | | | | Some terminal emulators (AKA vte) refuse to set ws_xpixel and ws_ypixel in the TIOCGWINSZ ioctl, so we now query for CSI 14 t as well. (Also CSI 18 t for good measure, just in case we can't ioctl for some reason.) Also added some fallback (optionally forced) config values for width, height, ppc, and ppl. (This is especially useful in dump mode.)
* buffer: remove incorrect assertionsbptato2024-02-251-3/+0
| | | | | `confidence' becomes ccCertain when PRES_STOP is returned, so asserting the opposite is incorrect (and was resulting in crashes).
* buffer: fix rewind with mailcap entriesbptato2024-02-251-5/+11
| | | | | | | | 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.)
* Separate ANSI text decoding from main binarybptato2024-02-251-77/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handling text/plain as ANSI colored text was problematic for two reasons: * You couldn't actually look at the real source of HTML pages or text files that used ANSI colors in the source. In general, I only want ANSI colors when piping something into my pager, not when viewing any random file. * More importantly, it introduced a separate rendering mode for plaintext documents, which resulted in the problem that only some buffers had DOMs. This made it impossible to add functionality that would operate on the buffer's DOM, to e.g. implement w3m's MARK_URL. Also, it locked us into the horribly inefficient line-based rendering model of entire documents. Now we solve the problem in two separate parts: * text/x-ansi is used automatically for documents received through stdin. A text/x-ansi handler ansi2html converts ANSI formatting to HTML. text/x-ansi is also used for .ans, .asc file extensions. * text/plain is a separate input mode in buffer, which places all text in a single <plaintext> tag. Crucially, this does not invoke the HTML parser; that would eat NUL characters, which we should avoid. One blind spot still remains: copiousoutput used to display ANSI colors, and now it doesn't. To solve this, users can put the x-ansioutput extension field to their mailcap entries, which behaves like x-htmloutput except it first pipes the output into ansi2html.
* buffer: improve cancel, use _exit, misc cleanupsbptato2024-02-231-44/+53
| | | | | | * cancel resources on cancel() call * call _exit in signal handler (also in loader) * misc cleanups
* buffer: remove BufferSourcebptato2024-02-222-61/+65
| | | | | | | | | | Aside from being a wrapper of Request, it was just storing the -I charset, except even that didn't actually work. Whoops. This fixes -I effectively not doing anything; now it's a forced override that even disables BOM sniffing. (If the user wants to decode a file using a certain encoding, it seems wise to assume that they really meant it.)
* buffer: clean up contentTypebptato2024-02-221-18/+4
| | | | | | | | | | This fixes a bug where setContentType would call setHTML twice, which messed up charsets and probably a couple more things. As a bonus, it allows us to pass around the content type less. In fact, buffer does not have to know its exact content type, just whether it is in HTML mode or not. So that's all we tell it now; only container still keeps track of the content type (as it should).
* Replace Chakasu with Chagashibptato2024-02-221-55/+153
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* buffer: fix broken jump-to-anchorbptato2024-02-181-1/+1
| | | | | source.request.url is not used after buffer initialization (because it may be replaced later), so we must set buffer.url instead.
* layout: use html/body bgcolor as canvas bgcolorbptato2024-02-171-17/+11
| | | | | | This is required by the standard. (Without this, lots of websites have incorrect background colors, because they set the body height to 100% of the viewport.)
* Various refactorings & fixesbptato2024-02-142-29/+23
| | | | | | | | * 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
* buffer: improve style invalidationbptato2024-02-141-5/+5
|
* buffer: fix regression on htmloutput document baseURLbptato2024-02-141-3/+2
| | | | | readFromFd replacing the base URL of the buffer turns out to be a very bad idea.
* buffer: skip rewind after the first readbptato2024-02-131-7/+17
| | | | | Speeds up processing of pretty much all documents, because we rarely need to switch the charset after having downloaded the first chunk.
* loader: fix delOutput bug, remove ErrorWouldBlockbptato2024-02-131-4/+4
|
* loader: fixes & improvementsbptato2024-02-131-21/+18
| | | | | | | | * 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