about summary refs log tree commit diff stats
path: root/src/utils
Commit message (Collapse)AuthorAgeFilesLines
* twtstr: fix skipBlanksTillLFbptato2024-12-121-1/+1
|
* twtstr: reduce copying in atobbptato2024-12-121-4/+6
|
* pager, mailcap: misc fixes, add prompt for global mailcapbptato2024-12-111-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | In the past, Chawan would read global mailcap (/etc/mailcap, ...) too, but every now and then that would run entries that I didn't even know existed and definitely didn't intend to run. So I changed it to only use ~/.mailcap, but this meant users now had to add mailcap entries for every single mime type. At some point I also changed application/octet-stream to always save to disk, which is usually nice except when a text file is misrecognized as binary. Often times I just want to decide myself what to do. So now there are two layers. First, the global mailcap files (path as per RFC) prompt before executing. Then there is ~/.chawan/auto.mailcap (or ~/.config/chawan/auto.mailcap) which runs entries automatically. If you press shift before selecting an option in the prompt, the corresponding entry gets copied to auto.mailcap. It's also possible to type a new entry on the fly. Overall I think it's quite convenient. One unfortunate side effect is that existing users will have to migrate their entries to auto.mailcap, or redefine external.auto-mailcap to e.g. ~/.mailcap, but this seems acceptable.
* twtstr: small cleanupbptato2024-12-111-9/+7
|
* Fix casingbptato2024-12-051-1/+1
|
* mimetypes: refactor, use mime.types for inline image extensionsbptato2024-12-052-46/+18
| | | | | | | | | | | | * remove std/streams use from mime.types; mmap and parse directly * use mime.types for inline image extensions * add some jpeg file extensions Latter came up because I was trying to add a format locally and it wouldn't recognize it on images from my file system (i.e. by extension). As a security measure we still do not allow additional extensions for predefined inline image types.
* twtstr: add mypairsbptato2024-11-281-0/+9
| | | | | This couldn't get into system.nim for technical reasons, but it's still pretty useful when iterating over non-mutable openArrays.
* twtstr: beforeLast -> untilLastbptato2024-11-151-2/+2
| | | | for consistency
* chaseccomp: update docs, remove redundant importbptato2024-11-071-2/+0
|
* luwrap: fix compilation on 2.0.8 and refactor a bitbptato2024-11-053-9/+11
| | | | ref. https://todo.sr.ht/~bptato/chawan/21
* utils, types: merge some modulesbptato2024-11-038-116/+113
| | | | | * line, vector, matrix -> path * twtuni, charcategory -> twtstr
* chaseccomp: fix compilation with newest dash, misc changesbptato2024-10-311-3/+0
| | | | | | | | | | | | | | * fix matching on unstripped whitespace: caught after upgrading to upstream dash & chaseccomp wouldn't compile * add defines to ensure that we computed the filter length correctly * inline cut_label * EPERM on sigaction, sigprocmask, gettid, and kill on tgkill (so a crash doesn't trigger sandbox violations) * move SIGSYS handler to C and add one for the network The last change removes the stack trace from SIGSYS, but gives us the syscall number which is probably more useful. (Indeed, we don't even have a stack trace in release builds.)
* config: refactor, accept more possible config dirsbptato2024-10-281-0/+6
| | | | | | | | | | | | | | | | | | | | | I'm starting to favor dotfiles over XDG basedirs, but there's no reason why we couldn't have both. So now the search path is: 0. if config was set through -C, use that 1. $CHA_CONFIG_DIR is set -> $CHA_CONFIG_DIR/config.toml 2. $XDG_CONFIG_HOME is set -> $XDG_CONFIG_HOME/chawan/config.toml 3. ~/.config/chawan/config.toml exists -> use that 4. ~/.chawan/config.toml exists -> use that Notably, this makes it so the default directory is ~/.chawan *if* you don't have an existing config.toml file. So in that case known_hosts will be placed in ~/.chawan/known_hosts. However, configurations with a config in ~/.config/chawan/config.toml continue to work as expected, as for those the known_hosts file remains inside ~/.config/chawan/. Finally, I've added a default user CGI directory to reduce friction in setting CGI up. (Like known_hosts, it's also relative to whatever config dir you have.)
* sandbox: use relative path to the object filebptato2024-10-231-1/+6
|
* sandbox: replace libseccomp with chaseccompbptato2024-10-231-176/+29
| | | | | | | | | | | | | | | This drops libseccomp as a dependency. Also, move the capsicum/pledge definitions from bindings to sandbox.nim because they are only used there. Interestingly, after integrating chaseccomp I found that the stbi process would mysteriously crash by a getrandom(2) syscall. Closer investigation revealed it is only called on the initialization of glibc's malloc; presumably it had never surfaced before because libseccomp would always allocate before entering the sandbox. So I've added getrandom to our filter as well.
* dynstream, serversocket: use posix instead of nativesocketsbptato2024-10-201-3/+3
| | | | | | | | | | | nativesockets is a wrapper over posix and winapi, but we don't support winapi, so we can just fall back to PosixStream instead. SocketStream remains as a constraint over PosixStream to allow sendFileHandle/recvFileHandle. As a nice side effect, we can drop some allowed syscalls from the seccomp filter.
* sandbox: do not ask for signal permissionsbptato2024-10-171-3/+0
| | | | | On a second thought, no timeouts for name resolution is fine - and even if it weren't, it's better implemented in the loader.
* twtstr, toml: misc cleanupbptato2024-10-131-0/+3
| | | | | * remove unused DateTime toml type * add parseIntP for pointer-size int parsing
* base64: merge into twtstr/envbptato2024-10-131-0/+41
|
* layout, pager: preserve tabs on display, selection & outputbptato2024-10-101-0/+43
| | | | | | | | | | | | Substitute tabs with one of eight PUA characters based on their width, and convert them back in the pager: * TUI mode always prints spaces, but now handles tabs appropriately on cursor movement * dump mode tries to preserve hard tabs, but uses soft tabs when that is not possible (e.g. tabs after a margin, tab with background color, etc) * selection mode always outputs hard tabs.
* twtstr: fix stripAndCollapsebptato2024-10-081-11/+9
|
* twtstr: misc refactoringsbptato2024-10-011-3/+3
|
* sandbox: allow clock_gettime64bptato2024-09-301-1/+2
| | | | used on 32-bit platforms
* Update monouchabptato2024-09-291-0/+1
| | | | | Now we use QuickJS-NG, which is better maintained than QJS and has column tracking.
* container: fix control char displaybptato2024-09-281-20/+1
| | | | | | Also, kill twidth and its friends; we haven't been using it for a while now. (In the future, a solution with PUA chars might be worth exploring.)
* sandbox: allow restart_syscallbptato2024-09-271-1/+3
| | | | required for poll
* Replace std/selectors with pollbptato2024-09-231-11/+2
| | | | | | | | | | | | 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).
* term: refactorbptato2024-09-231-0/+3
| | | | | * reduce copies & allocations * simplify SGR generation
* twtstr: simplify integer parsingbptato2024-09-211-86/+65
| | | | | | * simplify uint parser * use uint parser for signed ints too (to simplify overflow handling) * use openArray[char] where possible
* sandbox: always allow epoll_pwaitbptato2024-09-151-1/+1
| | | | looks like it's also necessary for musl
* sandbox: stricter fcntl policybptato2024-09-141-4/+17
| | | | fcntl has some cursed commands that we really don't want to allow
* twtuni: correct behavior on failed bounds checkbptato2024-09-081-11/+11
| | | | Make sure U+FFFD is returned when a bounds check fails.
* utils: add twtunibptato2024-09-086-166/+226
| | | | | | | | | | | | | | | | | | | std/unicode has the following issues: * Rune is an int32, which implies overflow checking. Also, it is distinct, so you have to convert it manually to do arithmetic. * QJS libunicode and Chagashi work with uint32, interfacing with these required pointless type conversions. * fastRuneAt is a template, meaning it's pasted into every call site. Also, it decodes to UCS-4, so it generates two branches that aren't even used. Overall this lead to quite some code bloat. * fastRuneAt and lastRune have frustratingly different interfaces. Writing code to handle both cases is error prone. * On older Nim versions which we still support, std/unicode takes strings, not openArray[char]'s. Replace it with "twtuni", which includes some improved versions of the few procedures from std/unicode that we actually use.
* Fix 1.6.14 compilationbptato2024-09-072-2/+30
| | | | | Wait, why does std fastRuneAt try to decode UCS-32? Hmm...
* md2html: code, pre, inline fixesbptato2024-09-072-3/+3
|
* sandbox: allow futex in network/buffer sandboxbptato2024-09-061-1/+2
| | | | | WSL needs it. It was already allowed on Android, so this just makes the sandboxes converge a little.
* twtstr: type erase binarySearch instantiationbptato2024-09-062-33/+43
| | | | | | | | Do it like parseEnumNoCase0, so we no longer instantiate a gazillion different binary searches for the same type. While we're at it, make matchNameProduction's searchInMap use uint32 too.
* sixel, stbi, sandbox: fix fstat sandbox violationbptato2024-09-041-2/+23
| | | | | | | Until recently, glibc used to implement it as fstatat. So don't trap for fstatat (and for consistency, fstat), but return EPERM. Just to be sure, rewrite sixel & stbi to never call fread.
* xhr: progressbptato2024-08-131-0/+2
| | | | | | | | | | | | | * 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
* dom: remove generic JS bindingsbptato2024-08-111-2/+1
| | | | Dispatch manually with fromJS instead.
* dom: fix crash on wrong image content typebptato2024-08-111-0/+3
| | | | + slightly optimize getContentType
* twtstr: don't cast in parseEnumbptato2024-08-091-2/+2
| | | | Nim 1.6 does not like it.
* sandbox: allow ugetrlimitbptato2024-08-091-0/+1
| | | | called on armhf
* Update monouchabptato2024-08-091-6/+5
|
* endians: removebptato2024-08-031-39/+0
| | | | was only used by the PNG decoder which got replaced by stbi
* cssvalues, twtstr, mediaquery: refactor & fixesbptato2024-08-021-28/+25
| | | | | | | * cssvalues, twtstr: unify enum parsing code paths, parse enums by bisearch instead of hash tables * mediaquery: refactor (long overdue), fix range comparison syntax parsing, make ident comparisons case-insensitive (as they should be)
* twtstr: fix startsWithIgnoreCasebptato2024-07-291-2/+2
|
* buffer, pager, config: add meta-refresh + misc fixesbptato2024-07-281-18/+12
| | | | | | | | | * buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
* url: misc fixes & improvementsbptato2024-07-241-25/+13
| | | | | | * fix various parsing bugs * rewrite state machine * other small optimizations
* client, sandbox: fix termux buildbptato2024-07-241-3/+51
| | | | | Still not perfect, because it crashes on missing /tmp dir so you have to manually set it...