From cf3b58fbe8f836c13e44d6152d78960aff6089ef Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 May 2020 21:57:44 +0200 Subject: Services: Renamed from Servers It didn't feel right to have a "DHCPClient" in a "Servers" directory. Rename this to Services to better reflect the type of programs we'll be putting in there. --- Applications/Browser/Makefile | 6 +- Documentation/BuildInstructions.md | 2 +- Kernel/build-root-filesystem.sh | 20 +- Libraries/LibAudio/Makefile | 4 +- Libraries/LibGUI/Makefile | 10 +- Libraries/LibProtocol/Makefile | 4 +- Libraries/LibWeb/Makefile | 4 +- Makefile | 2 +- Makefile.common | 2 +- Meta/CLion/CMakeLists.txt | 4 +- Servers/AudioServer/ASClientConnection.cpp | 161 --- Servers/AudioServer/ASClientConnection.h | 69 - Servers/AudioServer/ASMixer.cpp | 152 --- Servers/AudioServer/ASMixer.h | 139 --- Servers/AudioServer/AudioClient.ipc | 5 - Servers/AudioServer/AudioServer.ipc | 21 - Servers/AudioServer/Makefile | 24 - Servers/AudioServer/main.cpp | 61 - Servers/DHCPClient/DHCPv4.cpp | 59 - Servers/DHCPClient/DHCPv4.h | 300 ----- Servers/DHCPClient/DHCPv4Client.cpp | 283 ----- Servers/DHCPClient/DHCPv4Client.h | 80 -- Servers/DHCPClient/Makefile | 10 - Servers/DHCPClient/main.cpp | 101 -- Servers/LookupServer/DNSAnswer.cpp | 46 - Servers/LookupServer/DNSAnswer.h | 51 - Servers/LookupServer/DNSPacket.h | 116 -- Servers/LookupServer/DNSQuestion.h | 59 - Servers/LookupServer/DNSRequest.cpp | 98 -- Servers/LookupServer/DNSRequest.h | 65 - Servers/LookupServer/DNSResponse.cpp | 147 --- Servers/LookupServer/DNSResponse.h | 78 -- Servers/LookupServer/LookupServer.cpp | 259 ---- Servers/LookupServer/LookupServer.h | 56 - Servers/LookupServer/Makefile | 12 - Servers/LookupServer/main.cpp | 53 - Servers/Makefile | 3 - Servers/NotificationServer/ClientConnection.cpp | 63 - Servers/NotificationServer/ClientConnection.h | 49 - Servers/NotificationServer/Makefile | 24 - Servers/NotificationServer/NotificationClient.ipc | 4 - Servers/NotificationServer/NotificationServer.ipc | 7 - Servers/NotificationServer/NotificationWindow.cpp | 124 -- Servers/NotificationServer/NotificationWindow.h | 46 - Servers/NotificationServer/main.cpp | 71 -- Servers/ProtocolServer/Download.cpp | 92 -- Servers/ProtocolServer/Download.h | 70 -- Servers/ProtocolServer/HttpDownload.cpp | 60 - Servers/ProtocolServer/HttpDownload.h | 45 - Servers/ProtocolServer/HttpProtocol.cpp | 50 - Servers/ProtocolServer/HttpProtocol.h | 37 - Servers/ProtocolServer/HttpsDownload.cpp | 60 - Servers/ProtocolServer/HttpsDownload.h | 45 - Servers/ProtocolServer/HttpsProtocol.cpp | 50 - Servers/ProtocolServer/HttpsProtocol.h | 37 - Servers/ProtocolServer/Makefile | 25 - Servers/ProtocolServer/PSClientConnection.cpp | 112 -- Servers/ProtocolServer/PSClientConnection.h | 55 - Servers/ProtocolServer/Protocol.cpp | 49 - Servers/ProtocolServer/Protocol.h | 49 - Servers/ProtocolServer/ProtocolClient.ipc | 6 - Servers/ProtocolServer/ProtocolServer.ipc | 15 - Servers/ProtocolServer/main.cpp | 71 -- Servers/SystemServer/Makefile | 13 - Servers/SystemServer/Service.cpp | 365 ------ Servers/SystemServer/Service.h | 90 -- Servers/SystemServer/main.cpp | 139 --- Servers/TTYServer/Makefile | 6 - Servers/TTYServer/main.cpp | 68 - Servers/TelnetServer/Client.cpp | 188 --- Servers/TelnetServer/Client.h | 69 - Servers/TelnetServer/Command.h | 82 -- Servers/TelnetServer/Makefile | 10 - Servers/TelnetServer/Parser.cpp | 89 -- Servers/TelnetServer/Parser.h | 59 - Servers/TelnetServer/main.cpp | 177 --- Servers/WebServer/Client.cpp | 230 ---- Servers/WebServer/Client.h | 54 - Servers/WebServer/Makefile | 9 - Servers/WebServer/main.cpp | 81 -- Servers/WindowServer/AppletManager.cpp | 135 -- Servers/WindowServer/AppletManager.h | 56 - Servers/WindowServer/Button.cpp | 115 -- Servers/WindowServer/Button.h | 70 -- Servers/WindowServer/ClientConnection.cpp | 833 ------------- Servers/WindowServer/ClientConnection.h | 148 --- Servers/WindowServer/Clipboard.cpp | 78 -- Servers/WindowServer/Clipboard.h | 62 - Servers/WindowServer/Compositor.cpp | 507 -------- Servers/WindowServer/Compositor.h | 108 -- Servers/WindowServer/Cursor.cpp | 77 -- Servers/WindowServer/Cursor.h | 65 - Servers/WindowServer/Event.h | 157 --- Servers/WindowServer/EventLoop.cpp | 157 --- Servers/WindowServer/EventLoop.h | 57 - Servers/WindowServer/Makefile | 38 - Servers/WindowServer/Menu.cpp | 570 --------- Servers/WindowServer/Menu.h | 158 --- Servers/WindowServer/MenuBar.cpp | 55 - Servers/WindowServer/MenuBar.h | 61 - Servers/WindowServer/MenuItem.cpp | 96 -- Servers/WindowServer/MenuItem.h | 99 -- Servers/WindowServer/MenuManager.cpp | 404 ------ Servers/WindowServer/MenuManager.h | 123 -- Servers/WindowServer/Screen.cpp | 171 --- Servers/WindowServer/Screen.h | 86 -- Servers/WindowServer/Window.cpp | 524 -------- Servers/WindowServer/Window.h | 286 ----- Servers/WindowServer/WindowClient.ipc | 40 - Servers/WindowServer/WindowFrame.cpp | 414 ------ Servers/WindowServer/WindowFrame.h | 74 -- Servers/WindowServer/WindowManager.cpp | 1317 -------------------- Servers/WindowServer/WindowManager.h | 416 ------- Servers/WindowServer/WindowServer.ipc | 97 -- Servers/WindowServer/WindowSwitcher.cpp | 256 ---- Servers/WindowServer/WindowSwitcher.h | 84 -- Servers/WindowServer/WindowType.h | 41 - Servers/WindowServer/main.cpp | 117 -- Services/AudioServer/ASClientConnection.cpp | 161 +++ Services/AudioServer/ASClientConnection.h | 69 + Services/AudioServer/ASMixer.cpp | 152 +++ Services/AudioServer/ASMixer.h | 139 +++ Services/AudioServer/AudioClient.ipc | 5 + Services/AudioServer/AudioServer.ipc | 21 + Services/AudioServer/Makefile | 24 + Services/AudioServer/main.cpp | 61 + Services/DHCPClient/DHCPv4.cpp | 59 + Services/DHCPClient/DHCPv4.h | 300 +++++ Services/DHCPClient/DHCPv4Client.cpp | 283 +++++ Services/DHCPClient/DHCPv4Client.h | 80 ++ Services/DHCPClient/Makefile | 10 + Services/DHCPClient/main.cpp | 101 ++ Services/LookupServer/DNSAnswer.cpp | 46 + Services/LookupServer/DNSAnswer.h | 51 + Services/LookupServer/DNSPacket.h | 116 ++ Services/LookupServer/DNSQuestion.h | 59 + Services/LookupServer/DNSRequest.cpp | 98 ++ Services/LookupServer/DNSRequest.h | 65 + Services/LookupServer/DNSResponse.cpp | 147 +++ Services/LookupServer/DNSResponse.h | 78 ++ Services/LookupServer/LookupServer.cpp | 259 ++++ Services/LookupServer/LookupServer.h | 56 + Services/LookupServer/Makefile | 12 + Services/LookupServer/main.cpp | 53 + Services/Makefile | 3 + Services/NotificationServer/ClientConnection.cpp | 63 + Services/NotificationServer/ClientConnection.h | 49 + Services/NotificationServer/Makefile | 24 + Services/NotificationServer/NotificationClient.ipc | 4 + Services/NotificationServer/NotificationServer.ipc | 7 + Services/NotificationServer/NotificationWindow.cpp | 124 ++ Services/NotificationServer/NotificationWindow.h | 46 + Services/NotificationServer/main.cpp | 71 ++ Services/ProtocolServer/Download.cpp | 92 ++ Services/ProtocolServer/Download.h | 70 ++ Services/ProtocolServer/HttpDownload.cpp | 60 + Services/ProtocolServer/HttpDownload.h | 45 + Services/ProtocolServer/HttpProtocol.cpp | 50 + Services/ProtocolServer/HttpProtocol.h | 37 + Services/ProtocolServer/HttpsDownload.cpp | 60 + Services/ProtocolServer/HttpsDownload.h | 45 + Services/ProtocolServer/HttpsProtocol.cpp | 50 + Services/ProtocolServer/HttpsProtocol.h | 37 + Services/ProtocolServer/Makefile | 25 + Services/ProtocolServer/PSClientConnection.cpp | 112 ++ Services/ProtocolServer/PSClientConnection.h | 55 + Services/ProtocolServer/Protocol.cpp | 49 + Services/ProtocolServer/Protocol.h | 49 + Services/ProtocolServer/ProtocolClient.ipc | 6 + Services/ProtocolServer/ProtocolServer.ipc | 15 + Services/ProtocolServer/main.cpp | 71 ++ Services/SystemServer/Makefile | 13 + Services/SystemServer/Service.cpp | 365 ++++++ Services/SystemServer/Service.h | 90 ++ Services/SystemServer/main.cpp | 139 +++ Services/TTYServer/Makefile | 6 + Services/TTYServer/main.cpp | 68 + Services/TelnetServer/Client.cpp | 188 +++ Services/TelnetServer/Client.h | 69 + Services/TelnetServer/Command.h | 82 ++ Services/TelnetServer/Makefile | 10 + Services/TelnetServer/Parser.cpp | 89 ++ Services/TelnetServer/Parser.h | 59 + Services/TelnetServer/main.cpp | 177 +++ Services/WebServer/Client.cpp | 230 ++++ Services/WebServer/Client.h | 54 + Services/WebServer/Makefile | 9 + Services/WebServer/main.cpp | 81 ++ Services/WindowServer/AppletManager.cpp | 135 ++ Services/WindowServer/AppletManager.h | 56 + Services/WindowServer/Button.cpp | 115 ++ Services/WindowServer/Button.h | 70 ++ Services/WindowServer/ClientConnection.cpp | 833 +++++++++++++ Services/WindowServer/ClientConnection.h | 148 +++ Services/WindowServer/Clipboard.cpp | 78 ++ Services/WindowServer/Clipboard.h | 62 + Services/WindowServer/Compositor.cpp | 507 ++++++++ Services/WindowServer/Compositor.h | 108 ++ Services/WindowServer/Cursor.cpp | 77 ++ Services/WindowServer/Cursor.h | 65 + Services/WindowServer/Event.h | 157 +++ Services/WindowServer/EventLoop.cpp | 157 +++ Services/WindowServer/EventLoop.h | 57 + Services/WindowServer/Makefile | 38 + Services/WindowServer/Menu.cpp | 570 +++++++++ Services/WindowServer/Menu.h | 158 +++ Services/WindowServer/MenuBar.cpp | 55 + Services/WindowServer/MenuBar.h | 61 + Services/WindowServer/MenuItem.cpp | 96 ++ Services/WindowServer/MenuItem.h | 99 ++ Services/WindowServer/MenuManager.cpp | 404 ++++++ Services/WindowServer/MenuManager.h | 123 ++ Services/WindowServer/Screen.cpp | 171 +++ Services/WindowServer/Screen.h | 86 ++ Services/WindowServer/Window.cpp | 524 ++++++++ Services/WindowServer/Window.h | 286 +++++ Services/WindowServer/WindowClient.ipc | 40 + Services/WindowServer/WindowFrame.cpp | 414 ++++++ Services/WindowServer/WindowFrame.h | 74 ++ Services/WindowServer/WindowManager.cpp | 1317 ++++++++++++++++++++ Services/WindowServer/WindowManager.h | 416 +++++++ Services/WindowServer/WindowServer.ipc | 97 ++ Services/WindowServer/WindowSwitcher.cpp | 256 ++++ Services/WindowServer/WindowSwitcher.h | 84 ++ Services/WindowServer/WindowType.h | 41 + Services/WindowServer/main.cpp | 117 ++ Toolchain/ComputeDependenciesHash.sh | 4 +- 227 files changed, 13736 insertions(+), 13736 deletions(-) delete mode 100644 Servers/AudioServer/ASClientConnection.cpp delete mode 100644 Servers/AudioServer/ASClientConnection.h delete mode 100644 Servers/AudioServer/ASMixer.cpp delete mode 100644 Servers/AudioServer/ASMixer.h delete mode 100644 Servers/AudioServer/AudioClient.ipc delete mode 100644 Servers/AudioServer/AudioServer.ipc delete mode 100644 Servers/AudioServer/Makefile delete mode 100644 Servers/AudioServer/main.cpp delete mode 100644 Servers/DHCPClient/DHCPv4.cpp delete mode 100644 Servers/DHCPClient/DHCPv4.h delete mode 100644 Servers/DHCPClient/DHCPv4Client.cpp delete mode 100644 Servers/DHCPClient/DHCPv4Client.h delete mode 100644 Servers/DHCPClient/Makefile delete mode 100644 Servers/DHCPClient/main.cpp delete mode 100644 Servers/LookupServer/DNSAnswer.cpp delete mode 100644 Servers/LookupServer/DNSAnswer.h delete mode 100644 Servers/LookupServer/DNSPacket.h delete mode 100644 Servers/LookupServer/DNSQuestion.h delete mode 100644 Servers/LookupServer/DNSRequest.cpp delete mode 100644 Servers/LookupServer/DNSRequest.h delete mode 100644 Servers/LookupServer/DNSResponse.cpp delete mode 100644 Servers/LookupServer/DNSResponse.h delete mode 100644 Servers/LookupServer/LookupServer.cpp delete mode 100644 Servers/LookupServer/LookupServer.h delete mode 100644 Servers/LookupServer/Makefile delete mode 100644 Servers/LookupServer/main.cpp delete mode 100644 Servers/Makefile delete mode 100644 Servers/NotificationServer/ClientConnection.cpp delete mode 100644 Servers/NotificationServer/ClientConnection.h delete mode 100644 Servers/NotificationServer/Makefile delete mode 100644 Servers/NotificationServer/NotificationClient.ipc delete mode 100644 Servers/NotificationServer/NotificationServer.ipc delete mode 100644 Servers/NotificationServer/NotificationWindow.cpp delete mode 100644 Servers/NotificationServer/NotificationWindow.h delete mode 100644 Servers/NotificationServer/main.cpp delete mode 100644 Servers/ProtocolServer/Download.cpp delete mode 100644 Servers/ProtocolServer/Download.h delete mode 100644 Servers/ProtocolServer/HttpDownload.cpp delete mode 100644 Servers/ProtocolServer/HttpDownload.h delete mode 100644 Servers/ProtocolServer/HttpProtocol.cpp delete mode 100644 Servers/ProtocolServer/HttpProtocol.h delete mode 100644 Servers/ProtocolServer/HttpsDownload.cpp delete mode 100644 Servers/ProtocolServer/HttpsDownload.h delete mode 100644 Servers/ProtocolServer/HttpsProtocol.cpp delete mode 100644 Servers/ProtocolServer/HttpsProtocol.h delete mode 100644 Servers/ProtocolServer/Makefile delete mode 100644 Servers/ProtocolServer/PSClientConnection.cpp delete mode 100644 Servers/ProtocolServer/PSClientConnection.h delete mode 100644 Servers/ProtocolServer/Protocol.cpp delete mode 100644 Servers/ProtocolServer/Protocol.h delete mode 100644 Servers/ProtocolServer/ProtocolClient.ipc delete mode 100644 Servers/ProtocolServer/ProtocolServer.ipc delete mode 100644 Servers/ProtocolServer/main.cpp delete mode 100644 Servers/SystemServer/Makefile delete mode 100644 Servers/SystemServer/Service.cpp delete mode 100644 Servers/SystemServer/Service.h delete mode 100644 Servers/SystemServer/main.cpp delete mode 100644 Servers/TTYServer/Makefile delete mode 100644 Servers/TTYServer/main.cpp delete mode 100644 Servers/TelnetServer/Client.cpp delete mode 100644 Servers/TelnetServer/Client.h delete mode 100644 Servers/TelnetServer/Command.h delete mode 100644 Servers/TelnetServer/Makefile delete mode 100644 Servers/TelnetServer/Parser.cpp delete mode 100644 Servers/TelnetServer/Parser.h delete mode 100644 Servers/TelnetServer/main.cpp delete mode 100644 Servers/WebServer/Client.cpp delete mode 100644 Servers/WebServer/Client.h delete mode 100644 Servers/WebServer/Makefile delete mode 100644 Servers/WebServer/main.cpp delete mode 100644 Servers/WindowServer/AppletManager.cpp delete mode 100644 Servers/WindowServer/AppletManager.h delete mode 100644 Servers/WindowServer/Button.cpp delete mode 100644 Servers/WindowServer/Button.h delete mode 100644 Servers/WindowServer/ClientConnection.cpp delete mode 100644 Servers/WindowServer/ClientConnection.h delete mode 100644 Servers/WindowServer/Clipboard.cpp delete mode 100644 Servers/WindowServer/Clipboard.h delete mode 100644 Servers/WindowServer/Compositor.cpp delete mode 100644 Servers/WindowServer/Compositor.h delete mode 100644 Servers/WindowServer/Cursor.cpp delete mode 100644 Servers/WindowServer/Cursor.h delete mode 100644 Servers/WindowServer/Event.h delete mode 100644 Servers/WindowServer/EventLoop.cpp delete mode 100644 Servers/WindowServer/EventLoop.h delete mode 100644 Servers/WindowServer/Makefile delete mode 100644 Servers/WindowServer/Menu.cpp delete mode 100644 Servers/WindowServer/Menu.h delete mode 100644 Servers/WindowServer/MenuBar.cpp delete mode 100644 Servers/WindowServer/MenuBar.h delete mode 100644 Servers/WindowServer/MenuItem.cpp delete mode 100644 Servers/WindowServer/MenuItem.h delete mode 100644 Servers/WindowServer/MenuManager.cpp delete mode 100644 Servers/WindowServer/MenuManager.h delete mode 100644 Servers/WindowServer/Screen.cpp delete mode 100644 Servers/WindowServer/Screen.h delete mode 100644 Servers/WindowServer/Window.cpp delete mode 100644 Servers/WindowServer/Window.h delete mode 100644 Servers/WindowServer/WindowClient.ipc delete mode 100644 Servers/WindowServer/WindowFrame.cpp delete mode 100644 Servers/WindowServer/WindowFrame.h delete mode 100644 Servers/WindowServer/WindowManager.cpp delete mode 100644 Servers/WindowServer/WindowManager.h delete mode 100644 Servers/WindowServer/WindowServer.ipc delete mode 100644 Servers/WindowServer/WindowSwitcher.cpp delete mode 100644 Servers/WindowServer/WindowSwitcher.h delete mode 100644 Servers/WindowServer/WindowType.h delete mode 100644 Servers/WindowServer/main.cpp create mode 100644 Services/AudioServer/ASClientConnection.cpp create mode 100644 Services/AudioServer/ASClientConnection.h create mode 100644 Services/AudioServer/ASMixer.cpp create mode 100644 Services/AudioServer/ASMixer.h create mode 100644 Services/AudioServer/AudioClient.ipc create mode 100644 Services/AudioServer/AudioServer.ipc create mode 100644 Services/AudioServer/Makefile create mode 100644 Services/AudioServer/main.cpp create mode 100644 Services/DHCPClient/DHCPv4.cpp create mode 100644 Services/DHCPClient/DHCPv4.h create mode 100644 Services/DHCPClient/DHCPv4Client.cpp create mode 100644 Services/DHCPClient/DHCPv4Client.h create mode 100644 Services/DHCPClient/Makefile create mode 100644 Services/DHCPClient/main.cpp create mode 100644 Services/LookupServer/DNSAnswer.cpp create mode 100644 Services/LookupServer/DNSAnswer.h create mode 100644 Services/LookupServer/DNSPacket.h create mode 100644 Services/LookupServer/DNSQuestion.h create mode 100644 Services/LookupServer/DNSRequest.cpp create mode 100644 Services/LookupServer/DNSRequest.h create mode 100644 Services/LookupServer/DNSResponse.cpp create mode 100644 Services/LookupServer/DNSResponse.h create mode 100644 Services/LookupServer/LookupServer.cpp create mode 100644 Services/LookupServer/LookupServer.h create mode 100644 Services/LookupServer/Makefile create mode 100644 Services/LookupServer/main.cpp create mode 100644 Services/Makefile create mode 100644 Services/NotificationServer/ClientConnection.cpp create mode 100644 Services/NotificationServer/ClientConnection.h create mode 100644 Services/NotificationServer/Makefile create mode 100644 Services/NotificationServer/NotificationClient.ipc create mode 100644 Services/NotificationServer/NotificationServer.ipc create mode 100644 Services/NotificationServer/NotificationWindow.cpp create mode 100644 Services/NotificationServer/NotificationWindow.h create mode 100644 Services/NotificationServer/main.cpp create mode 100644 Services/ProtocolServer/Download.cpp create mode 100644 Services/ProtocolServer/Download.h create mode 100644 Services/ProtocolServer/HttpDownload.cpp create mode 100644 Services/ProtocolServer/HttpDownload.h create mode 100644 Services/ProtocolServer/HttpProtocol.cpp create mode 100644 Services/ProtocolServer/HttpProtocol.h create mode 100644 Services/ProtocolServer/HttpsDownload.cpp create mode 100644 Services/ProtocolServer/HttpsDownload.h create mode 100644 Services/ProtocolServer/HttpsProtocol.cpp create mode 100644 Services/ProtocolServer/HttpsProtocol.h create mode 100644 Services/ProtocolServer/Makefile create mode 100644 Services/ProtocolServer/PSClientConnection.cpp create mode 100644 Services/ProtocolServer/PSClientConnection.h create mode 100644 Services/ProtocolServer/Protocol.cpp create mode 100644 Services/ProtocolServer/Protocol.h create mode 100644 Services/ProtocolServer/ProtocolClient.ipc create mode 100644 Services/ProtocolServer/ProtocolServer.ipc create mode 100644 Services/ProtocolServer/main.cpp create mode 100644 Services/SystemServer/Makefile create mode 100644 Services/SystemServer/Service.cpp create mode 100644 Services/SystemServer/Service.h create mode 100644 Services/SystemServer/main.cpp create mode 100644 Services/TTYServer/Makefile create mode 100644 Services/TTYServer/main.cpp create mode 100644 Services/TelnetServer/Client.cpp create mode 100644 Services/TelnetServer/Client.h create mode 100644 Services/TelnetServer/Command.h create mode 100644 Services/TelnetServer/Makefile create mode 100644 Services/TelnetServer/Parser.cpp create mode 100644 Services/TelnetServer/Parser.h create mode 100644 Services/TelnetServer/main.cpp create mode 100644 Services/WebServer/Client.cpp create mode 100644 Services/WebServer/Client.h create mode 100644 Services/WebServer/Makefile create mode 100644 Services/WebServer/main.cpp create mode 100644 Services/WindowServer/AppletManager.cpp create mode 100644 Services/WindowServer/AppletManager.h create mode 100644 Services/WindowServer/Button.cpp create mode 100644 Services/WindowServer/Button.h create mode 100644 Services/WindowServer/ClientConnection.cpp create mode 100644 Services/WindowServer/ClientConnection.h create mode 100644 Services/WindowServer/Clipboard.cpp create mode 100644 Services/WindowServer/Clipboard.h create mode 100644 Services/WindowServer/Compositor.cpp create mode 100644 Services/WindowServer/Compositor.h create mode 100644 Services/WindowServer/Cursor.cpp create mode 100644 Services/WindowServer/Cursor.h create mode 100644 Services/WindowServer/Event.h create mode 100644 Services/WindowServer/EventLoop.cpp create mode 100644 Services/WindowServer/EventLoop.h create mode 100644 Services/WindowServer/Makefile create mode 100644 Services/WindowServer/Menu.cpp create mode 100644 Services/WindowServer/Menu.h create mode 100644 Services/WindowServer/MenuBar.cpp create mode 100644 Services/WindowServer/MenuBar.h create mode 100644 Services/WindowServer/MenuItem.cpp create mode 100644 Services/WindowServer/MenuItem.h create mode 100644 Services/WindowServer/MenuManager.cpp create mode 100644 Services/WindowServer/MenuManager.h create mode 100644 Services/WindowServer/Screen.cpp create mode 100644 Services/WindowServer/Screen.h create mode 100644 Services/WindowServer/Window.cpp create mode 100644 Services/WindowServer/Window.h create mode 100644 Services/WindowServer/WindowClient.ipc create mode 100644 Services/WindowServer/WindowFrame.cpp create mode 100644 Services/WindowServer/WindowFrame.h create mode 100644 Services/WindowServer/WindowManager.cpp create mode 100644 Services/WindowServer/WindowManager.h create mode 100644 Services/WindowServer/WindowServer.ipc create mode 100644 Services/WindowServer/WindowSwitcher.cpp create mode 100644 Services/WindowServer/WindowSwitcher.h create mode 100644 Services/WindowServer/WindowType.h create mode 100644 Services/WindowServer/main.cpp diff --git a/Applications/Browser/Makefile b/Applications/Browser/Makefile index 354d07c7cb..1cd944c891 100644 --- a/Applications/Browser/Makefile +++ b/Applications/Browser/Makefile @@ -14,8 +14,8 @@ main.cpp: ../../Libraries/LibWeb/CSS/PropertyID.h ../../Libraries/LibWeb/CSS/PropertyID.h: @flock ../../Libraries/LibWeb $(MAKE) -C ../../Libraries/LibWeb -main.cpp: ../../Servers/ProtocolServer/ProtocolClientEndpoint.h -../../Servers/ProtocolServer/ProtocolClientEndpoint.h: - @flock ../../Servers/ProtocolServer $(MAKE) -C $(dir $(@)) +main.cpp: ../../Services/ProtocolServer/ProtocolClientEndpoint.h +../../Services/ProtocolServer/ProtocolClientEndpoint.h: + @flock ../../Services/ProtocolServer $(MAKE) -C $(dir $(@)) include ../../Makefile.common diff --git a/Documentation/BuildInstructions.md b/Documentation/BuildInstructions.md index 4dd79d15ee..5fbd287624 100644 --- a/Documentation/BuildInstructions.md +++ b/Documentation/BuildInstructions.md @@ -81,7 +81,7 @@ Bare curious users may even consider sourcing suitable hardware to [install Sere Later on, when you `git pull` to get the latest changes, there's no need to rebuild the toolchain. You can simply rerun **./makeall.sh** in the `Kernel/` directory and you'll be good to **./run** again. -You can even re-compile only parts of the system. Imagine you changed something in the **WindowServer**. Then run `make -C ../Servers/WindowServer` (from the `Kernel/` directory) followed by **./sync.sh** to update the disk image. Then you can start the system with **./run** again. +You can even re-compile only parts of the system. Imagine you changed something in the **WindowServer**. Then run `make -C ../Services/WindowServer` (from the `Kernel/` directory) followed by **./sync.sh** to update the disk image. Then you can start the system with **./run** again. #### Ports To add a package from the ports collection to Serenity, for example curl, go into `Ports/curl/` and run **./package.sh**. The sourcecode for the package will be downloaded and the package will be built. After that, run **./sync.sh** from the `Kernel/` directory to update the disk image. The next time you start Serenity with **./run**, `curl` will be available. diff --git a/Kernel/build-root-filesystem.sh b/Kernel/build-root-filesystem.sh index 3c078ad0ef..90b753c6cf 100755 --- a/Kernel/build-root-filesystem.sh +++ b/Kernel/build-root-filesystem.sh @@ -159,16 +159,16 @@ cp ../DevTools/Inspector/Inspector mnt/bin/Inspector cp ../DevTools/ProfileViewer/ProfileViewer mnt/bin/ProfileViewer cp ../Games/Minesweeper/Minesweeper mnt/bin/Minesweeper cp ../Games/Snake/Snake mnt/bin/Snake -cp ../Servers/DHCPClient/DHCPClient mnt/bin/DHCPClient -cp ../Servers/LookupServer/LookupServer mnt/bin/LookupServer -cp ../Servers/SystemServer/SystemServer mnt/bin/SystemServer -cp ../Servers/WindowServer/WindowServer mnt/bin/WindowServer -cp ../Servers/AudioServer/AudioServer mnt/bin/AudioServer -cp ../Servers/TTYServer/TTYServer mnt/bin/TTYServer -cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer -cp ../Servers/ProtocolServer/ProtocolServer mnt/bin/ProtocolServer -cp ../Servers/NotificationServer/NotificationServer mnt/bin/NotificationServer -cp ../Servers/WebServer/WebServer mnt/bin/WebServer +cp ../Services/DHCPClient/DHCPClient mnt/bin/DHCPClient +cp ../Services/LookupServer/LookupServer mnt/bin/LookupServer +cp ../Services/SystemServer/SystemServer mnt/bin/SystemServer +cp ../Services/WindowServer/WindowServer mnt/bin/WindowServer +cp ../Services/AudioServer/AudioServer mnt/bin/AudioServer +cp ../Services/TTYServer/TTYServer mnt/bin/TTYServer +cp ../Services/TelnetServer/TelnetServer mnt/bin/TelnetServer +cp ../Services/ProtocolServer/ProtocolServer mnt/bin/ProtocolServer +cp ../Services/NotificationServer/NotificationServer mnt/bin/NotificationServer +cp ../Services/WebServer/WebServer mnt/bin/WebServer cp ../Shell/Shell mnt/bin/Shell cp ../MenuApplets/Audio/Audio.MenuApplet mnt/bin/ cp ../MenuApplets/ResourceGraph/ResourceGraph.MenuApplet mnt/bin/ diff --git a/Libraries/LibAudio/Makefile b/Libraries/LibAudio/Makefile index 51453a9665..41e9fd3549 100644 --- a/Libraries/LibAudio/Makefile +++ b/Libraries/LibAudio/Makefile @@ -5,8 +5,8 @@ OBJS = \ LIBRARY = libaudio.a -ClientConnection.cpp: ../../Servers/AudioServer/AudioClientEndpoint.h -../../Servers/AudioServer/AudioClientEndpoint.h: +ClientConnection.cpp: ../../Services/AudioServer/AudioClientEndpoint.h +../../Services/AudioServer/AudioClientEndpoint.h: @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) install: diff --git a/Libraries/LibGUI/Makefile b/Libraries/LibGUI/Makefile index 2535132435..bbb1327472 100644 --- a/Libraries/LibGUI/Makefile +++ b/Libraries/LibGUI/Makefile @@ -77,18 +77,18 @@ OBJS = \ LIBRARY = libgui.a -Application.cpp: ../../Servers/WindowServer/WindowServerEndpoint.h +Application.cpp: ../../Services/WindowServer/WindowServerEndpoint.h -../../Servers/WindowServer/WindowServerEndpoint.h: +../../Services/WindowServer/WindowServerEndpoint.h: @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) # HACK: NotificationServer depends on LibGUI so we don't flock for these.. -Notification.cpp: ../../Servers/NotificationServer/NotificationServerEndpoint.h ../../Servers/NotificationServer/NotificationClientEndpoint.h +Notification.cpp: ../../Services/NotificationServer/NotificationServerEndpoint.h ../../Services/NotificationServer/NotificationClientEndpoint.h -../../Servers/NotificationServer/NotificationServerEndpoint.h: +../../Services/NotificationServer/NotificationServerEndpoint.h: $(MAKE) -C $(dir $(@)) NotificationServerEndpoint.h -../../Servers/NotificationServer/NotificationClientEndpoint.h: +../../Services/NotificationServer/NotificationClientEndpoint.h: $(MAKE) -C $(dir $(@)) NotificationClientEndpoint.h install: diff --git a/Libraries/LibProtocol/Makefile b/Libraries/LibProtocol/Makefile index 05714ffb88..00b3605fb6 100644 --- a/Libraries/LibProtocol/Makefile +++ b/Libraries/LibProtocol/Makefile @@ -4,8 +4,8 @@ OBJS = \ LIBRARY = libprotocol.a -Download.cpp Client.cpp: ../../Servers/ProtocolServer/ProtocolClientEndpoint.h ../../Servers/ProtocolServer/ProtocolServerEndpoint.h -../../Servers/ProtocolServer/ProtocolClientEndpoint.h ../../Servers/ProtocolServer/ProtocolServerEndpoint.h: +Download.cpp Client.cpp: ../../Services/ProtocolServer/ProtocolClientEndpoint.h ../../Services/ProtocolServer/ProtocolServerEndpoint.h +../../Services/ProtocolServer/ProtocolClientEndpoint.h ../../Services/ProtocolServer/ProtocolServerEndpoint.h: @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) include ../../Makefile.common diff --git a/Libraries/LibWeb/Makefile b/Libraries/LibWeb/Makefile index 2016f72898..c86aa8bf12 100644 --- a/Libraries/LibWeb/Makefile +++ b/Libraries/LibWeb/Makefile @@ -118,8 +118,8 @@ CSS/PropertyID.cpp: CSS/Properties.json $(GENERATE_CSS_PROPERTYID_CPP) @echo "GENERATE $@" $(QUIET) flock CSS $(GENERATE_CSS_PROPERTYID_CPP) $< > $@ -ResourceLoader.cpp: ../../Servers/ProtocolServer/ProtocolClientEndpoint.h ../../Servers/ProtocolServer/ProtocolServerEndpoint.h -../../Servers/ProtocolServer/ProtocolClientEndpoint.h ../../Servers/ProtocolServer/ProtocolServerEndpoint.h: +ResourceLoader.cpp: ../../Services/ProtocolServer/ProtocolClientEndpoint.h ../../Services/ProtocolServer/ProtocolServerEndpoint.h +../../Services/ProtocolServer/ProtocolClientEndpoint.h ../../Services/ProtocolServer/ProtocolServerEndpoint.h: @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) EXTRA_CLEAN = CSS/DefaultStyleSheetSource.cpp CSS/PropertyID.h CSS/PropertyID.cpp diff --git a/Makefile b/Makefile index f59dd7517d..f8171d607a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SUBDIRS += \ Libraries \ AK \ DevTools \ - Servers + Services SUBDIRS += \ Applications \ diff --git a/Makefile.common b/Makefile.common index 50b7efd90e..0f40094a1d 100644 --- a/Makefile.common +++ b/Makefile.common @@ -18,7 +18,7 @@ INCLUDE_FLAGS += \ -I$(SERENITY_BASE_DIR)/DevTools \ -I$(SERENITY_BASE_DIR) \ -I$(SERENITY_BASE_DIR)/Libraries \ - -I$(SERENITY_BASE_DIR)/Servers + -I$(SERENITY_BASE_DIR)/Services VERBOSE = 0 diff --git a/Meta/CLion/CMakeLists.txt b/Meta/CLion/CMakeLists.txt index 4e060c8b4a..048e657892 100644 --- a/Meta/CLion/CMakeLists.txt +++ b/Meta/CLion/CMakeLists.txt @@ -12,7 +12,7 @@ file(GLOB_RECURSE KERNEL_SOURCES "serenity/Kernel/*.cpp") file(GLOB_RECURSE LIBRARIES_SOURCES "serenity/Libraries/*.cpp") file(GLOB_RECURSE MENU_APPLETS_SOURCES "serenity/MenuApplets/*.cpp") file(GLOB_RECURSE PORTS_SOURCES "serenity/Ports/*.cpp") -file(GLOB_RECURSE SERVERS_SOURCES "serenity/Servers/*.cpp") +file(GLOB_RECURSE SERVERS_SOURCES "serenity/Services/*.cpp") file(GLOB_RECURSE SHELL_SOURCES "serenity/Shell/*.cpp") file(GLOB_RECURSE TESTS_SOURCES "serenity/Tests/*.cpp") file(GLOB_RECURSE TOOLCHAIN_SOURCES "serenity/Toolchain/*.cpp") @@ -24,7 +24,7 @@ set(INCLUDE_DIRS "serenity/Libraries" "serenity/Libraries/LibC" "serenity/Libraries/LibPthread" - "serenity/Servers" + "serenity/Services" "serenity/Toolchain/Local/i686-pc-serenity/include/c++/9.3.0") add_library(serenity diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp deleted file mode 100644 index a1d4b766a0..0000000000 --- a/Servers/AudioServer/ASClientConnection.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ASClientConnection.h" -#include "ASMixer.h" -#include "AudioClientEndpoint.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static HashMap> s_connections; - -void ASClientConnection::for_each(Function callback) -{ - NonnullRefPtrVector connections; - for (auto& it : s_connections) - connections.append(*it.value); - for (auto& connection : connections) - callback(connection); -} - -ASClientConnection::ASClientConnection(Core::LocalSocket& client_socket, int client_id, ASMixer& mixer) - : IPC::ClientConnection(*this, client_socket, client_id) - , m_mixer(mixer) -{ - s_connections.set(client_id, *this); -} - -ASClientConnection::~ASClientConnection() -{ -} - -void ASClientConnection::die() -{ - s_connections.remove(client_id()); -} - -void ASClientConnection::did_finish_playing_buffer(Badge, int buffer_id) -{ - post_message(Messages::AudioClient::FinishedPlayingBuffer(buffer_id)); -} - -void ASClientConnection::did_change_muted_state(Badge, bool muted) -{ - post_message(Messages::AudioClient::MutedStateChanged(muted)); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::GetMainMixVolume&) -{ - return make(m_mixer.main_volume()); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::SetMainMixVolume& message) -{ - m_mixer.set_main_volume(message.volume()); - return make(); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::EnqueueBuffer& message) -{ - auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.buffer_id()); - if (!shared_buffer) { - // FIXME: The shared buffer should have been retrieved for us already. - // We don't want to do IPC error checking at this layer. - ASSERT_NOT_REACHED(); - } - - if (!m_queue) - m_queue = m_mixer.create_queue(*this); - - if (m_queue->is_full()) - return make(false); - - m_queue->enqueue(Audio::Buffer::create_with_shared_buffer(*shared_buffer, message.sample_count())); - return make(true); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::GetRemainingSamples&) -{ - int remaining = 0; - if (m_queue) - remaining = m_queue->get_remaining_samples(); - - return make(remaining); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::GetPlayedSamples&) -{ - int played = 0; - if (m_queue) - played = m_queue->get_played_samples(); - - return make(played); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::SetPaused& message) -{ - if (m_queue) - m_queue->set_paused(message.paused()); - return make(); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::ClearBuffer& message) -{ - if (m_queue) - m_queue->clear(message.paused()); - return make(); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::GetPlayingBuffer&) -{ - int id = -1; - if (m_queue) - id = m_queue->get_playing_buffer(); - return make(id); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::GetMuted&) -{ - return make(m_mixer.is_muted()); -} - -OwnPtr ASClientConnection::handle(const Messages::AudioServer::SetMuted& message) -{ - m_mixer.set_muted(message.muted()); - return make(); -} diff --git a/Servers/AudioServer/ASClientConnection.h b/Servers/AudioServer/ASClientConnection.h deleted file mode 100644 index c76c51eb36..0000000000 --- a/Servers/AudioServer/ASClientConnection.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -namespace Audio { -class Buffer; -} - -class ASBufferQueue; -class ASMixer; - -class ASClientConnection final : public IPC::ClientConnection - , public AudioServerEndpoint { - C_OBJECT(ASClientConnection) -public: - explicit ASClientConnection(Core::LocalSocket&, int client_id, ASMixer& mixer); - ~ASClientConnection() override; - - void did_finish_playing_buffer(Badge, int buffer_id); - void did_change_muted_state(Badge, bool muted); - - virtual void die() override; - - static void for_each(Function); - -private: - virtual OwnPtr handle(const Messages::AudioServer::Greet&) override; - virtual OwnPtr handle(const Messages::AudioServer::GetMainMixVolume&) override; - virtual OwnPtr handle(const Messages::AudioServer::SetMainMixVolume&) override; - virtual OwnPtr handle(const Messages::AudioServer::EnqueueBuffer&) override; - virtual OwnPtr handle(const Messages::AudioServer::GetRemainingSamples&) override; - virtual OwnPtr handle(const Messages::AudioServer::GetPlayedSamples&) override; - virtual OwnPtr handle(const Messages::AudioServer::SetPaused&) override; - virtual OwnPtr handle(const Messages::AudioServer::ClearBuffer&) override; - virtual OwnPtr handle(const Messages::AudioServer::GetPlayingBuffer&) override; - virtual OwnPtr handle(const Messages::AudioServer::GetMuted&) override; - virtual OwnPtr handle(const Messages::AudioServer::SetMuted&) override; - - ASMixer& m_mixer; - RefPtr m_queue; -}; diff --git a/Servers/AudioServer/ASMixer.cpp b/Servers/AudioServer/ASMixer.cpp deleted file mode 100644 index 3d9ff00cc5..0000000000 --- a/Servers/AudioServer/ASMixer.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -ASMixer::ASMixer() - : m_device(Core::File::construct("/dev/audio", this)) - , m_sound_thread( - [this] { - mix(); - return 0; - }, - "AudioServer[mixer]") -{ - if (!m_device->open(Core::IODevice::WriteOnly)) { - dbgprintf("Can't open audio device: %s\n", m_device->error_string()); - return; - } - - pthread_mutex_init(&m_pending_mutex, nullptr); - pthread_cond_init(&m_pending_cond, nullptr); - - m_zero_filled_buffer = (u8*)malloc(4096); - bzero(m_zero_filled_buffer, 4096); - m_sound_thread.start(); -} - -ASMixer::~ASMixer() -{ -} - -NonnullRefPtr ASMixer::create_queue(ASClientConnection& client) -{ - auto queue = adopt(*new ASBufferQueue(client)); - pthread_mutex_lock(&m_pending_mutex); - m_pending_mixing.append(*queue); - pthread_cond_signal(&m_pending_cond); - pthread_mutex_unlock(&m_pending_mutex); - return queue; -} - -void ASMixer::mix() -{ - decltype(m_pending_mixing) active_mix_queues; - - for (;;) { - if (active_mix_queues.is_empty()) { - pthread_mutex_lock(&m_pending_mutex); - pthread_cond_wait(&m_pending_cond, &m_pending_mutex); - active_mix_queues.append(move(m_pending_mixing)); - pthread_mutex_unlock(&m_pending_mutex); - } - - active_mix_queues.remove_all_matching([&](auto& entry) { return !entry->client(); }); - - Audio::Sample mixed_buffer[1024]; - auto mixed_buffer_length = (int)(sizeof(mixed_buffer) / sizeof(Audio::Sample)); - - // Mix the buffers together into the output - for (auto& queue : active_mix_queues) { - if (!queue->client()) { - queue->clear(); - continue; - } - - for (int i = 0; i < mixed_buffer_length; ++i) { - auto& mixed_sample = mixed_buffer[i]; - Audio::Sample sample; - if (!queue->get_next_sample(sample)) - break; - mixed_sample += sample; - } - } - - bool muted = m_muted; - - // output the mixed stuff to the device - u8 raw_buffer[4096]; - auto buffer = ByteBuffer::wrap(muted ? m_zero_filled_buffer : raw_buffer, sizeof(raw_buffer)); - - BufferStream stream(buffer); - if (!muted) { - for (int i = 0; i < mixed_buffer_length; ++i) { - auto& mixed_sample = mixed_buffer[i]; - - mixed_sample.scale(m_main_volume); - mixed_sample.clip(); - - i16 out_sample; - out_sample = mixed_sample.left * NumericLimits::max(); - stream << out_sample; - - ASSERT(!stream.at_end()); // we should have enough space for both channels in one buffer! - out_sample = mixed_sample.right * NumericLimits::max(); - stream << out_sample; - } - } - - if (stream.offset() != 0) { - buffer.trim(stream.offset()); - } - m_device->write(buffer); - } -} - -void ASMixer::set_muted(bool muted) -{ - if (m_muted == muted) - return; - m_muted = muted; - ASClientConnection::for_each([muted](ASClientConnection& client) { - client.did_change_muted_state({}, muted); - }); -} - -ASBufferQueue::ASBufferQueue(ASClientConnection& client) - : m_client(client.make_weak_ptr()) -{ -} - -void ASBufferQueue::enqueue(NonnullRefPtr&& buffer) -{ - m_remaining_samples += buffer->sample_count(); - m_queue.enqueue(move(buffer)); -} diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h deleted file mode 100644 index e5ed5874b2..0000000000 --- a/Servers/AudioServer/ASMixer.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include "ASClientConnection.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class ASClientConnection; - -class ASBufferQueue : public RefCounted { -public: - explicit ASBufferQueue(ASClientConnection&); - ~ASBufferQueue() {} - - bool is_full() const { return m_queue.size() >= 3; } - void enqueue(NonnullRefPtr&&); - - bool get_next_sample(Audio::Sample& sample) - { - if (m_paused) - return false; - - while (!m_current && !m_queue.is_empty()) - m_current = m_queue.dequeue(); - - if (!m_current) - return false; - - sample = m_current->samples()[m_position++]; - --m_remaining_samples; - ++m_played_samples; - - if (m_position >= m_current->sample_count()) { - m_client->did_finish_playing_buffer({}, m_current->shbuf_id()); - m_current = nullptr; - m_position = 0; - } - return true; - } - - ASClientConnection* client() { return m_client.ptr(); } - - void clear(bool paused = false) - { - m_queue.clear(); - m_position = 0; - m_remaining_samples = 0; - m_played_samples = 0; - m_current = nullptr; - m_paused = paused; - } - - void set_paused(bool paused) - { - m_paused = paused; - } - - int get_remaining_samples() const { return m_remaining_samples; } - int get_played_samples() const { return m_played_samples; } - int get_playing_buffer() const - { - if (m_current) - return m_current->shbuf_id(); - return -1; - } - -private: - RefPtr m_current; - Queue> m_queue; - int m_position { 0 }; - int m_remaining_samples { 0 }; - int m_played_samples { 0 }; - bool m_paused { false }; - WeakPtr m_client; -}; - -class ASMixer : public Core::Object { - C_OBJECT(ASMixer) -public: - ASMixer(); - virtual ~ASMixer() override; - - NonnullRefPtr create_queue(ASClientConnection&); - - int main_volume() const { return m_main_volume; } - void set_main_volume(int volume) { m_main_volume = volume; } - - bool is_muted() const { return m_muted; } - void set_muted(bool); - -private: - Vector> m_pending_mixing; - pthread_mutex_t m_pending_mutex; - pthread_cond_t m_pending_cond; - - RefPtr m_device; - - LibThread::Thread m_sound_thread; - - bool m_muted { false }; - int m_main_volume { 100 }; - - u8* m_zero_filled_buffer { nullptr }; - - void mix(); -}; diff --git a/Servers/AudioServer/AudioClient.ipc b/Servers/AudioServer/AudioClient.ipc deleted file mode 100644 index 12aa2d0b92..0000000000 --- a/Servers/AudioServer/AudioClient.ipc +++ /dev/null @@ -1,5 +0,0 @@ -endpoint AudioClient = 82 -{ - FinishedPlayingBuffer(i32 buffer_id) =| - MutedStateChanged(bool muted) =| -} diff --git a/Servers/AudioServer/AudioServer.ipc b/Servers/AudioServer/AudioServer.ipc deleted file mode 100644 index b48dcd7e46..0000000000 --- a/Servers/AudioServer/AudioServer.ipc +++ /dev/null @@ -1,21 +0,0 @@ -endpoint AudioServer = 85 -{ - // Basic protocol - Greet() => (i32 client_id) - - // Mixer functions - SetMuted(bool muted) => () - GetMuted() => (bool muted) - GetMainMixVolume() => (i32 volume) - SetMainMixVolume(i32 volume) => () - - // Buffer playback - EnqueueBuffer(i32 buffer_id, int sample_count) => (bool success) - SetPaused(bool paused) => () - ClearBuffer(bool paused) => () - - //Buffer information - GetRemainingSamples() => (int remaining_samples) - GetPlayedSamples() => (int played_samples) - GetPlayingBuffer() => (i32 buffer_id) -} diff --git a/Servers/AudioServer/Makefile b/Servers/AudioServer/Makefile deleted file mode 100644 index 7b6b3dd031..0000000000 --- a/Servers/AudioServer/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -OBJS = \ - main.o \ - ASMixer.o \ - ASClientConnection.o - -PROGRAM = AudioServer - -LIB_DEPS = Core IPC Thread Pthread - -EXTRA_CLEAN = AudioServerEndpoint.h AudioClientEndpoint.h - -*.cpp: AudioServerEndpoint.h AudioClientEndpoint.h - -AudioServerEndpoint.h: AudioServer.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -AudioClientEndpoint.h: AudioClient.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -install: - mkdir -p $(SERENITY_BASE_DIR)/Root/usr/include/AudioServer/ - cp *.h $(SERENITY_BASE_DIR)/Root/usr/include/AudioServer/ - -include ../../Makefile.common diff --git a/Servers/AudioServer/main.cpp b/Servers/AudioServer/main.cpp deleted file mode 100644 index 5907dd77c6..0000000000 --- a/Servers/AudioServer/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ASMixer.h" -#include -#include - -int main(int, char**) -{ - if (pledge("stdio thread shared_buffer accept rpath wpath cpath unix fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - Core::EventLoop event_loop; - ASMixer mixer; - - auto server = Core::LocalServer::construct(); - bool ok = server->take_over_from_system_server(); - ASSERT(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbg() << "AudioServer: accept failed."; - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(*client_socket, client_id, mixer); - }; - - if (pledge("stdio thread shared_buffer accept", nullptr) < 0) { - perror("pledge"); - return 1; - } - - return event_loop.exec(); -} diff --git a/Servers/DHCPClient/DHCPv4.cpp b/Servers/DHCPClient/DHCPv4.cpp deleted file mode 100644 index 36430f4eec..0000000000 --- a/Servers/DHCPClient/DHCPv4.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DHCPv4.h" - -//#define DHCPV4_DEBUG - -ParsedDHCPv4Options DHCPv4Packet::parse_options() const -{ - ParsedDHCPv4Options options; - for (size_t index = 4; index < DHCPV4_OPTION_FIELD_MAX_LENGTH; ++index) { - auto opt_name = *(const DHCPOption*)&m_options[index]; - switch (opt_name) { - case DHCPOption::Pad: - continue; - case DHCPOption::End: - goto escape; - default: - ++index; - auto length = m_options[index]; - if ((size_t)length > DHCPV4_OPTION_FIELD_MAX_LENGTH - index) { - dbg() << "Bogus option length " << length << " assuming forgotten END"; - break; - } -#ifdef DHCPV4_DEBUG - dbg() << "DHCP Option " << (u8)opt_name << " with length " << length; -#endif - ++index; - options.options.set(opt_name, { length, &m_options[index] }); - index += length - 1; - break; - } - } -escape:; - return options; -} diff --git a/Servers/DHCPClient/DHCPv4.h b/Servers/DHCPClient/DHCPv4.h deleted file mode 100644 index 07c5787f8a..0000000000 --- a/Servers/DHCPClient/DHCPv4.h +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum class DHCPv4Flags : u16 { - Broadcast = 1, - /* everything else is reserved and must be zero */ -}; - -enum class DHCPv4Op : u8 { - BootRequest = 1, - BootReply = 2 -}; - -enum class DHCPOption : u8 { - // BOOTP - Pad = 0, - SubnetMask, - TimeOffset, - Router, - TimeServer, - NameServer, - DomainNameServer, - LogServer, - CookieServer, - LPRServer, - ImpressServer, - ResourceLocationServer, - HostName, - BootFileSize, - MeritDumpFile, - DomainName, - SwapServer, - RootPath, - ExtensionsPath, - IPForwardingEnableDisable, - NonLocalSourceRoutingEnableDisable, - PolicyFilter, - MaximumDatagramReassemblySize, - DefaultIPTTL, - PathMTUAgingTimeout, - PathMTUPlateauTable, - InterfaceMTU, - AllSubnetsAreLocal, - BroadcastAddress, - PerformMaskDiscovery, - MaskSupplier, - PerformRouterDiscovery, - RouterSolicitationAddress, - StaticRoute, - TrailerEncapsulation, - ARPCacheTimeout, - EthernetEncapsulation, - TCPDefaultTTL, - TCPKeepaliveInterval, - TCPKeepaliveGarbage, - NetworkInformationServiceDomain, - NetworkInformationServers, - NetworkTimeProtocolServers, - VendorSpecificInformation, - NetBIOSOverTCPIPNameServer, - NetBIOSOverTCPIPDatagramDistributionServer, - NetBIOSOverTCPIPNodeType, - NetBIOSOverTCPIPScope, - XWindowSystemFontServer, // wow - XWindowSystemDisplayManager, - // DHCP - RequestedIPAddress = 50, - IPAddressLeaseTime, - OptionOverload, - DHCPMessageType, - ServerIdentifier, - ParameterRequestList, - Message, - MaximumDHCPMessageSize, - RenewalT1Time, - RenewalT2Time, - ClassIdentifier, - ClientIdentifier, - End = 255 -}; - -enum class DHCPMessageType : u8 { - DHCPDiscover = 1, - DHCPOffer, - DHCPRequest, - DHCPDecline, - DHCPAck, - DHCPNak, - DHCPRelease, -}; - -template <> -struct AK::Traits : public AK::GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(DHCPOption u) { return int_hash((u8)u); } -}; - -struct ParsedDHCPv4Options { - template - Optional get(DHCPOption option_name) const - { - auto option = options.get(option_name); - if (!option.has_value()) { - return {}; - } - auto& value = option.value(); - if (value.length != sizeof(T)) - return {}; - return *(const T*)value.value; - } - - template - Vector get_many(DHCPOption option_name, size_t max_number) const - { - Vector values; - - auto option = options.get(option_name); - if (!option.has_value()) { - return {}; - } - auto& value = option.value(); - if (value.length < sizeof(T)) - return {}; - - for (size_t i = 0; i < max_number; ++i) { - auto offset = i * sizeof(T); - if (offset >= value.length) - break; - values.append(*(T*)((u8*)const_cast(value.value) + offset)); - } - - return values; - } - - String to_string() const - { - StringBuilder builder; - builder.append("DHCP Options ("); - builder.appendf("%d", options.size()); - builder.append(" entries)\n"); - for (auto& opt : options) { - builder.appendf("\toption %d (%d bytes):", (u8)opt.key, (u8)opt.value.length); - for (auto i = 0; i < opt.value.length; ++i) - builder.appendf(" %u ", ((const u8*)opt.value.value)[i]); - builder.append('\n'); - } - return builder.build(); - } - - struct DHCPOptionValue { - u8 length; - const void* value; - }; - - HashMap options; -}; - -constexpr auto DHCPV4_OPTION_FIELD_MAX_LENGTH = 312; - -class [[gnu::packed]] DHCPv4Packet -{ -public: - u8 op() const { return m_op; } - void set_op(DHCPv4Op op) { m_op = (u8)op; } - - u8 htype() const { return m_htype; } - void set_htype(u8 htype) { m_htype = htype; } - - u8 hlen() const { return m_hlen; } - void set_hlen(u8 hlen) { m_hlen = hlen; } - - u8 hops() const { return m_hops; } - void set_hops(u8 hops) { m_hops = hops; } - - u32 xid() const { return m_xid; } - void set_xid(u32 xid) { m_xid = xid; } - - u16 secs() const { return m_secs; } - void set_secs(u16 secs) { m_secs = secs; } - - u16 flags() const { return m_flags; } - void set_flags(DHCPv4Flags flags) { m_flags = (u16)flags; } - - const IPv4Address& ciaddr() const { return m_ciaddr; } - const IPv4Address& yiaddr() const { return m_yiaddr; } - const IPv4Address& siaddr() const { return m_siaddr; } - const IPv4Address& giaddr() const { return m_giaddr; } - - IPv4Address& ciaddr() { return m_ciaddr; } - IPv4Address& yiaddr() { return m_yiaddr; } - IPv4Address& siaddr() { return m_siaddr; } - IPv4Address& giaddr() { return m_giaddr; } - - u8* options() { return m_options; } - ParsedDHCPv4Options parse_options() const; - - const MACAddress& chaddr() const { return *(const MACAddress*)&m_chaddr[0]; } - void set_chaddr(const MACAddress& mac) { *(MACAddress*)&m_chaddr[0] = mac; } - - StringView sname() const { return { (const char*)&m_sname[0] }; } - StringView file() const { return { (const char*)&m_file[0] }; } - -private: - NetworkOrdered m_op; - NetworkOrdered m_htype; - NetworkOrdered m_hlen; - NetworkOrdered m_hops; - NetworkOrdered m_xid; - NetworkOrdered m_secs; - NetworkOrdered m_flags; - IPv4Address m_ciaddr; - IPv4Address m_yiaddr; - IPv4Address m_siaddr; - IPv4Address m_giaddr; - u8 m_chaddr[16]; // 10 bytes of padding at the end - u8 m_sname[64] { 0 }; - u8 m_file[128] { 0 }; - u8 m_options[DHCPV4_OPTION_FIELD_MAX_LENGTH] { 0 }; // variable, less than 312 bytes -}; - -class DHCPv4PacketBuilder { -public: - DHCPv4PacketBuilder() - : m_buffer(ByteBuffer::create_zeroed(sizeof(DHCPv4Packet))) - { - auto* options = peek().options(); - // set the magic DHCP cookie value - options[0] = 99; - options[1] = 130; - options[2] = 83; - options[3] = 99; - } - - void add_option(DHCPOption option, u8 length, const void* data) - { - ASSERT(m_can_add); - // we need enough space to fit the option value, its length, and its data - ASSERT(next_option_offset + length + 2 < DHCPV4_OPTION_FIELD_MAX_LENGTH); - - auto* options = peek().options(); - options[next_option_offset++] = (u8)option; - memcpy(options + next_option_offset, &length, 1); - next_option_offset++; - memcpy(options + next_option_offset, data, length); - next_option_offset += length; - } - - void set_message_type(DHCPMessageType type) { add_option(DHCPOption::DHCPMessageType, 1, &type); } - - DHCPv4Packet& peek() { return *(DHCPv4Packet*)m_buffer.data(); } - DHCPv4Packet& build() - { - add_option(DHCPOption::End, 0, nullptr); - m_can_add = false; - return *(DHCPv4Packet*)m_buffer.data(); - } - size_t size() const { return m_buffer.size(); } - -private: - ByteBuffer m_buffer; - size_t next_option_offset { 4 }; - bool m_can_add { true }; -}; diff --git a/Servers/DHCPClient/DHCPv4Client.cpp b/Servers/DHCPClient/DHCPv4Client.cpp deleted file mode 100644 index 918a20b93f..0000000000 --- a/Servers/DHCPClient/DHCPv4Client.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DHCPv4Client.h" -#include -#include -#include -#include -#include - -//#define DHCPV4CLIENT_DEBUG - -static void send(const InterfaceDescriptor& iface, const DHCPv4Packet& packet, Core::Object*) -{ - int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (fd < 0) { - dbg() << "ERROR: socket :: " << strerror(errno); - return; - } - - if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface.m_ifname.characters(), IFNAMSIZ) < 0) { - dbg() << "ERROR: setsockopt(SO_BINDTODEVICE) :: " << strerror(errno); - return; - } - - sockaddr_in dst; - memset(&dst, 0, sizeof(dst)); - dst.sin_family = AF_INET; - dst.sin_port = htons(67); - dst.sin_addr.s_addr = IPv4Address { 255, 255, 255, 255 }.to_u32(); - memset(&dst.sin_zero, 0, sizeof(dst.sin_zero)); - - auto rc = sendto(fd, &packet, sizeof(packet), 0, (sockaddr*)&dst, sizeof(dst)); - if (rc < 0) { - dbg() << "sendto failed with " << strerror(errno); - // FIXME: what do we do here? - } -} - -static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4_addr, const IPv4Address& netmask, const IPv4Address& gateway) -{ - int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); - if (fd < 0) { - dbg() << "ERROR: socket :: " << strerror(errno); - return; - } - - struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, iface.m_ifname.characters(), IFNAMSIZ); - - // set the IP address - ifr.ifr_addr.sa_family = AF_INET; - ((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr = ipv4_addr.to_in_addr_t(); - - if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { - dbg() << "ERROR: ioctl(SIOCSIFADDR) :: " << strerror(errno); - } - - // set the network mask - ((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr = netmask.to_in_addr_t(); - - if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) { - dbg() << "ERROR: ioctl(SIOCSIFNETMASK) :: " << strerror(errno); - } - - // set the default gateway - struct rtentry rt; - memset(&rt, 0, sizeof(rt)); - - rt.rt_dev = const_cast(iface.m_ifname.characters()); - rt.rt_gateway.sa_family = AF_INET; - ((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = gateway.to_in_addr_t(); - rt.rt_flags = RTF_UP | RTF_GATEWAY; - - if (ioctl(fd, SIOCADDRT, &rt) < 0) { - dbg() << "Error: ioctl(SIOCADDRT) :: " << strerror(errno); - } -} - -DHCPv4Client::DHCPv4Client(Vector ifnames) - : m_ifnames(ifnames) -{ - m_server = Core::UDPServer::construct(this); - m_server->on_ready_to_receive = [this] { - auto buffer = m_server->receive(sizeof(DHCPv4Packet)); - dbg() << "Received " << buffer.size() << " bytes"; - if (buffer.size() != sizeof(DHCPv4Packet)) { - dbg() << "we expected " << sizeof(DHCPv4Packet) << " bytes, this is a bad packet"; - return; - } - auto& packet = *(DHCPv4Packet*)buffer.data(); - process_incoming(packet); - }; - - if (!m_server->bind({}, 68)) { - dbg() << "The server we just created somehow came already bound, refusing to continue"; - ASSERT_NOT_REACHED(); - } - - for (auto& iface : m_ifnames) - dhcp_discover(iface); -} - -DHCPv4Client::~DHCPv4Client() -{ -} - -void DHCPv4Client::handle_offer(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) -{ - dbg() << "We were offered " << packet.yiaddr().to_string() << " for " << options.get(DHCPOption::IPAddressLeaseTime).value_or(0); - auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); - if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); - return; - } - if (transaction->has_ip) - return; - if (transaction->accepted_offer) { - // we've accepted someone's offer, but they haven't given us an ack - // TODO: maybe record this offer? - return; - } - // TAKE IT... - transaction->offered_lease_time = options.get(DHCPOption::IPAddressLeaseTime).value(); - dhcp_request(*transaction, packet); -} - -void DHCPv4Client::handle_ack(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) -{ -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "The DHCP server handed us " << packet.yiaddr().to_string(); - dbg() << "Here are the options: " << options.to_string(); -#endif - auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); - if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); - return; - } - transaction->has_ip = true; - auto& interface = transaction->interface; - auto new_ip = packet.yiaddr(); - auto lease_time = convert_between_host_and_network(options.get(DHCPOption::IPAddressLeaseTime).value_or(transaction->offered_lease_time)); - // set a timer for the duration of the lease, we shall renew if needed - Core::Timer::create_single_shot( - lease_time * 1000, - [this, transaction, interface = InterfaceDescriptor { interface }, new_ip] { - transaction->accepted_offer = false; - transaction->has_ip = false; - dhcp_discover(interface, new_ip); - }, - this); - set_params(transaction->interface, new_ip, options.get(DHCPOption::SubnetMask).value(), options.get_many(DHCPOption::Router, 1).first()); -} - -void DHCPv4Client::handle_nak(const DHCPv4Packet& packet, const ParsedDHCPv4Options& options) -{ - dbg() << "The DHCP server told us to go chase our own tail about " << packet.yiaddr().to_string(); - dbg() << "Here are the options: " << options.to_string(); - // make another request a bit later :shrug: - auto* transaction = const_cast(m_ongoing_transactions.get(packet.xid()).value_or(nullptr)); - if (!transaction) { - dbg() << "we're not looking for " << packet.xid(); - return; - } - transaction->accepted_offer = false; - transaction->has_ip = false; - auto& iface = transaction->interface; - Core::Timer::create_single_shot( - 10000, - [this, iface = InterfaceDescriptor { iface }] { - dhcp_discover(iface); - }, - this); -} - -void DHCPv4Client::process_incoming(const DHCPv4Packet& packet) -{ - auto options = packet.parse_options(); -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "Here are the options: " << options.to_string(); -#endif - auto value = options.get(DHCPOption::DHCPMessageType).value(); - switch (value) { - case DHCPMessageType::DHCPOffer: - handle_offer(packet, options); - break; - case DHCPMessageType::DHCPAck: - handle_ack(packet, options); - break; - case DHCPMessageType::DHCPNak: - handle_nak(packet, options); - break; - case DHCPMessageType::DHCPDiscover: - case DHCPMessageType::DHCPRequest: - case DHCPMessageType::DHCPRelease: - // These are not for us - // we're just getting them because there are other people on our subnet - // broadcasting stuff - break; - case DHCPMessageType::DHCPDecline: - default: - dbg() << "I dunno what to do with this " << (u8)value; - ASSERT_NOT_REACHED(); - break; - } -} - -void DHCPv4Client::dhcp_discover(const InterfaceDescriptor& iface, IPv4Address previous) -{ - auto transaction_id = rand(); -#ifdef DHCPV4CLIENT_DEBUG - dbg() << "Trying to lease an IP for " << iface.m_ifname << " with ID " << transaction_id; - if (!previous.is_zero()) - dbg() << "going to request the server to hand us " << previous.to_string(); -#endif - DHCPv4PacketBuilder builder; - - DHCPv4Packet& packet = builder.peek(); - packet.set_op(DHCPv4Op::BootRequest); - packet.set_htype(1); // 10mb ethernet - packet.set_hlen(sizeof(MACAddress)); - packet.set_xid(transaction_id); - packet.set_flags(DHCPv4Flags::Broadcast); - packet.ciaddr() = previous; - packet.set_chaddr(iface.m_mac_address); - packet.set_secs(65535); // we lie - - // set packet options - builder.set_message_type(DHCPMessageType::DHCPDiscover); - auto& dhcp_packet = builder.build(); - - // broadcast the discover request - send(iface, dhcp_packet, this); - m_ongoing_transactions.set(transaction_id, make(iface)); -} - -void DHCPv4Client::dhcp_request(DHCPv4Transaction& transaction, const DHCPv4Packet& offer) -{ - auto& iface = transaction.interface; - dbg() << "Leasing the IP " << offer.yiaddr().to_string() << " for adapter " << iface.m_ifname; - DHCPv4PacketBuilder builder; - - DHCPv4Packet& packet = builder.peek(); - packet.set_op(DHCPv4Op::BootRequest); - packet.set_htype(1); // 10mb ethernet - packet.set_hlen(sizeof(MACAddress)); - packet.set_xid(offer.xid()); - packet.set_flags(DHCPv4Flags::Broadcast); - packet.set_chaddr(iface.m_mac_address); - packet.set_secs(65535); // we lie - - // set packet options - builder.set_message_type(DHCPMessageType::DHCPRequest); - auto& dhcp_packet = builder.build(); - - // broadcast the "request" request - send(iface, dhcp_packet, this); - transaction.accepted_offer = true; -} diff --git a/Servers/DHCPClient/DHCPv4Client.h b/Servers/DHCPClient/DHCPv4Client.h deleted file mode 100644 index c45f08f0d1..0000000000 --- a/Servers/DHCPClient/DHCPv4Client.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include "DHCPv4.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct InterfaceDescriptor { - FlyString m_ifname; - MACAddress m_mac_address; -}; - -struct DHCPv4Transaction { - DHCPv4Transaction(InterfaceDescriptor ifname) - : interface(ifname) - { - } - - InterfaceDescriptor interface; - bool accepted_offer { false }; - bool has_ip { false }; - u32 offered_lease_time { 0 }; -}; - -class DHCPv4Client final : public Core::Object { - C_OBJECT(DHCPv4Client) - -public: - explicit DHCPv4Client(Vector ifnames); - virtual ~DHCPv4Client() override; - - void dhcp_discover(const InterfaceDescriptor& ifname, IPv4Address previous = IPv4Address { 0, 0, 0, 0 }); - void dhcp_request(DHCPv4Transaction& transaction, const DHCPv4Packet& packet); - - void process_incoming(const DHCPv4Packet& packet); - - bool id_is_registered(u32 id) { return m_ongoing_transactions.contains(id); } - -private: - HashMap> m_ongoing_transactions; - Vector m_ifnames; - RefPtr m_server; - - void handle_offer(const DHCPv4Packet&, const ParsedDHCPv4Options&); - void handle_ack(const DHCPv4Packet&, const ParsedDHCPv4Options&); - void handle_nak(const DHCPv4Packet&, const ParsedDHCPv4Options&); -}; diff --git a/Servers/DHCPClient/Makefile b/Servers/DHCPClient/Makefile deleted file mode 100644 index ce7c27b86d..0000000000 --- a/Servers/DHCPClient/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -OBJS = \ - DHCPv4.o \ - DHCPv4Client.o \ - main.o - -PROGRAM = DHCPClient - -LIB_DEPS = Core - -include ../../Makefile.common diff --git a/Servers/DHCPClient/main.cpp b/Servers/DHCPClient/main.cpp deleted file mode 100644 index b65b63eb46..0000000000 --- a/Servers/DHCPClient/main.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DHCPv4Client.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static u8 mac_part(const Vector& parts, size_t index) -{ - auto chars = parts.at(index).characters(); - return (chars[0] - '0') * 16 + (chars[1] - '0'); -} - -static MACAddress mac_from_string(const String& str) -{ - auto chunks = str.split(':'); - ASSERT(chunks.size() == 6); // should we...worry about this? - return { - mac_part(chunks, 0), mac_part(chunks, 1), mac_part(chunks, 2), - mac_part(chunks, 3), mac_part(chunks, 4), mac_part(chunks, 5) - }; -} - -int main(int argc, char** argv) -{ - (void)argc; - (void)argv; - - if (pledge("stdio unix inet cpath rpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - Core::EventLoop event_loop; - - if (unveil("/proc/net/", "r") < 0) { - perror("unveil"); - return 1; - } - - unveil(nullptr, nullptr); - - auto file = Core::File::construct("/proc/net/adapters"); - if (!file->open(Core::IODevice::ReadOnly)) { - fprintf(stderr, "Error: %s\n", file->error_string()); - return 1; - } - - auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents).as_array(); - Vector ifnames; - json.for_each([&ifnames](auto& value) { - auto if_object = value.as_object(); - - if (if_object.get("class_name").to_string() == "LoopbackAdapter") - return; - - auto name = if_object.get("name").to_string(); - auto mac = if_object.get("mac_address").to_string(); - ifnames.append({ name, mac_from_string(mac) }); - }); - - auto client = DHCPv4Client::construct(move(ifnames)); - - if (pledge("stdio inet", nullptr) < 0) { - perror("pledge"); - return 1; - } - - return event_loop.exec(); -} diff --git a/Servers/LookupServer/DNSAnswer.cpp b/Servers/LookupServer/DNSAnswer.cpp deleted file mode 100644 index 775c23784e..0000000000 --- a/Servers/LookupServer/DNSAnswer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DNSAnswer.h" -#include - -DNSAnswer::DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data) - : m_name(name) - , m_type(type) - , m_class_code(class_code) - , m_ttl(ttl) - , m_record_data(record_data) -{ - auto now = time(nullptr); - m_expiration_time = now + m_ttl; - if (m_expiration_time < now) - m_expiration_time = 0; -} - -bool DNSAnswer::has_expired() const -{ - return time(nullptr) >= m_expiration_time; -} diff --git a/Servers/LookupServer/DNSAnswer.h b/Servers/LookupServer/DNSAnswer.h deleted file mode 100644 index 794603dd30..0000000000 --- a/Servers/LookupServer/DNSAnswer.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -class DNSAnswer { -public: - DNSAnswer(const String& name, u16 type, u16 class_code, u32 ttl, const String& record_data); - - const String& name() const { return m_name; } - u16 type() const { return m_type; } - u16 class_code() const { return m_class_code; } - u32 ttl() const { return m_ttl; } - const String& record_data() const { return m_record_data; } - - bool has_expired() const; - -private: - String m_name; - u16 m_type { 0 }; - u16 m_class_code { 0 }; - u32 m_ttl { 0 }; - time_t m_expiration_time { 0 }; - String m_record_data; -}; diff --git a/Servers/LookupServer/DNSPacket.h b/Servers/LookupServer/DNSPacket.h deleted file mode 100644 index 832de9b7bb..0000000000 --- a/Servers/LookupServer/DNSPacket.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -class [[gnu::packed]] DNSPacket -{ -public: - DNSPacket() - : m_recursion_desired(false) - , m_truncated(false) - , m_authoritative_answer(false) - , m_opcode(0) - , m_query_or_response(false) - , m_response_code(0) - , m_checking_disabled(false) - , m_authenticated_data(false) - , m_zero(false) - , m_recursion_available(false) - { - } - - u16 id() const { return m_id; } - void set_id(u16 w) { m_id = w; } - - bool recursion_desired() const { return m_recursion_desired; } - void set_recursion_desired(bool b) { m_recursion_desired = b; } - - bool is_truncated() const { return m_truncated; } - void set_truncated(bool b) { m_truncated = b; } - - bool is_authoritative_answer() const { return m_authoritative_answer; } - void set_authoritative_answer(bool b) { m_authoritative_answer = b; } - - u8 opcode() const { return m_opcode; } - void set_opcode(u8 b) { m_opcode = b; } - - bool is_query() const { return !m_query_or_response; } - bool is_response() const { return m_query_or_response; } - void set_is_query() { m_query_or_response = false; } - void set_is_response() { m_query_or_response = true; } - - u8 response_code() const { return m_response_code; } - void set_response_code(u8 b) { m_response_code = b; } - - bool checking_disabled() const { return m_checking_disabled; } - void set_checking_disabled(bool b) { m_checking_disabled = b; } - - bool is_authenticated_data() const { return m_authenticated_data; } - void set_authenticated_data(bool b) { m_authenticated_data = b; } - - bool is_recursion_available() const { return m_recursion_available; } - void set_recursion_available(bool b) { m_recursion_available = b; } - - u16 question_count() const { return m_question_count; } - void set_question_count(u16 w) { m_question_count = w; } - - u16 answer_count() const { return m_answer_count; } - void set_answer_count(u16 w) { m_answer_count = w; } - - u16 authority_count() const { return m_authority_count; } - void set_authority_count(u16 w) { m_authority_count = w; } - - u16 additional_count() const { return m_additional_count; } - void set_additional_count(u16 w) { m_additional_count = w; } - - void* payload() { return this + 1; } - const void* payload() const { return this + 1; } - -private: - NetworkOrdered m_id; - - bool m_recursion_desired : 1; - bool m_truncated : 1; - bool m_authoritative_answer : 1; - u8 m_opcode : 4; - bool m_query_or_response : 1; - u8 m_response_code : 4; - bool m_checking_disabled : 1; - bool m_authenticated_data : 1; - bool m_zero : 1; - bool m_recursion_available : 1; - - NetworkOrdered m_question_count; - NetworkOrdered m_answer_count; - NetworkOrdered m_authority_count; - NetworkOrdered m_additional_count; -}; - -static_assert(sizeof(DNSPacket) == 12); diff --git a/Servers/LookupServer/DNSQuestion.h b/Servers/LookupServer/DNSQuestion.h deleted file mode 100644 index ec696905e6..0000000000 --- a/Servers/LookupServer/DNSQuestion.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -class DNSQuestion { -public: - DNSQuestion(const String& name, u16 record_type, u16 class_code) - : m_name(name) - , m_record_type(record_type) - , m_class_code(class_code) - { - } - - u16 record_type() const { return m_record_type; } - u16 class_code() const { return m_class_code; } - const String& name() const { return m_name; } - - bool operator==(const DNSQuestion& other) const - { - return m_name == other.m_name && m_record_type == other.m_record_type && m_class_code == other.m_class_code; - } - - bool operator!=(const DNSQuestion& other) const - { - return !(*this == other); - } - -private: - String m_name; - u16 m_record_type { 0 }; - u16 m_class_code { 0 }; -}; diff --git a/Servers/LookupServer/DNSRequest.cpp b/Servers/LookupServer/DNSRequest.cpp deleted file mode 100644 index 79d6ff5aec..0000000000 --- a/Servers/LookupServer/DNSRequest.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DNSRequest.h" -#include "DNSPacket.h" -#include -#include -#include -#include -#include - -#define C_IN 1 - -DNSRequest::DNSRequest() - : m_id(arc4random_uniform(UINT16_MAX)) -{ -} - -void DNSRequest::add_question(const String& name, u16 record_type, ShouldRandomizeCase should_randomize_case) -{ - ASSERT(m_questions.size() <= UINT16_MAX); - - if (name.is_empty()) - return; - - StringBuilder builder; - for (size_t i = 0; i < name.length(); ++i) { - u8 ch = name[i]; - if (should_randomize_case == ShouldRandomizeCase::Yes) { - // Randomize the 0x20 bit in every ASCII character. - if (isalpha(ch)) { - if (arc4random_uniform(2)) - ch |= 0x20; - else - ch &= ~0x20; - } - } - builder.append(ch); - } - - if (name[name.length() - 1] != '.') - builder.append('.'); - - m_questions.empend(builder.to_string(), record_type, C_IN); -} - -ByteBuffer DNSRequest::to_byte_buffer() const -{ - DNSPacket request_header; - request_header.set_id(m_id); - request_header.set_is_query(); - request_header.set_opcode(0); - request_header.set_truncated(false); - request_header.set_recursion_desired(true); - request_header.set_question_count(m_questions.size()); - - auto buffer = ByteBuffer::create_uninitialized(m_questions.size() * 4096); - BufferStream stream(buffer); - - stream << ByteBuffer::wrap(&request_header, sizeof(request_header)); - - for (auto& question : m_questions) { - auto parts = question.name().split('.'); - for (auto& part : parts) { - stream << (u8)part.length(); - stream << part; - } - stream << '\0'; - stream << htons(question.record_type()); - stream << htons(question.class_code()); - } - stream.snip(); - - return buffer; -} diff --git a/Servers/LookupServer/DNSRequest.h b/Servers/LookupServer/DNSRequest.h deleted file mode 100644 index 2b55dd75fb..0000000000 --- a/Servers/LookupServer/DNSRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include "DNSQuestion.h" -#include -#include - -#define T_A 1 -#define T_NS 2 -#define T_CNAME 5 -#define T_SOA 6 -#define T_PTR 12 -#define T_MX 15 - -enum class ShouldRandomizeCase { - No = 0, - Yes -}; - -class DNSRequest { -public: - DNSRequest(); - - void add_question(const String& name, u16 record_type, ShouldRandomizeCase); - - const Vector& questions() const { return m_questions; } - - u16 question_count() const - { - ASSERT(m_questions.size() < UINT16_MAX); - return m_questions.size(); - } - - u16 id() const { return m_id; } - ByteBuffer to_byte_buffer() const; - -private: - u16 m_id { 0 }; - Vector m_questions; -}; diff --git a/Servers/LookupServer/DNSResponse.cpp b/Servers/LookupServer/DNSResponse.cpp deleted file mode 100644 index 614e58db2b..0000000000 --- a/Servers/LookupServer/DNSResponse.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "DNSResponse.h" -#include "DNSPacket.h" -#include "DNSRequest.h" -#include -#include - -static String parse_dns_name(const u8* data, size_t& offset, size_t max_offset, size_t recursion_level = 0); - -class [[gnu::packed]] DNSRecordWithoutName -{ -public: - DNSRecordWithoutName() {} - - u16 type() const { return m_type; } - u16 record_class() const { return m_class; } - u32 ttl() const { return m_ttl; } - u16 data_length() const { return m_data_length; } - - void* data() { return this + 1; } - const void* data() const { return this + 1; } - -private: - NetworkOrdered m_type; - NetworkOrdered m_class; - NetworkOrdered m_ttl; - NetworkOrdered m_data_length; -}; - -static_assert(sizeof(DNSRecordWithoutName) == 10); - -Optional DNSResponse::from_raw_response(const u8* raw_data, size_t raw_size) -{ - if (raw_size < sizeof(DNSPacket)) { - dbg() << "DNS response not large enough (" << raw_size << " out of " << sizeof(DNSPacket) << ") to be a DNS packet."; - return {}; - } - - auto& response_header = *(const DNSPacket*)(raw_data); - dbgprintf("Got response (ID: %u)\n", response_header.id()); - dbgprintf(" Question count: %u\n", response_header.question_count()); - dbgprintf(" Answer count: %u\n", response_header.answer_count()); - dbgprintf(" Authority count: %u\n", response_header.authority_count()); - dbgprintf("Additional count: %u\n", response_header.additional_count()); - - DNSResponse response; - response.m_id = response_header.id(); - response.m_code = response_header.response_code(); - - if (response.code() != DNSResponse::Code::NOERROR) - return response; - - size_t offset = sizeof(DNSPacket); - - for (u16 i = 0; i < response_header.question_count(); ++i) { - auto name = parse_dns_name(raw_data, offset, raw_size); - struct RawDNSAnswerQuestion { - NetworkOrdered record_type; - NetworkOrdered class_code; - }; - auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset]; - response.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code); - auto& question = response.m_questions.last(); - offset += 4; - dbg() << "Question #" << i << ": _" << question.name() << "_ type: " << question.record_type() << ", class: " << question.class_code(); - } - - for (u16 i = 0; i < response_header.answer_count(); ++i) { - auto name = parse_dns_name(raw_data, offset, raw_size); - - auto& record = *(const DNSRecordWithoutName*)(&raw_data[offset]); - - String data; - - offset += sizeof(DNSRecordWithoutName); - if (record.type() == T_PTR) { - size_t dummy_offset = offset; - data = parse_dns_name(raw_data, dummy_offset, raw_size); - } else if (record.type() == T_A) { - auto ipv4_address = IPv4Address((const u8*)record.data()); - data = ipv4_address.to_string(); - } else { - // FIXME: Parse some other record types perhaps? - dbg() << " data=(unimplemented record type " << record.type() << ")"; - } - dbg() << "Answer #" << i << ": name=_" << name << "_, type=" << record.type() << ", ttl=" << record.ttl() << ", length=" << record.data_length() << ", data=_" << data << "_"; - response.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data); - offset += record.data_length(); - } - - return response; -} - -String parse_dns_name(const u8* data, size_t& offset, size_t max_offset, size_t recursion_level) -{ - if (recursion_level > 4) - return {}; - Vector buf; - while (offset < max_offset) { - u8 ch = data[offset]; - if (ch == '\0') { - ++offset; - break; - } - if ((ch & 0xc0) == 0xc0) { - if ((offset + 1) >= max_offset) - return {}; - size_t dummy = (ch & 0x3f) << 8 | data[offset + 1]; - offset += 2; - StringBuilder builder; - builder.append(buf.data(), buf.size()); - auto okay = parse_dns_name(data, dummy, max_offset, recursion_level + 1); - builder.append(okay); - return builder.to_string(); - } - for (size_t i = 0; i < ch; ++i) - buf.append(data[offset + i + 1]); - buf.append('.'); - offset += ch + 1; - } - return String::copy(buf); -} diff --git a/Servers/LookupServer/DNSResponse.h b/Servers/LookupServer/DNSResponse.h deleted file mode 100644 index 0301c12075..0000000000 --- a/Servers/LookupServer/DNSResponse.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#pragma once - -#include "DNSAnswer.h" -#include "DNSQuestion.h" -#include -#include -#include - -class DNSResponse { -public: - static Optional from_raw_response(const u8*, size_t); - - u16 id() const { return m_id; } - const Vector& questions() const { return m_questions; } - const Vector& answers() const { return m_answers; } - - u16 question_count() const - { - ASSERT(m_questions.size() <= UINT16_MAX); - return m_questions.size(); - } - - u16 answer_count() const - { - ASSERT(m_answers.size() <= UINT16_MAX); - return m_answers.size(); - } - - enum class Code : u8 { - NOERROR = 0, - FORMERR = 1, - SERVFAIL = 2, - NXDOMAIN = 3, - NOTIMP = 4, - REFUSED = 5, - YXDOMAIN = 6, - XRRSET = 7, - NOTAUTH = 8, - NOTZONE = 9, - }; - - Code code() const { return (Code)m_code; } - -private: - DNSResponse() {} - - u16 m_id { 0 }; - u8 m_code { 0 }; - Vector m_questions; - Vector m_answers; -}; diff --git a/Servers/LookupServer/LookupServer.cpp b/Servers/LookupServer/LookupServer.cpp deleted file mode 100644 index fe89bd97fc..0000000000 --- a/Servers/LookupServer/LookupServer.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "LookupServer.h" -#include "DNSRequest.h" -#include "DNSResponse.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -LookupServer::LookupServer() -{ - auto config = Core::ConfigFile::get_for_system("LookupServer"); - dbg() << "Using network config file at " << config->file_name(); - m_nameserver = config->read_entry("DNS", "Nameserver", "1.1.1.1"); - - load_etc_hosts(); - - m_local_server = Core::LocalServer::construct(this); - m_local_server->on_ready_to_accept = [this]() { - auto socket = m_local_server->accept(); - socket->on_ready_to_read = [this, socket]() { - service_client(socket); - RefPtr keeper = socket; - const_cast(*socket).on_ready_to_read = [] {}; - }; - }; - bool ok = m_local_server->take_over_from_system_server(); - ASSERT(ok); -} - -void LookupServer::load_etc_hosts() -{ - auto file = Core::File::construct("/etc/hosts"); - if (!file->open(Core::IODevice::ReadOnly)) - return; - while (!file->eof()) { - auto line = file->read_line(1024); - if (line.is_empty()) - break; - auto str_line = String((const char*)line.data(), line.size() - 1, Chomp); - auto fields = str_line.split('\t'); - - auto sections = fields[0].split('.'); - IPv4Address addr { - (u8)atoi(sections[0].characters()), - (u8)atoi(sections[1].characters()), - (u8)atoi(sections[2].characters()), - (u8)atoi(sections[3].characters()), - }; - - auto name = fields[1]; - m_etc_hosts.set(name, addr.to_string()); - - IPv4Address reverse_addr { - (u8)atoi(sections[3].characters()), - (u8)atoi(sections[2].characters()), - (u8)atoi(sections[1].characters()), - (u8)atoi(sections[0].characters()), - }; - StringBuilder builder; - builder.append(reverse_addr.to_string()); - builder.append(".in-addr.arpa"); - m_etc_hosts.set(builder.to_string(), name); - } -} - -void LookupServer::service_client(RefPtr socket) -{ - u8 client_buffer[1024]; - int nrecv = socket->read(client_buffer, sizeof(client_buffer) - 1); - if (nrecv < 0) { - perror("read"); - return; - } - - client_buffer[nrecv] = '\0'; - - char lookup_type = client_buffer[0]; - if (lookup_type != 'L' && lookup_type != 'R') { - dbg() << "Invalid lookup_type " << lookup_type; - return; - } - auto hostname = String((const char*)client_buffer + 1, nrecv - 1, Chomp); - dbg() << "Got request for '" << hostname << "' (using IP " << m_nameserver << ")"; - - Vector responses; - - if (auto known_host = m_etc_hosts.get(hostname); known_host.has_value()) { - responses.append(known_host.value()); - } else if (!hostname.is_empty()) { - bool did_timeout; - int retries = 3; - do { - did_timeout = false; - if (lookup_type == 'L') - responses = lookup(hostname, did_timeout, T_A); - else if (lookup_type == 'R') - responses = lookup(hostname, did_timeout, T_PTR); - if (!did_timeout) - break; - } while (--retries); - if (did_timeout) { - fprintf(stderr, "LookupServer: Out of retries :(\n"); - return; - } - } - - if (responses.is_empty()) { - int nsent = socket->write("Not found.\n"); - if (nsent < 0) - perror("write"); - return; - } - for (auto& response : responses) { - auto line = String::format("%s\n", response.characters()); - int nsent = socket->write(line); - if (nsent < 0) { - perror("write"); - break; - } - } -} - -Vector LookupServer::lookup(const String& hostname, bool& did_timeout, unsigned short record_type, ShouldRandomizeCase should_randomize_case) -{ - if (auto it = m_lookup_cache.find(hostname); it != m_lookup_cache.end()) { - auto& cached_lookup = it->value; - if (cached_lookup.question.record_type() == record_type) { - Vector responses; - for (auto& cached_answer : cached_lookup.answers) { - dbg() << "Cache hit: " << hostname << " -> " << cached_answer.record_data() << ", expired: " << cached_answer.has_expired(); - if (!cached_answer.has_expired()) { - responses.append(cached_answer.record_data()); - } - } - if (!responses.is_empty()) - return responses; - } - m_lookup_cache.remove(it); - } - - DNSRequest request; - request.add_question(hostname, record_type, should_randomize_case); - - auto buffer = request.to_byte_buffer(); - - auto udp_socket = Core::UDPSocket::construct(); - udp_socket->set_blocking(true); - - struct timeval timeout { - 1, 0 - }; - - int rc = setsockopt(udp_socket->fd(), SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); - if (rc < 0) { - perror("setsockopt(SOL_SOCKET, SO_RCVTIMEO)"); - return {}; - } - - if (!udp_socket->connect(m_nameserver, 53)) - return {}; - - if (!udp_socket->write(buffer)) - return {}; - - u8 response_buffer[4096]; - int nrecv = udp_socket->read(response_buffer, sizeof(response_buffer)); - if (nrecv == 0) - return {}; - - auto o_response = DNSResponse::from_raw_response(response_buffer, nrecv); - if (!o_response.has_value()) - return {}; - - auto& response = o_response.value(); - - if (response.id() != request.id()) { - dbgprintf("LookupServer: ID mismatch (%u vs %u) :(\n", response.id(), request.id()); - return {}; - } - - if (response.code() == DNSResponse::Code::REFUSED) { - if (should_randomize_case == ShouldRandomizeCase::Yes) { - // Retry with 0x20 case randomization turned off. - return lookup(hostname, did_timeout, record_type, ShouldRandomizeCase::No); - } - return {}; - } - - if (response.question_count() != request.question_count()) { - dbgprintf("LookupServer: Question count (%u vs %u) :(\n", response.question_count(), request.question_count()); - return {}; - } - - for (size_t i = 0; i < request.question_count(); ++i) { - auto& request_question = request.questions()[i]; - auto& response_question = response.questions()[i]; - if (request_question != response_question) { - dbg() << "Request and response questions do not match"; - dbg() << " Request: {_" << request_question.name() << "_, " << request_question.record_type() << ", " << request_question.class_code() << "}"; - dbg() << " Response: {_" << response_question.name() << "_, " << response_question.record_type() << ", " << response_question.class_code() << "}"; - return {}; - } - } - - if (response.answer_count() < 1) { - dbgprintf("LookupServer: Not enough answers (%u) :(\n", response.answer_count()); - return {}; - } - - Vector responses; - Vector cacheable_answers; - for (auto& answer : response.answers()) { - if (answer.type() != T_A) - continue; - responses.append(answer.record_data()); - if (!answer.has_expired()) - cacheable_answers.append(answer); - } - - if (!cacheable_answers.is_empty()) { - if (m_lookup_cache.size() >= 256) - m_lookup_cache.remove(m_lookup_cache.begin()); - m_lookup_cache.set(hostname, { request.questions()[0], move(cacheable_answers) }); - } - return responses; -} diff --git a/Servers/LookupServer/LookupServer.h b/Servers/LookupServer/LookupServer.h deleted file mode 100644 index 4666e0904b..0000000000 --- a/Servers/LookupServer/LookupServer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include "DNSRequest.h" -#include "DNSResponse.h" -#include -#include - -class DNSAnswer; - -class LookupServer final : public Core::Object { - C_OBJECT(LookupServer) - -public: - LookupServer(); - -private: - void load_etc_hosts(); - void service_client(RefPtr); - Vector lookup(const String& hostname, bool& did_timeout, unsigned short record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes); - - struct CachedLookup { - DNSQuestion question; - Vector answers; - }; - - RefPtr m_local_server; - String m_nameserver; - HashMap m_etc_hosts; - HashMap m_lookup_cache; -}; diff --git a/Servers/LookupServer/Makefile b/Servers/LookupServer/Makefile deleted file mode 100644 index 42a4e1930b..0000000000 --- a/Servers/LookupServer/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -OBJS = \ - LookupServer.o \ - DNSRequest.o \ - DNSResponse.o \ - DNSAnswer.o \ - main.o - -PROGRAM = LookupServer - -LIB_DEPS = Core - -include ../../Makefile.common diff --git a/Servers/LookupServer/main.cpp b/Servers/LookupServer/main.cpp deleted file mode 100644 index d8f40e114b..0000000000 --- a/Servers/LookupServer/main.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "LookupServer.h" -#include -#include -#include - -int main(int argc, char** argv) -{ - (void)argc; - (void)argv; - - if (pledge("stdio accept unix inet cpath rpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - Core::EventLoop event_loop; - LookupServer server; - - if (pledge("stdio accept inet", nullptr) < 0) { - perror("pledge"); - return 1; - } - - unveil(nullptr, nullptr); - - return event_loop.exec(); -} diff --git a/Servers/Makefile b/Servers/Makefile deleted file mode 100644 index 0025ae2061..0000000000 --- a/Servers/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS := $(patsubst %/Makefile,%/,$(wildcard */Makefile)) - -include ../Makefile.subdir diff --git a/Servers/NotificationServer/ClientConnection.cpp b/Servers/NotificationServer/ClientConnection.cpp deleted file mode 100644 index 9b8064de03..0000000000 --- a/Servers/NotificationServer/ClientConnection.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ClientConnection.h" -#include "NotificationClientEndpoint.h" -#include "NotificationWindow.h" -#include - -namespace NotificationServer { - -static HashMap> s_connections; - -ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id) - : IPC::ClientConnection(*this, client_socket, client_id) -{ - s_connections.set(client_id, *this); -} - -ClientConnection::~ClientConnection() -{ -} - -void ClientConnection::die() -{ - s_connections.remove(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::NotificationServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message) -{ - auto window = NotificationWindow::construct(message.text(), message.title(), message.icon()); - window->show(); - return make(); -} - -} diff --git a/Servers/NotificationServer/ClientConnection.h b/Servers/NotificationServer/ClientConnection.h deleted file mode 100644 index bec07fb127..0000000000 --- a/Servers/NotificationServer/ClientConnection.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -namespace NotificationServer { - -class ClientConnection final : public IPC::ClientConnection - , public NotificationServerEndpoint { - C_OBJECT(ClientConnection) -public: - ~ClientConnection() override; - - virtual void die() override; - -private: - explicit ClientConnection(Core::LocalSocket&, int client_id); - - virtual OwnPtr handle(const Messages::NotificationServer::Greet&) override; - virtual OwnPtr handle(const Messages::NotificationServer::ShowNotification&) override; -}; - -} diff --git a/Servers/NotificationServer/Makefile b/Servers/NotificationServer/Makefile deleted file mode 100644 index 36a1e41652..0000000000 --- a/Servers/NotificationServer/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -OBJS = \ - main.o \ - ClientConnection.o \ - NotificationWindow.o - -PROGRAM = NotificationServer - -LIB_DEPS = GUI Gfx Core IPC - -EXTRA_CLEAN = NotificationServerEndpoint.h NotificationClientEndpoint.h - -*.cpp: NotificationServerEndpoint.h NotificationClientEndpoint.h - -NotificationServerEndpoint.h: NotificationServer.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -NotificationClientEndpoint.h: NotificationClient.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -install: - mkdir -p $(SERENITY_BASE_DIR)/Root/usr/include/NotificationServer/ - cp *.h $(SERENITY_BASE_DIR)/Root/usr/include/NotificationServer/ - -include ../../Makefile.common diff --git a/Servers/NotificationServer/NotificationClient.ipc b/Servers/NotificationServer/NotificationClient.ipc deleted file mode 100644 index fc85168f76..0000000000 --- a/Servers/NotificationServer/NotificationClient.ipc +++ /dev/null @@ -1,4 +0,0 @@ -endpoint NotificationClient = 92 -{ - Dummy() =| -} diff --git a/Servers/NotificationServer/NotificationServer.ipc b/Servers/NotificationServer/NotificationServer.ipc deleted file mode 100644 index f1ac5e13df..0000000000 --- a/Servers/NotificationServer/NotificationServer.ipc +++ /dev/null @@ -1,7 +0,0 @@ -endpoint NotificationServer = 95 -{ - // Basic protocol - Greet() => (i32 client_id) - - ShowNotification(String text, String title, Gfx::ShareableBitmap icon) => () -} diff --git a/Servers/NotificationServer/NotificationWindow.cpp b/Servers/NotificationServer/NotificationWindow.cpp deleted file mode 100644 index 96b0c2652d..0000000000 --- a/Servers/NotificationServer/NotificationWindow.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "NotificationWindow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace NotificationServer { - -static Vector> s_windows; - -void update_notification_window_locations() -{ - Gfx::Rect last_window_rect; - for (auto& window : s_windows) { - Gfx::Point new_window_location; - if (last_window_rect.is_null()) - new_window_location = GUI::Desktop::the().rect().top_right().translated(-window->rect().width() - 24, 26); - else - new_window_location = last_window_rect.bottom_left().translated(0, 10); - if (window->rect().location() != new_window_location) { - window->move_to(new_window_location); - window->set_original_rect(window->rect()); - } - last_window_rect = window->rect(); - } -} - -NotificationWindow::NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap& icon) -{ - s_windows.append(this); - - set_window_type(GUI::WindowType::Notification); - set_resizable(false); - set_minimizable(false); - - Gfx::Rect lowest_notification_rect_on_screen; - for (auto& window : s_windows) { - if (window->m_original_rect.y() > lowest_notification_rect_on_screen.y()) - lowest_notification_rect_on_screen = window->m_original_rect; - } - - Gfx::Rect rect; - rect.set_width(220); - rect.set_height(40); - rect.set_location(GUI::Desktop::the().rect().top_right().translated(-rect.width() - 24, 26)); - - if (!lowest_notification_rect_on_screen.is_null()) - rect.set_location(lowest_notification_rect_on_screen.bottom_left().translated(0, 10)); - - set_rect(rect); - - m_original_rect = rect; - - auto& widget = set_main_widget(); - widget.set_fill_with_background_color(true); - - widget.set_layout(); - widget.layout()->set_margins({ 8, 8, 8, 8 }); - widget.layout()->set_spacing(6); - - if (icon.is_valid()) { - auto& icon_label = widget.add(); - icon_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); - icon_label.set_preferred_size(32, 32); - icon_label.set_icon(icon.bitmap()); - } - - auto& left_container = widget.add(); - left_container.set_layout(); - - auto& title_label = left_container.add(title); - title_label.set_font(Gfx::Font::default_bold_font()); - title_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); - auto& text_label = left_container.add(text); - text_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); - - auto& right_container = widget.add(); - right_container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - right_container.set_preferred_size(36, 0); - right_container.set_layout(); - - on_close_request = [this] { - s_windows.remove_first_matching([this](auto& entry) { return entry == this; }); - update_notification_window_locations(); - return CloseRequestDecision::Close; - }; -} - -NotificationWindow::~NotificationWindow() -{ -} - -} diff --git a/Servers/NotificationServer/NotificationWindow.h b/Servers/NotificationServer/NotificationWindow.h deleted file mode 100644 index 3519af0752..0000000000 --- a/Servers/NotificationServer/NotificationWindow.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include - -namespace NotificationServer { - -class NotificationWindow final : public GUI::Window { - C_OBJECT(NotificationWindow); - -public: - virtual ~NotificationWindow() override; - void set_original_rect(Gfx::Rect original_rect) { m_original_rect = original_rect; }; - -private: - NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap&); - - Gfx::Rect m_original_rect; -}; - -} diff --git a/Servers/NotificationServer/main.cpp b/Servers/NotificationServer/main.cpp deleted file mode 100644 index f26aeec567..0000000000 --- a/Servers/NotificationServer/main.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "ClientConnection.h" -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - if (pledge("stdio shared_buffer accept rpath wpath cpath unix fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - GUI::Application app(argc, argv); - auto server = Core::LocalServer::construct(); - - bool ok = server->take_over_from_system_server(); - ASSERT(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbg() << "NotificationServer: accept failed."; - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(*client_socket, client_id); - }; - - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - unveil(nullptr, nullptr); - - if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - - return app.exec(); -} diff --git a/Servers/ProtocolServer/Download.cpp b/Servers/ProtocolServer/Download.cpp deleted file mode 100644 index e4bbce082b..0000000000 --- a/Servers/ProtocolServer/Download.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -// FIXME: What about rollover? -static i32 s_next_id = 1; - -static HashMap>& all_downloads() -{ - static HashMap> map; - return map; -} - -Download* Download::find_by_id(i32 id) -{ - return const_cast(all_downloads().get(id).value_or(nullptr)); -} - -Download::Download(PSClientConnection& client) - : m_id(s_next_id++) - , m_client(client.make_weak_ptr()) -{ - all_downloads().set(m_id, this); -} - -Download::~Download() -{ -} - -void Download::stop() -{ - all_downloads().remove(m_id); -} - -void Download::set_payload(const ByteBuffer& payload) -{ - m_payload = payload; - m_total_size = payload.size(); -} - -void Download::set_response_headers(const HashMap& response_headers) -{ - m_response_headers = response_headers; -} - -void Download::did_finish(bool success) -{ - if (!m_client) { - dbg() << "Download::did_finish() after the client already disconnected."; - return; - } - m_client->did_finish_download({}, *this, success); - all_downloads().remove(m_id); -} - -void Download::did_progress(Optional total_size, u32 downloaded_size) -{ - if (!m_client) { - // FIXME: We should also abort the download in this situation, I guess! - dbg() << "Download::did_progress() after the client already disconnected."; - return; - } - m_total_size = total_size; - m_downloaded_size = downloaded_size; - m_client->did_progress_download({}, *this); -} diff --git a/Servers/ProtocolServer/Download.h b/Servers/ProtocolServer/Download.h deleted file mode 100644 index 5609cd15b4..0000000000 --- a/Servers/ProtocolServer/Download.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -class PSClientConnection; - -class Download : public RefCounted { -public: - virtual ~Download(); - - static Download* find_by_id(i32); - - i32 id() const { return m_id; } - URL url() const { return m_url; } - - Optional total_size() const { return m_total_size; } - size_t downloaded_size() const { return m_downloaded_size; } - const ByteBuffer& payload() const { return m_payload; } - const HashMap& response_headers() const { return m_response_headers; } - - void stop(); - -protected: - explicit Download(PSClientConnection&); - - void did_finish(bool success); - void did_progress(Optional total_size, u32 downloaded_size); - void set_payload(const ByteBuffer&); - void set_response_headers(const HashMap&); - -private: - i32 m_id; - URL m_url; - Optional m_total_size {}; - size_t m_downloaded_size { 0 }; - ByteBuffer m_payload; - HashMap m_response_headers; - WeakPtr m_client; -}; diff --git a/Servers/ProtocolServer/HttpDownload.cpp b/Servers/ProtocolServer/HttpDownload.cpp deleted file mode 100644 index 5ffa30362b..0000000000 --- a/Servers/ProtocolServer/HttpDownload.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -HttpDownload::HttpDownload(PSClientConnection& client, NonnullRefPtr&& job) - : Download(client) - , m_job(job) -{ - m_job->on_finish = [this](bool success) { - if (auto* response = m_job->response()) { - set_payload(response->payload()); - set_response_headers(response->headers()); - } - - // if we didn't know the total size, pretend that the download finished successfully - // and set the total size to the downloaded size - if (!total_size().has_value()) - did_progress(downloaded_size(), downloaded_size()); - - did_finish(success); - }; - m_job->on_progress = [this](Optional total, u32 current) { - did_progress(total, current); - }; -} - -HttpDownload::~HttpDownload() -{ -} - -NonnullRefPtr HttpDownload::create_with_job(Badge, PSClientConnection& client, NonnullRefPtr&& job) -{ - return adopt(*new HttpDownload(client, move(job))); -} diff --git a/Servers/ProtocolServer/HttpDownload.h b/Servers/ProtocolServer/HttpDownload.h deleted file mode 100644 index 364fe6aef2..0000000000 --- a/Servers/ProtocolServer/HttpDownload.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include - -class HttpProtocol; - -class HttpDownload final : public Download { -public: - virtual ~HttpDownload() override; - static NonnullRefPtr create_with_job(Badge, PSClientConnection&, NonnullRefPtr&&); - -private: - explicit HttpDownload(PSClientConnection&, NonnullRefPtr&&); - - NonnullRefPtr m_job; -}; diff --git a/Servers/ProtocolServer/HttpProtocol.cpp b/Servers/ProtocolServer/HttpProtocol.cpp deleted file mode 100644 index 1513a32e66..0000000000 --- a/Servers/ProtocolServer/HttpProtocol.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -HttpProtocol::HttpProtocol() - : Protocol("http") -{ -} - -HttpProtocol::~HttpProtocol() -{ -} - -RefPtr HttpProtocol::start_download(PSClientConnection& client, const URL& url) -{ - HTTP::HttpRequest request; - request.set_method(HTTP::HttpRequest::Method::GET); - request.set_url(url); - auto job = request.schedule(); - if (!job) - return nullptr; - return HttpDownload::create_with_job({}, client, (HTTP::HttpJob&)*job); -} diff --git a/Servers/ProtocolServer/HttpProtocol.h b/Servers/ProtocolServer/HttpProtocol.h deleted file mode 100644 index ea6c15d2a4..0000000000 --- a/Servers/ProtocolServer/HttpProtocol.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include - -class HttpProtocol final : public Protocol { -public: - HttpProtocol(); - virtual ~HttpProtocol() override; - - virtual RefPtr start_download(PSClientConnection&, const URL&) override; -}; diff --git a/Servers/ProtocolServer/HttpsDownload.cpp b/Servers/ProtocolServer/HttpsDownload.cpp deleted file mode 100644 index 8e068c2b04..0000000000 --- a/Servers/ProtocolServer/HttpsDownload.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -HttpsDownload::HttpsDownload(PSClientConnection& client, NonnullRefPtr&& job) - : Download(client) - , m_job(job) -{ - m_job->on_finish = [this](bool success) { - if (auto* response = m_job->response()) { - set_payload(response->payload()); - set_response_headers(response->headers()); - } - - // if we didn't know the total size, pretend that the download finished successfully - // and set the total size to the downloaded size - if (!total_size().has_value()) - did_progress(downloaded_size(), downloaded_size()); - - did_finish(success); - }; - m_job->on_progress = [this](Optional total, u32 current) { - did_progress(total, current); - }; -} - -HttpsDownload::~HttpsDownload() -{ -} - -NonnullRefPtr HttpsDownload::create_with_job(Badge, PSClientConnection& client, NonnullRefPtr&& job) -{ - return adopt(*new HttpsDownload(client, move(job))); -} diff --git a/Servers/ProtocolServer/HttpsDownload.h b/Servers/ProtocolServer/HttpsDownload.h deleted file mode 100644 index a6c75bc4d7..0000000000 --- a/Servers/ProtocolServer/HttpsDownload.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include - -class HttpsProtocol; - -class HttpsDownload final : public Download { -public: - virtual ~HttpsDownload() override; - static NonnullRefPtr create_with_job(Badge, PSClientConnection&, NonnullRefPtr&&); - -private: - explicit HttpsDownload(PSClientConnection&, NonnullRefPtr&&); - - NonnullRefPtr m_job; -}; diff --git a/Servers/ProtocolServer/HttpsProtocol.cpp b/Servers/ProtocolServer/HttpsProtocol.cpp deleted file mode 100644 index 07020affe5..0000000000 --- a/Servers/ProtocolServer/HttpsProtocol.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018-2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -HttpsProtocol::HttpsProtocol() - : Protocol("https") -{ -} - -HttpsProtocol::~HttpsProtocol() -{ -} - -RefPtr HttpsProtocol::start_download(PSClientConnection& client, const URL& url) -{ - HTTP::HttpRequest request; - request.set_method(HTTP::HttpRequest::Method::GET); - request.set_url(url); - auto job = HTTP::HttpsJob::construct(request); - auto download = HttpsDownload::create_with_job({}, client, (HTTP::HttpsJob&)*job); - job->start(); - return download; -} diff --git a/Servers/ProtocolServer/HttpsProtocol.h b/Servers/ProtocolServer/HttpsProtocol.h deleted file mode 100644 index e446178751..0000000000 --- a/Servers/ProtocolServer/HttpsProtocol.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018-2020, The SerenityOS developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include - -class HttpsProtocol final : public Protocol { -public: - HttpsProtocol(); - virtual ~HttpsProtocol() override; - - virtual RefPtr start_download(PSClientConnection&, const URL&) override; -}; diff --git a/Servers/ProtocolServer/Makefile b/Servers/ProtocolServer/Makefile deleted file mode 100644 index fa39255c53..0000000000 --- a/Servers/ProtocolServer/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -OBJS = \ - PSClientConnection.o \ - Protocol.o \ - Download.o \ - HttpProtocol.o \ - HttpDownload.o \ - HttpsProtocol.o \ - HttpsDownload.o \ - main.o - -PROGRAM = ProtocolServer - -LIB_DEPS = HTTP TLS Crypto Core IPC - -EXTRA_CLEAN = ProtocolServerEndpoint.h ProtocolClientEndpoint.h - -*.cpp: ProtocolServerEndpoint.h ProtocolClientEndpoint.h - -ProtocolServerEndpoint.h: ProtocolServer.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -ProtocolClientEndpoint.h: ProtocolClient.ipc | IPCCOMPILER - @echo "IPC $<"; $(IPCCOMPILER) $< > $@ - -include ../../Makefile.common diff --git a/Servers/ProtocolServer/PSClientConnection.cpp b/Servers/ProtocolServer/PSClientConnection.cpp deleted file mode 100644 index 1d07fdb8b2..0000000000 --- a/Servers/ProtocolServer/PSClientConnection.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -static HashMap> s_connections; - -PSClientConnection::PSClientConnection(Core::LocalSocket& socket, int client_id) - : IPC::ClientConnection(*this, socket, client_id) -{ - s_connections.set(client_id, *this); -} - -PSClientConnection::~PSClientConnection() -{ -} - -void PSClientConnection::die() -{ - s_connections.remove(client_id()); -} - -OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message) -{ - bool supported = Protocol::find_by_name(message.protocol().to_lowercase()); - return make(supported); -} - -OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::StartDownload& message) -{ - URL url(message.url()); - if (!url.is_valid()) - return make(-1); - auto* protocol = Protocol::find_by_name(url.protocol()); - if (!protocol) - return make(-1); - auto download = protocol->start_download(*this, url); - return make(download->id()); -} - -OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::StopDownload& message) -{ - auto* download = Download::find_by_id(message.download_id()); - bool success = false; - if (download) { - download->stop(); - success = true; - } - return make(success); -} - -void PSClientConnection::did_finish_download(Badge, Download& download, bool success) -{ - RefPtr buffer; - if (success && download.payload().size() > 0 && !download.payload().is_null()) { - buffer = SharedBuffer::create_with_size(download.payload().size()); - memcpy(buffer->data(), download.payload().data(), download.payload().size()); - buffer->seal(); - buffer->share_with(client_pid()); - m_shared_buffers.set(buffer->shbuf_id(), buffer); - } - ASSERT(download.total_size().has_value()); - - IPC::Dictionary response_headers; - for (auto& it : download.response_headers()) - response_headers.add(it.key, it.value); - post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.total_size().value(), buffer ? buffer->shbuf_id() : -1, response_headers)); -} - -void PSClientConnection::did_progress_download(Badge, Download& download) -{ - post_message(Messages::ProtocolClient::DownloadProgress(download.id(), download.total_size(), download.downloaded_size())); -} - -OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr PSClientConnection::handle(const Messages::ProtocolServer::DisownSharedBuffer& message) -{ - m_shared_buffers.remove(message.shbuf_id()); - return make(); -} diff --git a/Servers/ProtocolServer/PSClientConnection.h b/Servers/ProtocolServer/PSClientConnection.h deleted file mode 100644 index 56a7c63c0c..0000000000 --- a/Servers/ProtocolServer/PSClientConnection.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -class Download; - -class PSClientConnection final : public IPC::ClientConnection - , public ProtocolServerEndpoint { - C_OBJECT(PSClientConnection) -public: - explicit PSClientConnection(Core::LocalSocket&, int client_id); - ~PSClientConnection() override; - - virtual void die() override; - - void did_finish_download(Badge, Download&, bool success); - void did_progress_download(Badge, Download&); - -private: - virtual OwnPtr handle(const Messages::ProtocolServer::Greet&) override; - virtual OwnPtr handle(const Messages::ProtocolServer::IsSupportedProtocol&) override; - virtual OwnPtr handle(const Messages::ProtocolServer::StartDownload&) override; - virtual OwnPtr handle(const Messages::ProtocolServer::StopDownload&) override; - virtual OwnPtr handle(const Messages::ProtocolServer::DisownSharedBuffer&) override; - - HashMap> m_shared_buffers; -}; diff --git a/Servers/ProtocolServer/Protocol.cpp b/Servers/ProtocolServer/Protocol.cpp deleted file mode 100644 index bf53895eaa..0000000000 --- a/Servers/ProtocolServer/Protocol.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -static HashMap& all_protocols() -{ - static HashMap map; - return map; -} - -Protocol* Protocol::find_by_name(const String& name) -{ - return all_protocols().get(name).value_or(nullptr); -} - -Protocol::Protocol(const String& name) -{ - all_protocols().set(name, this); -} - -Protocol::~Protocol() -{ - ASSERT_NOT_REACHED(); -} diff --git a/Servers/ProtocolServer/Protocol.h b/Servers/ProtocolServer/Protocol.h deleted file mode 100644 index 19bd38f517..0000000000 --- a/Servers/ProtocolServer/Protocol.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -class Download; -class PSClientConnection; - -class Protocol { -public: - virtual ~Protocol(); - - const String& name() const { return m_name; } - virtual RefPtr start_download(PSClientConnection&, const URL&) = 0; - - static Protocol* find_by_name(const String&); - -protected: - explicit Protocol(const String& name); - -private: - String m_name; -}; diff --git a/Servers/ProtocolServer/ProtocolClient.ipc b/Servers/ProtocolServer/ProtocolClient.ipc deleted file mode 100644 index 575b3ddd2b..0000000000 --- a/Servers/ProtocolServer/ProtocolClient.ipc +++ /dev/null @@ -1,6 +0,0 @@ -endpoint ProtocolClient = 13 -{ - // Download notifications - DownloadProgress(i32 download_id, Optional total_size, u32 downloaded_size) =| - DownloadFinished(i32 download_id, bool success, u32 total_size, i32 shbuf_id, IPC::Dictionary response_headers) =| -} diff --git a/Servers/ProtocolServer/ProtocolServer.ipc b/Servers/ProtocolServer/ProtocolServer.ipc deleted file mode 100644 index 74ec138ab5..0000000000 --- a/Servers/ProtocolServer/ProtocolServer.ipc +++ /dev/null @@ -1,15 +0,0 @@ -endpoint ProtocolServer = 9 -{ - // Basic protocol - Greet() => (i32 client_id) - - // FIXME: It would be nice if the kernel provided a way to avoid this - DisownSharedBuffer(i32 shbuf_id) => () - - // Test if a specific protocol is supported, e.g "http" - IsSupportedProtocol(String protocol) => (bool supported) - - // Download API - StartDownload(String url) => (i32 download_id) - StopDownload(i32 download_id) => (bool success) -} diff --git a/Servers/ProtocolServer/main.cpp b/Servers/ProtocolServer/main.cpp deleted file mode 100644 index 9a3da67b78..0000000000 --- a/Servers/ProtocolServer/main.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -int main(int, char**) -{ - if (pledge("stdio inet shared_buffer accept unix rpath cpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - Core::EventLoop event_loop; - // FIXME: Establish a connection to LookupServer and then drop "unix"? - if (pledge("stdio inet shared_buffer accept unix", nullptr) < 0) { - perror("pledge"); - return 1; - } - if (unveil("/tmp/portal/lookup", "rw") < 0) { - perror("unveil"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - (void)*new HttpProtocol; - (void)*new HttpsProtocol; - auto server = Core::LocalServer::construct(); - bool ok = server->take_over_from_system_server(); - ASSERT(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbg() << "ProtocolServer: accept failed."; - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(*client_socket, client_id); - }; - return event_loop.exec(); -} diff --git a/Servers/SystemServer/Makefile b/Servers/SystemServer/Makefile deleted file mode 100644 index 0a29c53463..0000000000 --- a/Servers/SystemServer/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -OBJS = \ - Service.o \ - main.o - -PROGRAM = SystemServer - -LIB_DEPS = Core - -install: - mkdir -p ../../Root/usr/include/SystemServer/ - cp *.h ../../Root/usr/include/SystemServer/ - -include ../../Makefile.common diff --git a/Servers/SystemServer/Service.cpp b/Servers/SystemServer/Service.cpp deleted file mode 100644 index 1f917ba1e6..0000000000 --- a/Servers/SystemServer/Service.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2019-2020, Sergey Bugaev - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Service.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct UidAndGids { - uid_t uid; - gid_t gid; - Vector extra_gids; -}; - -static HashMap* s_user_map; -static HashMap s_service_map; - -void Service::resolve_user() -{ - if (s_user_map == nullptr) { - s_user_map = new HashMap; - for (struct passwd* passwd = getpwent(); passwd; passwd = getpwent()) { - Vector extra_gids; - for (struct group* group = getgrent(); group; group = getgrent()) { - for (size_t m = 0; group->gr_mem[m]; ++m) { - if (!strcmp(group->gr_mem[m], passwd->pw_name)) - extra_gids.append(group->gr_gid); - } - } - endgrent(); - s_user_map->set(passwd->pw_name, { passwd->pw_uid, passwd->pw_gid, move(extra_gids) }); - } - endpwent(); - } - - auto user = s_user_map->get(m_user); - if (!user.has_value()) { - dbg() << "Failed to resolve user name " << m_user; - ASSERT_NOT_REACHED(); - } - m_uid = user.value().uid; - m_gid = user.value().gid; - m_extra_gids = user.value().extra_gids; -} - -Service* Service::find_by_pid(pid_t pid) -{ - auto it = s_service_map.find(pid); - if (it == s_service_map.end()) - return nullptr; - return (*it).value; -} - -static int ensure_parent_directories(const char* path) -{ - ASSERT(path[0] == '/'); - - char* parent_buffer = strdup(path); - const char* parent = dirname(parent_buffer); - - int rc = 0; - while (true) { - int rc = mkdir(parent, 0755); - - if (rc == 0) - break; - - if (errno != ENOENT) - break; - - ensure_parent_directories(parent); - }; - - free(parent_buffer); - return rc; -} - -void Service::setup_socket() -{ - ASSERT(!m_socket_path.is_null()); - ASSERT(m_socket_fd == -1); - - ensure_parent_directories(m_socket_path.characters()); - - // Note: we use SOCK_CLOEXEC here to make sure we don't leak every socket to - // all the clients. We'll make the one we do need to pass down !CLOEXEC later - // after forking off the process. - m_socket_fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); - if (m_socket_fd < 0) { - perror("socket"); - ASSERT_NOT_REACHED(); - } - - if (fchown(m_socket_fd, m_uid, m_gid) < 0) { - perror("fchown"); - ASSERT_NOT_REACHED(); - } - - if (fchmod(m_socket_fd, m_socket_permissions) < 0) { - perror("fchmod"); - ASSERT_NOT_REACHED(); - } - - auto socket_address = Core::SocketAddress::local(m_socket_path); - auto un = socket_address.to_sockaddr_un(); - int rc = bind(m_socket_fd, (const sockaddr*)&un, sizeof(un)); - if (rc < 0) { - perror("bind"); - ASSERT_NOT_REACHED(); - } - - rc = listen(m_socket_fd, 16); - if (rc < 0) { - perror("listen"); - ASSERT_NOT_REACHED(); - } -} - -void Service::setup_notifier() -{ - ASSERT(m_lazy); - ASSERT(m_socket_fd >= 0); - ASSERT(!m_socket_notifier); - - m_socket_notifier = Core::Notifier::construct(m_socket_fd, Core::Notifier::Event::Read, this); - m_socket_notifier->on_ready_to_read = [this] { - dbg() << "Ready to read on behalf of " << name(); - remove_child(*m_socket_notifier); - m_socket_notifier = nullptr; - spawn(); - }; -} - -void Service::activate() -{ - ASSERT(m_pid < 0); - - if (m_lazy) - setup_notifier(); - else - spawn(); -} - -void Service::spawn() -{ - dbg() << "Spawning " << name(); - - m_run_timer.start(); - m_pid = fork(); - - if (m_pid < 0) { - perror("fork"); - ASSERT_NOT_REACHED(); - } else if (m_pid == 0) { - // We are the child. - - if (!m_working_directory.is_null()) { - if (chdir(m_working_directory.characters()) < 0) { - perror("chdir"); - ASSERT_NOT_REACHED(); - } - } - - struct sched_param p; - p.sched_priority = m_priority; - int rc = sched_setparam(0, &p); - if (rc < 0) { - perror("sched_setparam"); - ASSERT_NOT_REACHED(); - } - - if (!m_stdio_file_path.is_null()) { - close(STDIN_FILENO); - int fd = open_with_path_length(m_stdio_file_path.characters(), m_stdio_file_path.length(), O_RDWR, 0); - ASSERT(fd <= 0); - if (fd < 0) { - perror("open"); - ASSERT_NOT_REACHED(); - } - dup2(STDIN_FILENO, STDOUT_FILENO); - dup2(STDIN_FILENO, STDERR_FILENO); - - if (isatty(STDIN_FILENO)) { - ioctl(STDIN_FILENO, TIOCSCTTY); - } - } else { - if (isatty(STDIN_FILENO)) { - ioctl(STDIN_FILENO, TIOCNOTTY); - } - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - - int fd = open("/dev/null", O_RDWR); - ASSERT(fd == STDIN_FILENO); - dup2(STDIN_FILENO, STDOUT_FILENO); - dup2(STDIN_FILENO, STDERR_FILENO); - } - - if (!m_socket_path.is_null()) { - ASSERT(m_socket_fd > 2); - dup2(m_socket_fd, 3); - // The new descriptor is !CLOEXEC here. - // This is true even if m_socket_fd == 3. - setenv("SOCKET_TAKEOVER", "1", true); - } - - if (!m_user.is_null()) { - if (setgid(m_gid) < 0 || setgroups(m_extra_gids.size(), m_extra_gids.data()) < 0 || setuid(m_uid) < 0) { - dbgprintf("Failed to drop privileges (GID=%u, UID=%u)\n", m_gid, m_uid); - exit(1); - } - } - - char* argv[m_extra_arguments.size() + 2]; - argv[0] = const_cast(m_executable_path.characters()); - for (size_t i = 0; i < m_extra_arguments.size(); i++) - argv[i + 1] = const_cast(m_extra_arguments[i].characters()); - argv[m_extra_arguments.size() + 1] = nullptr; - - rc = execv(argv[0], argv); - perror("exec"); - ASSERT_NOT_REACHED(); - } else { - // We are the parent. - s_service_map.set(m_pid, this); - } -} - -void Service::did_exit(int exit_code) -{ - ASSERT(m_pid > 0); - - dbg() << "Service " << name() << " has exited with exit code " << exit_code; - - s_service_map.remove(m_pid); - m_pid = -1; - - if (!m_keep_alive) - return; - - int run_time_in_msec = m_run_timer.elapsed(); - bool exited_successfully = exit_code == 0; - - if (!exited_successfully && run_time_in_msec < 1000) { - switch (m_restart_attempts) { - case 0: - dbg() << "Trying again"; - break; - case 1: - dbg() << "Third time's a charm?"; - break; - default: - dbg() << "Giving up on " << name() << ". Good luck!"; - return; - } - m_restart_attempts++; - } - - activate(); -} - -Service::Service(const Core::ConfigFile& config, const StringView& name) - : Core::Object(nullptr) -{ - ASSERT(config.has_group(name)); - - set_name(name); - m_executable_path = config.read_entry(name, "Executable", String::format("/bin/%s", this->name().characters())); - m_extra_arguments = config.read_entry(name, "Arguments", "").split(' '); - m_stdio_file_path = config.read_entry(name, "StdIO"); - - String prio = config.read_entry(name, "Priority"); - if (prio == "low") - m_priority = 10; - else if (prio == "normal" || prio.is_null()) - m_priority = 30; - else if (prio == "high") - m_priority = 50; - else - ASSERT_NOT_REACHED(); - - m_keep_alive = config.read_bool_entry(name, "KeepAlive"); - m_lazy = config.read_bool_entry(name, "Lazy"); - - m_user = config.read_entry(name, "User"); - if (!m_user.is_null()) - resolve_user(); - - m_socket_path = config.read_entry(name, "Socket"); - if (!m_socket_path.is_null()) { - auto socket_permissions_string = config.read_entry(name, "SocketPermissions", "0600"); - m_socket_permissions = strtol(socket_permissions_string.characters(), nullptr, 8) & 04777; - setup_socket(); - } - - m_working_directory = config.read_entry(name, "WorkingDirectory"); -} - -void Service::save_to(JsonObject& json) -{ - Core::Object::save_to(json); - - json.set("executable_path", m_executable_path); - - // FIXME: This crashes Inspector. - /* - JsonArray extra_args; - for (String& arg : m_extra_arguments) - extra_args.append(arg); - json.set("extra_arguments", move(extra_args)); - */ - - json.set("stdio_file_path", m_stdio_file_path); - json.set("priority", m_priority); - json.set("keep_alive", m_keep_alive); - json.set("socket_path", m_socket_path); - json.set("socket_permissions", m_socket_permissions); - json.set("lazy", m_lazy); - json.set("user", m_user); - json.set("uid", m_uid); - json.set("gid", m_gid); - - if (m_pid > 0) - json.set("pid", m_pid); - else - json.set("pid", nullptr); - - json.set("restart_attempts", m_restart_attempts); - json.set("working_directory", m_working_directory); -} diff --git a/Servers/SystemServer/Service.h b/Servers/SystemServer/Service.h deleted file mode 100644 index de408ec04d..0000000000 --- a/Servers/SystemServer/Service.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2019-2020, Sergey Bugaev - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include - -class Service final : public Core::Object { - C_OBJECT(Service) - -public: - void activate(); - void did_exit(int exit_code); - - static Service* find_by_pid(pid_t); - - void save_to(AK::JsonObject&) override; - -private: - Service(const Core::ConfigFile&, const StringView& name); - - void spawn(); - - // Path to the executable. By default this is /bin/{m_name}. - String m_executable_path; - // Extra arguments, starting from argv[1], to pass when exec'ing. - Vector m_extra_arguments; - // File path to open as stdio fds. - String m_stdio_file_path; - int m_priority { 1 }; - // Whether we should re-launch it if it exits. - bool m_keep_alive { false }; - // Path to the socket to create and listen on on behalf of this service. - String m_socket_path; - // File system permissions for the socket. - mode_t m_socket_permissions { 0 }; - // Whether we should only spawn this service once somebody connects to the socket. - bool m_lazy; - // The name of the user we should run this service as. - String m_user; - uid_t m_uid { 0 }; - gid_t m_gid { 0 }; - Vector m_extra_gids; - - // PID of the running instance of this service. - pid_t m_pid { -1 }; - // An open fd to the socket. - int m_socket_fd { -1 }; - RefPtr m_socket_notifier; - - // Timer since we last spawned the service. - Core::ElapsedTimer m_run_timer; - // How many times we have tried to restart this service, only counting those - // times where it has exited unsuccessfully and too quickly. - int m_restart_attempts { 0 }; - - // The working directory in which to spawn the service - String m_working_directory; - - void resolve_user(); - void setup_socket(); - void setup_notifier(); -}; diff --git a/Servers/SystemServer/main.cpp b/Servers/SystemServer/main.cpp deleted file mode 100644 index 0d49d0d937..0000000000 --- a/Servers/SystemServer/main.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Service.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void sigchld_handler(int) -{ - int status = 0; - pid_t pid = waitpid(-1, &status, WNOHANG); - if (!pid) - return; - - dbg() << "Reaped child with pid " << pid; - Service* service = Service::find_by_pid(pid); - if (service == nullptr) { - dbg() << "There was no service with this pid, what is going on?"; - return; - } - - // Call service->did_exit(status) some time soon. - // We wouldn't want to run the complex logic, such - // as possibly spawning the service again, from the - // signal handler, so defer it. - Core::EventLoop::main().post_event(*service, make([=](auto&) { - service->did_exit(status); - })); - Core::EventLoop::wake(); -} - -static void check_for_test_mode() -{ - auto f = Core::File::construct("/proc/cmdline"); - if (!f->open(Core::IODevice::ReadOnly)) { - dbg() << "Failed to read command line: " << f->error_string(); - ASSERT(false); - } - const String cmd = String::copy(f->read_all()); - dbg() << "Read command line: " << cmd; - if (cmd.matches("*testmode=1*")) { - // Eventually, we should run a test binary and wait for it to finish - // before shutting down. But this is good enough for now. - dbg() << "Waiting for testmode shutdown..."; - sleep(5); - dbg() << "Shutting down due to testmode..."; - if (fork() == 0) { - execl("/bin/shutdown", "/bin/shutdown", "-n", nullptr); - ASSERT_NOT_REACHED(); - } - } else { - dbg() << "Continuing normally"; - } -} - -static void mount_all_filesystems() -{ - dbg() << "Spawning mount -a to mount all filesystems."; - pid_t pid = fork(); - - if (pid < 0) { - perror("fork"); - ASSERT_NOT_REACHED(); - } else if (pid == 0) { - execl("/bin/mount", "mount", "-a", nullptr); - perror("exec"); - ASSERT_NOT_REACHED(); - } else { - wait(nullptr); - } -} - -int main(int, char**) -{ - if (pledge("stdio proc exec tty accept unix rpath wpath cpath chown fattr id", nullptr) < 0) { - perror("pledge"); - return 1; - } - - mount_all_filesystems(); - - struct sigaction sa = { - .sa_handler = sigchld_handler, - .sa_mask = 0, - .sa_flags = SA_RESTART - }; - sigaction(SIGCHLD, &sa, nullptr); - - Core::EventLoop event_loop; - - // Read our config and instantiate services. - // This takes care of setting up sockets. - NonnullRefPtrVector services; - auto config = Core::ConfigFile::get_for_system("SystemServer"); - for (auto name : config->groups()) - services.append(Service::construct(*config, name)); - - // After we've set them all up, activate them! - for (auto& service : services) - service.activate(); - - // This won't return if we're in test mode. - check_for_test_mode(); - - return event_loop.exec(); -} diff --git a/Servers/TTYServer/Makefile b/Servers/TTYServer/Makefile deleted file mode 100644 index d1eb798683..0000000000 --- a/Servers/TTYServer/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -OBJS = \ - main.o - -PROGRAM = TTYServer - -include ../../Makefile.common diff --git a/Servers/TTYServer/main.cpp b/Servers/TTYServer/main.cpp deleted file mode 100644 index 79e43ca84b..0000000000 --- a/Servers/TTYServer/main.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - if (pledge("stdio tty proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/bin/Shell", "x") < 0) { - perror("unveil"); - return 1; - } - - unveil(nullptr, nullptr); - - if (argc < 2) - return -1; - - dbgprintf("Starting console server on %s\n", argv[1]); - - while (true) { - dbgprintf("Running shell on %s\n", argv[1]); - - auto child = fork(); - if (!child) { - int rc = execl("/bin/Shell", "Shell", nullptr); - ASSERT(rc < 0); - perror("execl"); - exit(127); - } else { - int wstatus; - waitpid(child, &wstatus, 0); - dbgprintf("Shell on %s exited with code %d\n", argv[1], WEXITSTATUS(wstatus)); - } - } -} diff --git a/Servers/TelnetServer/Client.cpp b/Servers/TelnetServer/Client.cpp deleted file mode 100644 index e983025df6..0000000000 --- a/Servers/TelnetServer/Client.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Client.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Client::Client(int id, RefPtr socket, int ptm_fd) - : m_id(id) - , m_socket(move(socket)) - , m_ptm_fd(ptm_fd) - , m_ptm_notifier(Core::Notifier::construct(ptm_fd, Core::Notifier::Read)) -{ - m_socket->on_ready_to_read = [this] { drain_socket(); }; - m_ptm_notifier->on_ready_to_read = [this] { drain_pty(); }; - m_parser.on_command = [this](const Command& command) { handle_command(command); }; - m_parser.on_data = [this](const StringView& data) { handle_data(data); }; - m_parser.on_error = [this]() { handle_error(); }; - send_commands({ - { CMD_WILL, SUB_SUPPRESS_GO_AHEAD }, - { CMD_WILL, SUB_ECHO }, - { CMD_DO, SUB_SUPPRESS_GO_AHEAD }, - { CMD_DONT, SUB_ECHO }, - }); -} - -void Client::drain_socket() -{ - NonnullRefPtr protect(*this); - while (m_socket->can_read()) { - auto buf = m_socket->read(1024); - - m_parser.write(buf); - - if (m_socket->eof()) { - quit(); - break; - } - } -} - -void Client::drain_pty() -{ - u8 buffer[BUFSIZ]; - ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer)); - if (nread < 0) { - perror("read(ptm)"); - quit(); - return; - } - if (nread == 0) { - quit(); - return; - } - send_data(StringView(buffer, (size_t)nread)); -} - -void Client::handle_data(const StringView& data) -{ - write(m_ptm_fd, data.characters_without_null_termination(), data.length()); -} - -void Client::handle_command(const Command& command) -{ - switch (command.command) { - case CMD_DO: - // no response - we've already advertised our options, and none of - // them can be disabled (or re-enabled) after connecting. - break; - case CMD_DONT: - // no response - we only "support" two options (echo and suppres - // go-ahead), and both of them are always enabled. - break; - case CMD_WILL: - switch (command.subcommand) { - case SUB_ECHO: - // we always want to be the ones in control of the output. tell - // the client to disable local echo. - send_command({ CMD_DONT, SUB_ECHO }); - break; - case SUB_SUPPRESS_GO_AHEAD: - send_command({ CMD_DO, SUB_SUPPRESS_GO_AHEAD }); - break; - default: - // don't respond to unknown commands - break; - } - break; - case CMD_WONT: - // no response - we don't care about anything the client says they - // won't do. - break; - } -} - -void Client::handle_error() -{ - quit(); -} - -void Client::send_data(StringView data) -{ - bool fast = true; - for (size_t i = 0; i < data.length(); i++) { - u8 c = data[i]; - if (c == '\n' || c == 0xff) - fast = false; - } - - if (fast) { - m_socket->write(data); - return; - } - - StringBuilder builder; - for (size_t i = 0; i < data.length(); i++) { - u8 c = data[i]; - - switch (c) { - case '\n': - builder.append("\r\n"); - break; - case IAC: - builder.append("\xff\xff"); - break; - default: - builder.append(c); - break; - } - } - - m_socket->write(builder.to_string()); -} - -void Client::send_command(Command command) -{ - send_commands({ command }); -} - -void Client::send_commands(Vector commands) -{ - auto buffer = ByteBuffer::create_uninitialized(commands.size() * 3); - BufferStream stream(buffer); - for (auto& command : commands) - stream << (u8)IAC << command.command << command.subcommand; - stream.snip(); - m_socket->write(buffer.data(), buffer.size()); -} - -void Client::quit() -{ - m_ptm_notifier->set_enabled(false); - close(m_ptm_fd); - m_socket->close(); - if (on_exit) - on_exit(); -} diff --git a/Servers/TelnetServer/Client.h b/Servers/TelnetServer/Client.h deleted file mode 100644 index fe345d38e3..0000000000 --- a/Servers/TelnetServer/Client.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include - -#include "Command.h" -#include "Parser.h" - -class Client : public RefCounted { -public: - static NonnullRefPtr create(int id, RefPtr socket, int ptm_fd) - { - return adopt(*new Client(id, move(socket), ptm_fd)); - } - - Function on_exit; - -protected: - Client(int id, RefPtr socket, int ptm_fd); - - void drain_socket(); - void drain_pty(); - void handle_data(const StringView&); - void handle_command(const Command& command); - void handle_error(); - void send_data(StringView str); - void send_command(Command command); - void send_commands(Vector commands); - void quit(); - -private: - // client id - int m_id { 0 }; - // client resources - RefPtr m_socket; - Parser m_parser; - // pty resources - int m_ptm_fd { -1 }; - RefPtr m_ptm_notifier; -}; diff --git a/Servers/TelnetServer/Command.h b/Servers/TelnetServer/Command.h deleted file mode 100644 index ac696c2111..0000000000 --- a/Servers/TelnetServer/Command.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -#define CMD_WILL 0xfb -#define CMD_WONT 0xfc -#define CMD_DO 0xfd -#define CMD_DONT 0xfe -#define SUB_ECHO 0x01 -#define SUB_SUPPRESS_GO_AHEAD 0x03 - -struct Command { - u8 command; - u8 subcommand; - - String to_string() const - { - StringBuilder builder; - - switch (command) { - case CMD_WILL: - builder.append("WILL"); - break; - case CMD_WONT: - builder.append("WONT"); - break; - case CMD_DO: - builder.append("DO"); - break; - case CMD_DONT: - builder.append("DONT"); - break; - default: - builder.append(String::format("UNKNOWN<%02x>", command)); - break; - } - - builder.append(" "); - - switch (subcommand) { - case SUB_ECHO: - builder.append("ECHO"); - break; - case SUB_SUPPRESS_GO_AHEAD: - builder.append("SUPPRESS_GO_AHEAD"); - break; - default: - builder.append(String::format("UNKNOWN<%02x>")); - break; - } - - return builder.to_string(); - }; -}; diff --git a/Servers/TelnetServer/Makefile b/Servers/TelnetServer/Makefile deleted file mode 100644 index bfee24f38c..0000000000 --- a/Servers/TelnetServer/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -OBJS = \ - Client.o \ - Parser.o \ - main.o - -PROGRAM = TelnetServer - -LIB_DEPS = Core - -include ../../Makefile.common diff --git a/Servers/TelnetServer/Parser.cpp b/Servers/TelnetServer/Parser.cpp deleted file mode 100644 index 9fc1aabcd1..0000000000 --- a/Servers/TelnetServer/Parser.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "Parser.h" - -void Parser::write(const StringView& data) -{ - for (size_t i = 0; i < data.length(); i++) { - u8 ch = data[i]; - - switch (m_state) { - case State::Free: - switch (ch) { - case IAC: - m_state = State::ReadCommand; - break; - case '\r': - if (on_data) - on_data("\n"); - break; - default: - if (on_data) - on_data(StringView(&ch, 1)); - break; - } - break; - case State::ReadCommand: - switch (ch) { - case IAC: { - m_state = State::Free; - if (on_data) - on_data("\xff"); - break; - } - case CMD_WILL: - case CMD_WONT: - case CMD_DO: - case CMD_DONT: - m_command = ch; - m_state = State::ReadSubcommand; - break; - default: - m_state = State::Error; - if (on_error) - on_error(); - break; - } - break; - case State::ReadSubcommand: { - auto command = m_command; - m_command = 0; - m_state = State::Free; - if (on_command) - on_command({ command, ch }); - break; - } - case State::Error: - // ignore everything - break; - } - } -} diff --git a/Servers/TelnetServer/Parser.h b/Servers/TelnetServer/Parser.h deleted file mode 100644 index 64688881df..0000000000 --- a/Servers/TelnetServer/Parser.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include - -#include "Command.h" - -#define IAC 0xff - -class Parser { -public: - Function on_command; - Function on_data; - Function on_error; - - void write(const StringView&); - -protected: - enum State { - Free, - ReadCommand, - ReadSubcommand, - Error, - }; - - void write(const String& str); - -private: - State m_state { State::Free }; - u8 m_command { 0 }; -}; diff --git a/Servers/TelnetServer/main.cpp b/Servers/TelnetServer/main.cpp deleted file mode 100644 index 6acb900b61..0000000000 --- a/Servers/TelnetServer/main.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Client.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void run_command(int ptm_fd, String command) -{ - pid_t pid = fork(); - if (pid == 0) { - const char* tty_name = ptsname(ptm_fd); - if (!tty_name) { - perror("ptsname"); - exit(1); - } - close(ptm_fd); - int pts_fd = open(tty_name, O_RDWR); - if (pts_fd < 0) { - perror("open"); - exit(1); - } - - // NOTE: It's okay if this fails. - (void)ioctl(0, TIOCNOTTY); - - close(0); - close(1); - close(2); - - int rc = dup2(pts_fd, 0); - if (rc < 0) { - perror("dup2"); - exit(1); - } - rc = dup2(pts_fd, 1); - if (rc < 0) { - perror("dup2"); - exit(1); - } - rc = dup2(pts_fd, 2); - if (rc < 0) { - perror("dup2"); - exit(1); - } - rc = close(pts_fd); - if (rc < 0) { - perror("close"); - exit(1); - } - rc = ioctl(0, TIOCSCTTY); - if (rc < 0) { - perror("ioctl(TIOCSCTTY)"); - exit(1); - } - const char* args[4] = { "/bin/Shell", nullptr, nullptr, nullptr }; - if (!command.is_empty()) { - args[1] = "-c"; - args[2] = command.characters(); - } - const char* envs[] = { "TERM=xterm", "PATH=/bin:/usr/bin:/usr/local/bin", nullptr }; - rc = execve("/bin/Shell", const_cast(args), const_cast(envs)); - if (rc < 0) { - perror("execve"); - exit(1); - } - ASSERT_NOT_REACHED(); - } -} - -int main(int argc, char** argv) -{ - Core::EventLoop event_loop; - auto server = Core::TCPServer::construct(); - - int opt; - u16 port = 23; - const char* command = ""; - while ((opt = getopt(argc, argv, "p:c:")) != -1) { - switch (opt) { - case 'p': - port = atoi(optarg); - break; - case 'c': - command = optarg; - break; - default: - fprintf(stderr, "Usage: %s [-p port] [-c command]", argv[0]); - exit(1); - } - } - - if (!server->listen({}, port)) { - perror("listen"); - exit(1); - } - - HashMap> clients; - int next_id = 0; - - server->on_ready_to_accept = [&next_id, &clients, &server, command] { - int id = next_id++; - - auto client_socket = server->accept(); - if (!client_socket) { - perror("accept"); - return; - } - - int ptm_fd = posix_openpt(O_RDWR); - if (ptm_fd < 0) { - perror("posix_openpt"); - client_socket->close(); - return; - } - if (grantpt(ptm_fd) < 0) { - perror("grantpt"); - client_socket->close(); - return; - } - if (unlockpt(ptm_fd) < 0) { - perror("unlockpt"); - client_socket->close(); - return; - } - - run_command(ptm_fd, command); - - auto client = Client::create(id, move(client_socket), ptm_fd); - client->on_exit = [&clients, id] { clients.remove(id); }; - clients.set(id, client); - }; - - int rc = event_loop.exec(); - if (rc != 0) { - fprintf(stderr, "event loop exited badly; rc=%d", rc); - exit(1); - } - - return 0; -} diff --git a/Servers/WebServer/Client.cpp b/Servers/WebServer/Client.cpp deleted file mode 100644 index ae9aedc907..0000000000 --- a/Servers/WebServer/Client.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Client.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace WebServer { - -Client::Client(NonnullRefPtr socket, Core::Object* parent) - : Core::Object(parent) - , m_socket(socket) -{ -} - -void Client::die() -{ - remove_from_parent(); -} - -void Client::start() -{ - m_socket->on_ready_to_read = [this] { - auto raw_request = m_socket->read_all(); - if (raw_request.is_null()) { - die(); - return; - } - - dbg() << "Got raw request: '" << String::copy(raw_request) << "'"; - - handle_request(move(raw_request)); - die(); - }; -} - -void Client::handle_request(ByteBuffer raw_request) -{ - auto request_or_error = HTTP::HttpRequest::from_raw_request(raw_request); - if (!request_or_error.has_value()) - return; - auto& request = request_or_error.value(); - - dbg() << "Got HTTP request: " << request.method_name() << " " << request.resource(); - for (auto& header : request.headers()) { - dbg() << " " << header.name << " => " << header.value; - } - - if (request.method() != HTTP::HttpRequest::Method::GET) { - send_error_response(403, "Forbidden, bro!", request); - return; - } - - auto requested_path = canonicalized_path(request.resource()); - dbg() << "Canonical requested path: '" << requested_path << "'"; - - StringBuilder path_builder; - path_builder.append("/www/"); - path_builder.append(requested_path); - auto real_path = path_builder.to_string(); - - if (Core::File::is_directory(real_path)) { - - if (!request.resource().ends_with("/")) { - StringBuilder red; - - red.append(requested_path); - red.append("/"); - - send_redirect(red.to_string(), request); - return; - } - - StringBuilder index_html_path_builder; - index_html_path_builder.append(real_path); - index_html_path_builder.append("/index.html"); - auto index_html_path = index_html_path_builder.to_string(); - if (!Core::File::exists(index_html_path)) { - handle_directory_listing(requested_path, real_path, request); - return; - } - real_path = index_html_path; - } - - auto file = Core::File::construct(real_path); - if (!file->open(Core::File::ReadOnly)) { - send_error_response(404, "Not found, bro!", request); - return; - } - - send_response(file->read_all(), request); -} - -void Client::send_response(StringView response, const HTTP::HttpRequest& request) -{ - StringBuilder builder; - builder.append("HTTP/1.0 200 OK\r\n"); - builder.append("Server: WebServer (SerenityOS)\r\n"); - builder.append("Content-Type: text/html\r\n"); - builder.append("\r\n"); - - m_socket->write(builder.to_string()); - m_socket->write(response); - - log_response(200, request); -} - -void Client::send_redirect(StringView redirect_path, const HTTP::HttpRequest& request) -{ - StringBuilder builder; - builder.append("HTTP/1.0 301 Moved Permanently\r\n"); - builder.append("Location: "); - builder.append(redirect_path); - builder.append("\r\n"); - builder.append("\r\n"); - - m_socket->write(builder.to_string()); - - log_response(301, request); -} - -void Client::handle_directory_listing(const String& requested_path, const String& real_path, const HTTP::HttpRequest& request) -{ - StringBuilder builder; - - builder.append("\n"); - builder.append("\n"); - builder.append("Index of "); - builder.append(escape_html_entities(requested_path)); - builder.append("\n"); - builder.append("\n"); - builder.append("

Index of "); - builder.append(escape_html_entities(requested_path)); - builder.append("

\n"); - builder.append("
\n"); - builder.append("
\n");
-
-    Core::DirIterator dt(real_path);
-    while (dt.has_next()) {
-        auto name = dt.next_path();
-        builder.append("");
-        builder.append(escape_html_entities(name));
-        builder.append("");
-        for (size_t i = 0; i < (40 - name.length()); ++i)
-            builder.append(' ');
-
-        StringBuilder path_builder;
-        path_builder.append(real_path);
-        path_builder.append('/');
-        path_builder.append(name);
-        struct stat st;
-        memset(&st, 0, sizeof(st));
-        int rc = stat(path_builder.to_string().characters(), &st);
-        if (rc < 0) {
-            perror("stat");
-        }
-        builder.appendf("  %10d", st.st_size);
-        builder.appendf("  ");
-        builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string());
-        builder.append("\n");
-    }
-
-    builder.append("
\n"); - builder.append("
\n"); - builder.append("Generated by WebServer (SerenityOS)\n"); - builder.append("\n"); - builder.append("\n"); - - send_response(builder.to_string(), request); -} - -void Client::send_error_response(unsigned code, const StringView& message, const HTTP::HttpRequest& request) -{ - StringBuilder builder; - builder.appendf("HTTP/1.0 %u ", code); - builder.append(message); - builder.append("\r\n\r\n"); - builder.append("

"); - builder.appendf("%u ", code); - builder.append(message); - builder.append("

"); - m_socket->write(builder.to_string()); - - log_response(code, request); -} - -void Client::log_response(unsigned code, const HTTP::HttpRequest& request) -{ - printf("%s :: %03u :: %s %s\n", - Core::DateTime::now().to_string().characters(), - code, - request.method_name().characters(), - request.resource().characters()); -} - -} diff --git a/Servers/WebServer/Client.h b/Servers/WebServer/Client.h deleted file mode 100644 index 35cdb4ab1c..0000000000 --- a/Servers/WebServer/Client.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -namespace WebServer { - -class Client final : public Core::Object { - C_OBJECT(Client); -public: - void start(); - -private: - Client(NonnullRefPtr, Core::Object* parent); - - void handle_request(ByteBuffer); - void send_response(StringView, const HTTP::HttpRequest&); - void send_redirect(StringView redirect, const HTTP::HttpRequest& request); - void send_error_response(unsigned code, const StringView& message, const HTTP::HttpRequest&); - void die(); - void log_response(unsigned code, const HTTP::HttpRequest&); - void handle_directory_listing(const String& requested_path, const String& real_path, const HTTP::HttpRequest&); - - NonnullRefPtr m_socket; -}; - -} diff --git a/Servers/WebServer/Makefile b/Servers/WebServer/Makefile deleted file mode 100644 index ddc99a85ae..0000000000 --- a/Servers/WebServer/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -OBJS = \ - Client.o \ - main.o - -PROGRAM = WebServer - -LIB_DEPS = HTTP Core - -include ../../Makefile.common diff --git a/Servers/WebServer/main.cpp b/Servers/WebServer/main.cpp deleted file mode 100644 index 7e218b8bb8..0000000000 --- a/Servers/WebServer/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "Client.h" -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - u16 default_port = 8000; - - int port = default_port; - - Core::ArgsParser args_parser; - args_parser.add_positional_argument(port, "Port to listen on", "port", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); - - if ((u16)port != port) { - printf("Warning: invalid port number: %d\n", port); - port = default_port; - } - - if (pledge("stdio accept rpath inet unix cpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - - Core::EventLoop loop; - - auto server = Core::TCPServer::construct(); - - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - ASSERT(client_socket); - auto client = WebServer::Client::construct(client_socket.release_nonnull(), server); - client->start(); - }; - - server->listen({}, port); - printf("Listening on 0.0.0.0:%d\n", port); - - if (unveil("/www", "r") < 0) { - perror("unveil"); - return 1; - } - - unveil(nullptr, nullptr); - - if (pledge("stdio accept rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - - return loop.exec(); -} diff --git a/Servers/WindowServer/AppletManager.cpp b/Servers/WindowServer/AppletManager.cpp deleted file mode 100644 index 855ff3bcd3..0000000000 --- a/Servers/WindowServer/AppletManager.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2020-2020, Hüseyin Aslıtürk - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "AppletManager.h" -#include -#include -#include - -namespace WindowServer { - -static AppletManager* s_the; -Vector order_vector; - -AppletManager::AppletManager() -{ - s_the = this; - - auto wm_config = Core::ConfigFile::open("/etc/WindowServer/WindowServer.ini"); - auto order = wm_config->read_entry("Applet", "Order"); - order_vector = order.split(','); -} - -AppletManager::~AppletManager() -{ -} - -AppletManager& AppletManager::the() -{ - ASSERT(s_the); - return *s_the; -} - -void AppletManager::event(Core::Event& event) -{ - auto& mouse_event = static_cast(event); - - for (auto& applet : m_applets) { - if (!applet) - continue; - if (!applet->rect_in_menubar().contains(mouse_event.position())) - continue; - auto local_event = mouse_event.translated(-applet->rect_in_menubar().location()); - applet->event(local_event); - } -} - -void AppletManager::add_applet(Window& applet) -{ - m_applets.append(applet.make_weak_ptr()); - - // Prune any dead weak pointers from the applet list. - m_applets.remove_all_matching([](auto& entry) { - return entry.is_null(); - }); - - quick_sort(m_applets, [](auto& a, auto& b) { - auto index_a = order_vector.find_first_index(a->title()); - auto index_b = order_vector.find_first_index(b->title()); - return index_a.value_or(0) > index_b.value_or(0); - }); - - calculate_applet_rects(MenuManager::the().window()); -} - -void AppletManager::calculate_applet_rects(Window& window) -{ - auto menubar_rect = window.rect(); - int right_edge_x = menubar_rect.width() - 4; - for (auto& existing_applet : m_applets) { - - Gfx::Rect new_applet_rect(right_edge_x - existing_applet->size().width(), 0, existing_applet->size().width(), existing_applet->size().height()); - Gfx::Rect dummy_menubar_rect(0, 0, 0, 18); - new_applet_rect.center_vertically_within(dummy_menubar_rect); - - existing_applet->set_rect_in_menubar(new_applet_rect); - right_edge_x = existing_applet->rect_in_menubar().x() - 4; - } -} - -void AppletManager::remove_applet(Window& applet) -{ - m_applets.remove_first_matching([&](auto& entry) { - return &applet == entry.ptr(); - }); -} - -void AppletManager::draw() -{ - for (auto& applet : m_applets) { - if (!applet) - continue; - draw_applet(*applet); - } -} - -void AppletManager::draw_applet(const Window& applet) -{ - if (!applet.backing_store()) - return; - - Gfx::Painter painter(*MenuManager::the().window().backing_store()); - painter.fill_rect(applet.rect_in_menubar(), WindowManager::the().palette().window()); - painter.blit(applet.rect_in_menubar().location(), *applet.backing_store(), applet.backing_store()->rect()); -} - -void AppletManager::invalidate_applet(const Window& applet, const Gfx::Rect& rect) -{ - draw_applet(applet); - MenuManager::the().window().invalidate(rect.translated(applet.rect_in_menubar().location())); -} - -} diff --git a/Servers/WindowServer/AppletManager.h b/Servers/WindowServer/AppletManager.h deleted file mode 100644 index 4619fd0030..0000000000 --- a/Servers/WindowServer/AppletManager.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2020-2020, Hüseyin Aslıtürk - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -namespace WindowServer { - -class AppletManager : public Core::Object { - C_OBJECT(AppletManager) -public: - AppletManager(); - ~AppletManager(); - - static AppletManager& the(); - - virtual void event(Core::Event&) override; - - void add_applet(Window& applet); - void remove_applet(Window& applet); - void draw(); - void invalidate_applet(const Window& applet, const Gfx::Rect& rect); - void calculate_applet_rects(Window& window); - -private: - void draw_applet(const Window& applet); - - Vector> m_applets; -}; - -} diff --git a/Servers/WindowServer/Button.cpp b/Servers/WindowServer/Button.cpp deleted file mode 100644 index 95037d4bc8..0000000000 --- a/Servers/WindowServer/Button.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -namespace WindowServer { - -Button::Button(WindowFrame& frame, NonnullRefPtr&& bitmap, Function&& on_click_handler) - : on_click(move(on_click_handler)) - , m_frame(frame) - , m_bitmap(move(bitmap)) -{ -} - -Button::~Button() -{ -} - -void Button::paint(Gfx::Painter& painter) -{ - auto palette = WindowManager::the().palette(); - Gfx::PainterStateSaver saver(painter); - painter.translate(relative_rect().location()); - Gfx::StylePainter::paint_button(painter, rect(), palette, Gfx::ButtonStyle::Normal, m_pressed, m_hovered); - auto x_location = rect().center(); - x_location.move_by(-(m_bitmap->width() / 2), -(m_bitmap->height() / 2)); - if (m_pressed) - x_location.move_by(1, 1); - painter.draw_bitmap(x_location, *m_bitmap, palette.button_text()); -} - -void Button::on_mouse_event(const MouseEvent& event) -{ - auto& wm = WindowManager::the(); - - if (event.type() == Event::MouseDown && event.button() == MouseButton::Left) { - m_pressed = true; - wm.set_cursor_tracking_button(this); - wm.invalidate(screen_rect()); - return; - } - - if (event.type() == Event::MouseUp && event.button() == MouseButton::Left) { - if (wm.cursor_tracking_button() != this) - return; - wm.set_cursor_tracking_button(nullptr); - bool old_pressed = m_pressed; - m_pressed = false; - if (rect().contains(event.position())) { - if (on_click) - on_click(*this); - } - if (old_pressed != m_pressed) { - // Would like to compute: - // m_hovered = rect_after_action().contains(event.position()); - // However, we don't know that rect yet. We can make an educated - // guess which also looks okay even when wrong: - m_hovered = false; - wm.invalidate(screen_rect()); - } - return; - } - - if (event.type() == Event::MouseMove) { - bool old_hovered = m_hovered; - m_hovered = rect().contains(event.position()); - wm.set_hovered_button(m_hovered ? this : nullptr); - if (old_hovered != m_hovered) - wm.invalidate(screen_rect()); - } - - if (event.type() == Event::MouseMove && event.buttons() & (unsigned)MouseButton::Left) { - if (wm.cursor_tracking_button() != this) - return; - bool old_pressed = m_pressed; - m_pressed = m_hovered; - if (old_pressed != m_pressed) - wm.invalidate(screen_rect()); - } -} - -Gfx::Rect Button::screen_rect() const -{ - return m_relative_rect.translated(m_frame.rect().location()); -} - -} diff --git a/Servers/WindowServer/Button.h b/Servers/WindowServer/Button.h deleted file mode 100644 index 555a5d6f9e..0000000000 --- a/Servers/WindowServer/Button.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace WindowServer { - -class MouseEvent; -class WindowFrame; - -class Button : public Weakable