Commit Graph

1002 Commits

Author SHA1 Message Date
Timothy Flynn
1f44c9468a LibCore: Replace MIME type description lookup with a more generic method
Rather than adding a bunch of `get_*_from_mime_type` functions, add just
one to get the Core::MimeType instance. We will need multiple fields at
once in Browser.
2024-03-16 08:42:33 +01:00
Timothy Flynn
a973fe13cb LibCore: Use Core::System::pipe2 for creating the event loops waking FDs 2024-03-13 12:52:07 -04:00
Timothy Flynn
40beebca71 LibCore: Apply the flags provided to System::pipe2 on all systems
We currently drop the flags on the floor for systems that do not have a
pipe2 syscall. Instead, use fcntl to set the flags.
2024-03-13 12:52:07 -04:00
Nico Weber
58838db445 LibGfx: Add the start of a JBIG2 loader
JBIG2 is infamous for two things:

1. It's used in xerox scanners were it falsifies scanned numbers:

https://www.dkriesel.com/en/blog/2013/0802_xerox-workcentres_are_switching_written_numbers_when_scanning

2. It was allegedly used in an iOS zero day, in a very cool way:

https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-into-nso-zero-click.html

Needless to say, we need support for it in Serenity. (...because it's
used in PDF files.)

This adds all the scaffolding, but no actual implementation yet.

It's enough for `file` to print the mime type of .jb2 files, but `image`
can't do anything with the files yet.
2024-03-09 16:01:22 +01:00
Andrew Kaster
e09bfc1a8c LibCore: Recognize .mjs as a common extension for application/javascript 2024-03-06 07:19:10 +01:00
Filiph Siitam Sandström
d6ab5c9b7d LibCore: Fix AK_OS_ANDROID build
b9dc2d7 accidentally broke Android builds, this fixes that regression.
2024-03-04 07:55:39 +00:00
Filiph Siitam Sandström
fd694e8672 AK+Lagom: Make it possible to build for iOS
This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
https://discord.com/channels/830522505605283862/830525031720943627/1211987732646068314
2024-03-03 13:13:42 -07:00
Shannon Booth
abf35f5bd6 LibCore: Support Optional<StringView> as an argument to ArgsParser
While StringView does have a null state, we have been moving away from
this in our other String classes. To represent a StringView not being
given at all on the commandline, use an Optional.
2024-03-03 08:56:00 +01:00
Sam Atkins
c2bc07ef7c LibCore: Use Core::Environment::raw_environ() instead of environment() 2024-02-27 08:33:48 +00:00
Sam Atkins
97cb9cf469 LibCore: Use Core::Environment instead of manually iterating environ 2024-02-27 08:33:48 +00:00
Sam Atkins
56b8e248a5 LibCore: Remove now-unused Core::System::*env() functions
These have been moved to Core::Environment.
2024-02-27 08:33:48 +00:00
Sam Atkins
b9dc2d7ebf LibCore: Introduce Core::Environment wrapper
Core::System already had some wrappers for *env() functions, which I've
copied over. But 1) the set of functions there was incomplete, and 2)
the environment feels like an object in its own right, so let's treat it
as one. :^)

Also add `Core::Environment::has(StringView)` for situations where we
just care if a variable is defined.
2024-02-27 08:33:48 +00:00
Tim Ledbetter
679fe00d10 LibCore+Utilities: Replace ElapsedTimer precise flag with an enum
Previously, `true` was passed into the ElapsedTimer constructor if a
precise timer was required. We now use an enum to more explicitly
specify whether we would like a precise or a coarse timer.
2024-02-26 16:12:20 -07:00
Dan Klishch
120d6b2f21 LibCore: Decouple handling of timers and waiting for events
This introduces a new TimeoutSet class for use in
EventLoopImplementationUnix. It is responsible for finding a timer that
expires the soonest and for firing expired timers. TimeoutSet expects
timeouts to be subclasses of EventLoopTimeout, of which EventLoopTimer
is now a subclass, obviously.

TimeoutSet stores timeouts in a binary heap, so
EventLoopImplementationUnix should handle large amounts of timers a lot
better now.

TimeoutSet also supports scheduling of timeouts whose fire time is
relative to the start of the next event loop iteration (i. e. ones
that directly bound polling time). This functionality will reveal its
full potential later with the implementation of asynchronous sockets but
it is currently used to implement zero-timeout timers that are an analog
of Core::deferred_invoke with slightly different semantics.
2024-02-25 17:24:36 -07:00
Dan Klishch
b77996884e LibCore+Ladybird: Don't force timer ids to be integer just to remap them
If we don't force event loop to fit timer id into integer, we can
eliminate awkward IDAllocator inside EventLoopImplementations.
2024-02-25 17:24:36 -07:00
Dan Klishch
bed4af6fef LibCore+Ladybird: Make unregistering timer infallible
Let's force calling code to provide valid timer ids. No code changes are
required since, surprise, nobody used this obscure functionality.
2024-02-25 17:24:36 -07:00
Dan Klishch
21097d1c9e LibCore+Ladybird: Don't store timer_id in Core::TimerEvent 2024-02-25 17:24:36 -07:00
Tim Ledbetter
4a7236cabf Everywhere: Prefer _string when constructing strings from literals 2024-02-08 11:01:10 -05:00
mobounya
7326d00baa RequestServer: Avoid using gethostbyname
Replace gethostbyname with Core::Socket::resolve_host in
RequestServer::ConnectionFromClient::ensure_connection.

Resolved #22199.
2024-02-06 21:43:23 +01:00
Bastiaan van der Plaat
c8dc77a552 LibCore: Add Music, Pictures and Videos user directory helpers 2024-02-05 16:30:52 +01:00
Dan Klishch
506707cc2b LibCore: Allow listening for socket errors and hang-ups 2024-02-03 16:43:13 -07:00
Dan Klishch
6836091a21 LibCore: Switch from select(2) to poll(2) for the event loop 2024-02-03 16:43:13 -07:00
Dan Klishch
77e4f0d7d8 LibCore: Allow listening for multiple conditions using a single Notifier
While on it, implement currently unused Notifier::set_type correctly
(but not efficiently) by re-registering Notifier in the EventLoop.
2024-02-03 16:43:13 -07:00
Kyle Lanmon
05b30ece17 LibCore: Add DateTime parser for milliseconds 2024-02-03 09:29:40 +01:00
Kyle Lanmon
f7efbba32d LibCore: Add parser for time offset without a sign
There is already a parser for the time offset but it requires a positive
or negative sign. There are some weird formats on the web that do not
have the sign, so let's support that. I chose to implement this as a new
option instead of editing the old one to avoid any unknown breaking
changes.
2024-02-03 09:29:40 +01:00
Ollrogge
f784122703 LibCore: Refactor template definitions to header in ArgsParser
This allows for automatic template instatiation and remove the need to
explicitly instantiate the template functions for different types.
2024-01-29 13:58:37 +00:00
Nico Weber
187862ebe0 LibGfx: Add a .pam loader
.pam is a "portrable arbitrarymap" as documented at
https://netpbm.sourceforge.net/doc/pam.html

It's very similar to .pbm, .pgm, and .ppm, so this uses the
PortableImageMapLoader framework. The header is slightly different,
so this has a custom header parsing function.

Also, .pam only exixts in binary form, so the ascii form support
becomes optional.
2024-01-26 07:36:53 +01:00
Ali Mohammad Pur
4f6c9f410c AK+LibCore: Add BufferedSocket::can_read_up_to_delimiter()
This method (unlike can_read_line) ensures that the delimiter is present
in the buffer, and doesn't return true after eof when the delimiter is
absent.
2024-01-21 21:13:58 +01:00
Sam Atkins
071f7fd818 LibCore+JSSpecCompiler: Add option for Process::spawn() to use spawnp()
Add a boolean to ProcessSpawnOptions, `search_for_executable_in_path`,
which when true, calls into posix_spawnp() instead of posix_spawn().
This defaults to false to maintain the existing behavior.

The `path` field is renamed to `executable` because having two fields
refer to "path" and mean different things seemed unnecessarily
confusing.
2024-01-19 12:16:21 -07:00
Liav A
603516e8c0 LibCore: Add new flag for DirIterator to not use fstatat
This will be useful in the upcoming listdir utility (in the next commit)
to get the file type which is obtained in the get_dir_entries syscall,
so it's not changed later by the fstatat syscall.

This will ensure that we get the raw file type value as it's represented
by directory entries from the get_dir_entries syscall.
2024-01-13 19:01:07 -07:00
Liav A
d568b09632 LibCore: Add methods to convert DirectoryEntry types to names
We can either convert DirectoryEntry::type to its representative name or
to the POSIX DT_* name.
2024-01-13 19:01:07 -07:00
implicitfield
20aa56891a LibCore: Avoid running fstatat on skipped entries in DirIterator
Fixes #22630
2024-01-12 16:21:28 -07:00
Lucas CHOLLET
4c23f0e142 LibCore: Log a message before failure in EventLoop::current()
If no EventLoop is present in the stack (like when you forget to create
one), a message is nicer than letting the developer go through the
stacktrace to figure out what went wrong.
2024-01-07 20:10:22 +01:00
david072
df3e6174b6 LibCore/DateTime: Add more binary operators 2024-01-06 10:37:53 -07:00
david072
985db495be LibCore/DateTime: Add helper for setting only the date from another date 2024-01-06 10:37:53 -07:00
david072
251e5fb074 LibCore/DateTime: Add a helper for setting the time individually 2024-01-06 10:37:53 -07:00
implicitfield
7c9ca8baab LibCore: Fall back to fstat if readdir doesn't produce a valid file type
Per POSIX, It is valid for dirent structures obtained via readdir to
not name a valid type.
2024-01-05 04:00:11 +03:30
Timothy Flynn
c190294a76 LibCore: Fix compilation of infallible Promise::when_resolved handlers
This overload is currently unused. When used, it doesn't compile due to
mismatched return types in the handler provided to the function and the
type of `on_resolution`.
2024-01-01 10:11:45 +01:00
Andrew Kaster
0c025c7d7e LibCore: Default to a temp directory for runtime directory on non-Linux
/run/user/$uid is a systemd-ism, and is not present on other platforms.
2023-12-29 09:46:50 +01:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Torstennator
38974b4128 LibCore: Allow widgets to reparent 2023-12-14 09:07:20 -07:00
Andrew Kaster
d253beb2f7 LibCore: Don't leak proto-Resources when loading non-existent paths
The construct `adopt_ref(*new Obj(TRY(get_resource())))` is another
manifestation of a classic anti-pattern. In old C++, you would leak the
object's memory if the argument threw an exception, or if a member
initializer threw an exception. In our case, we leak if the MappedFile
returns an Error. This is pretty concerning, and we should avoid this
pattern at all costs, and try to use the "safer" helpers whenever
possible.
2023-12-13 17:28:07 -05:00
Nicolas Ramz
cd6c7f3fc4 LibGfx/ILBMLoader: Add support for PC DeluxePaint files 2023-12-13 10:39:13 +00:00
Dan Klishch
b7259ab38c LibCore: Support POSIX file actions in Core::Process::spawn 2023-12-07 10:13:21 -07:00
Dan Klishch
d317309d89 Everywhere: Unport Core::System::current_executable_path from new string
Storing paths in AK::String is never correct.
2023-12-07 10:13:21 -07:00
Ali Mohammad Pur
7edc69dc94 LibCore: Ignore non-S_IFMT bits in directory_entry_type_from_stat
The st_mode field in struct stat is a bitfield of more than just the
file type, this commit masks off the non-filetype bits to ensure no
unrelated bits are checked.
2023-12-01 20:46:16 +01:00
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
Lucas CHOLLET
b00476abac AK: Use an enum to specify the open mode instead of a bool
Let's replace this bool with an `enum class` in order to enhance
readability. This is done by repurposing `MappedFile`'s `OpenMode` into
a shared `enum` simply called `Mode`.
2023-11-08 18:19:34 +01:00
Timothy Flynn
ee7ab5d053 LibCore: Support wildcard-skipping characters in Core::DateTime::parse
For example, LibJS will need to parse date strings of the form:

    Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time)

This string contains both the time zone offset (-05:00) and a display
name for the time zone (Eastern Standard Time). Because we will already
handle time zone adjustments when we handle the offsets, we will want to
just skip the time zone name. This patch will let us use a format string
of the form "GMT%z (%+)" to do so.
2023-11-08 09:28:17 +01:00