summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWebSocket
AgeCommit message (Collapse)Author
2022-09-29AK+Everywhere: Replace "protocol" with "scheme" url helpersnetworkException
URL had properly named replacements for protocol(), set_protocol() and create_with_file_protocol() already. This patch removes these function and updates all call sites to use the functions named according to the specification. See https://url.spec.whatwg.org/#concept-url-scheme
2022-07-12Everywhere: Replace single-char StringView op. arguments with charssin-ack
This prevents us from needing a sv suffix, and potentially reduces the need to run generic code for a single character (as contains, starts_with, ends_with etc. for a char will be just a length and equality check). No functional changes.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-04-16LibCore+Everywhere: Make Core::Stream read_line() return StringViewSam Atkins
Similar reasoning to making Core::Stream::read() return Bytes, except that every user of read_line() creates a StringView from the result, so let's just return one right away.
2022-04-16LibCore+Everywhere: Make Core::Stream::read() return BytesSam Atkins
A mistake I've repeatedly made is along these lines: ```c++ auto nread = TRY(source_file->read(buffer)); TRY(destination_file->write(buffer)); ``` It's a little clunky to have to create a Bytes or StringView from the buffer's data pointer and the nread, and easy to forget and just use the buffer. So, this patch changes the read() function to return a Bytes of the data that were just read. The other read_foo() methods will be modified in the same way in subsequent commits. Fixes #13687
2022-03-13Libraries: Use default constructors/destructors in LibWebSocketLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-10LibWebSocket: Add to the total read in bytes instead of subtractingLuke Wilde
read_length in WebSocket::read_frame is used to track how many bytes we have read in from the network. However, we was subtracting the number of read in bytes instead of adding, underflowing it to about the 64-bit unsigned integer limit. This effectively limited us to only doing one read from the network. This was only an issue if the server stalled when sending data, which is especially common for large payloads. This would also cause us to go out of sync. This meant when a new frame came in, we would read the payload data of the previous frame as if it was the frame header and payload of the next frame. This allows us to read in the initial payload from Discord Gateway that describes to the client the servers we are in, the emotes the server has, the channels it has, etc. For an account that's only in the Serenity Discord, this was about 20 KB (compressed!)
2022-02-12LibWebSocket: Don't try to send empty payload inside of frameDerpyCrabs
According to RFC 6455 sections 5.5.2-5.5.3 Ping and Pong frames can have empty "Application data" that means payload can be of size 0. This change fixes failed "buffer.size()" assertion inside of Core::Stream::write_or_error by not trying to send empty payload in WebSocket::send_frame.
2022-02-06LibCore+Userland: Remove Core::TCPSocket :^)sin-ack
This was deprecated in favor of Core::Stream::TCPSocket, and now has no users.
2022-02-06LibWebSocket: Switch to using Core::StreamAli Mohammad Pur
As LibTLS now supports the Core::Stream APIs, we can get rid of the split paths for TCP/TLS and significantly simplify the code as well. Provided to you free of charge by the Core::Stream-ification team :^)
2022-02-06Userland: Convert TLS::TLSv12 to a Core::Stream::SocketAli Mohammad Pur
This commit converts TLS::TLSv12 to a Core::Stream object, and in the process allows TLS to now wrap other Core::Stream::Socket objects. As a large part of LibHTTP and LibGemini depend on LibTLS's interface, this also converts those to support Core::Stream, which leads to a simplification of LibHTTP (as there's no need to care about the underlying socket type anymore). Note that RequestServer now controls the TLS socket options, which is a better place anyway, as RS is the first receiver of the user-requested options (though this is currently not particularly useful).
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-04Userland: Resolve tautological-constant-out-of-range-compare warningsAndrew Kaster
Stop comparing platform-specific sized integer types to max() values of other interger types. Enable the warning everywhere.
2021-11-02Libraries: Fix visibility of Object-derivative constructorsBen Wiederhake
Derivatives of Core::Object should be constructed through ClassName::construct(), to avoid handling ref-counted objects with refcount zero. Fixing the visibility means that misuses like this are more difficult.
2021-10-06LibWebSocket: Add missing headers to Message.hBen Wiederhake
2021-09-19LibTLS: Use a setter for on_tls_ready_to_write with some more smartsAli Mohammad Pur
The callback should be called as soon as the connection is established, and if we actually set the callback when it already is, we expect it to be called immediately.
2021-09-18LibWebSocket: Use deferred_invoke() when discarding a connectionAndreas Kling
We don't want to destroy the WebSocketImpl while we're still using it higher up the stack. By using deferred_invoke(), we allow the stack to unwind before actually destroying any objects. This fixes an issue with the WebSocket service crashing on immediate connection failure.
2021-09-18LibWebSocket: Fix confusion about sizeof(size_t) on 64-bit platformsAndreas Kling
sizeof(size_t) is 8 on 64-bit platforms, not 64.
2021-09-18LibWebSocket: Fix a handful of clang-tidy warnings in WebSocket.{cpp,h}Andreas Kling
2021-09-14AK: Make URL::m_port an Optional<u16>, Expose raw port getterIdan Horowitz
Our current way of signalling a missing port with m_port == 0 was lacking, as 0 is a valid port number in URLs.
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-02Userland: Migrate to argument-less deferred_invokesin-ack
Only one place used this argument and it was to hold on to a strong ref for the object. Since we already do that now, there's no need to keep this argument around since this can be easily captured. This commit contains no changes.
2021-06-06AK+Everywhere: Disallow constructing Functions from incompatible typesAli Mohammad Pur
Previously, AK::Function would accept _any_ callable type, and try to call it when called, first with the given set of arguments, then with zero arguments, and if all of those failed, it would simply not call the function and **return a value-constructed Out type**. This lead to many, many, many hard to debug situations when someone forgot a `const` in their lambda argument types, and many cases of people taking zero arguments in their lambdas to ignore them. This commit reworks the Function interface to not include any such surprising behaviour, if your function instance is not callable with the declared argument set of the Function, it can simply not be assigned to that Function instance, end of story.
2021-05-18LibWebSocket: Fixed occasional infinite loop with TLS socketsDexesTTP
This was caused by a double notifier on the TLS socket, which caused the TLS code to freak out about not being able to read properly. In addition, the existing loop inside of drain_read() has been replaced by code that actually works, and which includes new warnings when the drain method is called before initialization is done or after the websocket gets closed.
2021-05-17Everywhere: Fix a bunch of typosLinus Groh
2021-04-25Services: Add a WebSocket serviceDexesTTP
The WebSocket service isolates communication with a WebSocket to its own isolated process. Similar to other isolating services, it has its own user and group.
2021-04-25LibWebSocket+telws: Use my own copyright headers :^)DexesTTP
Since I guess I'll start attributing my own code, might as well change it for the previously written WebSocket code too !
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-18LibWebSocket: Add a new websocket libraryDexesTTP
This library currently contains a basic WebSocket client that can handle both standard TCP websockets and TLS websockets.