From c7ac7e6eaff862c1ea4f99e0c6ce75e095106d9c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 12 Jan 2021 12:23:01 +0100 Subject: Services: Move to Userland/Services/ --- CMakeLists.txt | 5 +- Meta/CMake/utils.cmake | 2 +- Services/AudioServer/AudioClient.ipc | 6 - Services/AudioServer/AudioServer.ipc | 21 - Services/AudioServer/CMakeLists.txt | 13 - Services/AudioServer/ClientConnection.cpp | 168 --- Services/AudioServer/ClientConnection.h | 75 - Services/AudioServer/Mixer.cpp | 166 --- Services/AudioServer/Mixer.h | 144 -- Services/AudioServer/main.cpp | 63 - Services/CMakeLists.txt | 18 - Services/ChessEngine/CMakeLists.txt | 8 - Services/ChessEngine/ChessEngine.cpp | 76 - Services/ChessEngine/ChessEngine.h | 49 - Services/ChessEngine/MCTSTree.cpp | 180 --- Services/ChessEngine/MCTSTree.h | 67 - Services/ChessEngine/main.cpp | 49 - Services/Clipboard/CMakeLists.txt | 13 - Services/Clipboard/ClientConnection.cpp | 103 -- Services/Clipboard/ClientConnection.h | 60 - Services/Clipboard/ClipboardClient.ipc | 4 - Services/Clipboard/ClipboardServer.ipc | 7 - Services/Clipboard/Storage.cpp | 62 - Services/Clipboard/Storage.h | 73 - Services/Clipboard/main.cpp | 76 - Services/CrashDaemon/CMakeLists.txt | 6 - Services/CrashDaemon/main.cpp | 94 -- Services/DHCPClient/CMakeLists.txt | 8 - Services/DHCPClient/DHCPv4.cpp | 59 - Services/DHCPClient/DHCPv4.h | 299 ---- Services/DHCPClient/DHCPv4Client.cpp | 289 ---- Services/DHCPClient/DHCPv4Client.h | 79 - Services/DHCPClient/main.cpp | 99 -- Services/EchoServer/CMakeLists.txt | 7 - Services/EchoServer/Client.cpp | 58 - Services/EchoServer/Client.h | 49 - Services/EchoServer/main.cpp | 99 -- Services/ImageDecoder/CMakeLists.txt | 12 - Services/ImageDecoder/ClientConnection.cpp | 102 -- Services/ImageDecoder/ClientConnection.h | 56 - Services/ImageDecoder/Forward.h | 34 - Services/ImageDecoder/ImageDecoderClient.ipc | 4 - Services/ImageDecoder/ImageDecoderServer.ipc | 7 - Services/ImageDecoder/main.cpp | 51 - Services/LaunchServer/CMakeLists.txt | 13 - Services/LaunchServer/ClientConnection.cpp | 159 --- Services/LaunchServer/ClientConnection.h | 64 - Services/LaunchServer/LaunchClient.ipc | 4 - Services/LaunchServer/LaunchServer.ipc | 12 - Services/LaunchServer/Launcher.cpp | 309 ---- Services/LaunchServer/Launcher.h | 78 - Services/LaunchServer/main.cpp | 65 - Services/LookupServer/CMakeLists.txt | 10 - Services/LookupServer/DNSAnswer.cpp | 46 - Services/LookupServer/DNSAnswer.h | 51 - Services/LookupServer/DNSPacket.h | 115 -- Services/LookupServer/DNSQuestion.h | 59 - Services/LookupServer/DNSRequest.cpp | 96 -- Services/LookupServer/DNSRequest.h | 65 - Services/LookupServer/DNSResponse.cpp | 152 -- Services/LookupServer/DNSResponse.h | 77 - Services/LookupServer/LookupServer.cpp | 278 ---- Services/LookupServer/LookupServer.h | 56 - Services/LookupServer/main.cpp | 50 - Services/NotificationServer/CMakeLists.txt | 13 - Services/NotificationServer/ClientConnection.cpp | 63 - Services/NotificationServer/ClientConnection.h | 50 - Services/NotificationServer/NotificationClient.ipc | 4 - Services/NotificationServer/NotificationServer.ipc | 7 - Services/NotificationServer/NotificationWindow.cpp | 123 -- Services/NotificationServer/NotificationWindow.h | 48 - Services/NotificationServer/main.cpp | 74 - Services/ProtocolServer/CMakeLists.txt | 20 - Services/ProtocolServer/ClientConnection.cpp | 142 -- Services/ProtocolServer/ClientConnection.h | 63 - Services/ProtocolServer/Download.cpp | 79 - Services/ProtocolServer/Download.h | 81 -- Services/ProtocolServer/Forward.h | 40 - Services/ProtocolServer/GeminiDownload.cpp | 84 -- Services/ProtocolServer/GeminiDownload.h | 49 - Services/ProtocolServer/GeminiProtocol.cpp | 62 - Services/ProtocolServer/GeminiProtocol.h | 41 - Services/ProtocolServer/HttpDownload.cpp | 74 - Services/ProtocolServer/HttpDownload.h | 47 - Services/ProtocolServer/HttpProtocol.cpp | 67 - Services/ProtocolServer/HttpProtocol.h | 41 - Services/ProtocolServer/HttpsDownload.cpp | 82 -- Services/ProtocolServer/HttpsDownload.h | 49 - Services/ProtocolServer/HttpsProtocol.cpp | 67 - Services/ProtocolServer/HttpsProtocol.h | 41 - Services/ProtocolServer/Protocol.cpp | 67 - Services/ProtocolServer/Protocol.h | 57 - Services/ProtocolServer/ProtocolClient.ipc | 10 - Services/ProtocolServer/ProtocolServer.ipc | 13 - Services/ProtocolServer/main.cpp | 69 - Services/SystemMenu/CMakeLists.txt | 7 - Services/SystemMenu/ShutdownDialog.cpp | 117 -- Services/SystemMenu/ShutdownDialog.h | 43 - Services/SystemMenu/main.cpp | 232 --- Services/SystemServer/CMakeLists.txt | 7 - Services/SystemServer/Service.cpp | 376 ----- Services/SystemServer/Service.h | 102 -- Services/SystemServer/main.cpp | 242 ---- Services/Taskbar/CMakeLists.txt | 9 - Services/Taskbar/TaskbarButton.cpp | 162 --- Services/Taskbar/TaskbarButton.h | 48 - Services/Taskbar/TaskbarWindow.cpp | 314 ---- Services/Taskbar/TaskbarWindow.h | 53 - Services/Taskbar/WindowIdentifier.h | 63 - Services/Taskbar/WindowList.cpp | 71 - Services/Taskbar/WindowList.h | 115 -- Services/Taskbar/main.cpp | 57 - Services/TelnetServer/CMakeLists.txt | 8 - Services/TelnetServer/Client.cpp | 190 --- Services/TelnetServer/Client.h | 69 - Services/TelnetServer/Command.h | 82 -- Services/TelnetServer/Parser.cpp | 89 -- Services/TelnetServer/Parser.h | 59 - Services/TelnetServer/main.cpp | 172 --- Services/WebContent/CMakeLists.txt | 13 - Services/WebContent/ClientConnection.cpp | 169 --- Services/WebContent/ClientConnection.h | 76 - Services/WebContent/Documentation.txt | 27 - Services/WebContent/Forward.h | 34 - Services/WebContent/PageHost.cpp | 182 --- Services/WebContent/PageHost.h | 79 - Services/WebContent/WebContentClient.ipc | 18 - Services/WebContent/WebContentServer.ipc | 18 - Services/WebContent/main.cpp | 60 - Services/WebServer/CMakeLists.txt | 7 - Services/WebServer/Client.cpp | 270 ---- Services/WebServer/Client.h | 56 - Services/WebServer/main.cpp | 101 -- Services/WindowServer/AppletManager.cpp | 141 -- Services/WindowServer/AppletManager.h | 56 - Services/WindowServer/Button.cpp | 116 -- Services/WindowServer/Button.h | 69 - Services/WindowServer/CMakeLists.txt | 26 - Services/WindowServer/ClientConnection.cpp | 941 ------------ Services/WindowServer/ClientConnection.h | 170 --- Services/WindowServer/Compositor.cpp | 1040 -------------- Services/WindowServer/Compositor.h | 135 -- Services/WindowServer/Cursor.cpp | 185 --- Services/WindowServer/Cursor.h | 81 -- Services/WindowServer/Event.h | 166 --- Services/WindowServer/EventLoop.cpp | 149 -- Services/WindowServer/EventLoop.h | 57 - Services/WindowServer/Menu.cpp | 568 -------- Services/WindowServer/Menu.h | 169 --- Services/WindowServer/MenuBar.cpp | 55 - Services/WindowServer/MenuBar.h | 61 - Services/WindowServer/MenuItem.cpp | 111 -- Services/WindowServer/MenuItem.h | 104 -- Services/WindowServer/MenuManager.cpp | 497 ------- Services/WindowServer/MenuManager.h | 123 -- Services/WindowServer/Screen.cpp | 186 --- Services/WindowServer/Screen.h | 98 -- Services/WindowServer/Window.cpp | 776 ---------- Services/WindowServer/Window.h | 363 ----- Services/WindowServer/WindowClient.ipc | 42 - Services/WindowServer/WindowFrame.cpp | 382 ----- Services/WindowServer/WindowFrame.h | 81 -- Services/WindowServer/WindowManager.cpp | 1509 -------------------- Services/WindowServer/WindowManager.h | 479 ------- Services/WindowServer/WindowServer.ipc | 117 -- Services/WindowServer/WindowSwitcher.cpp | 257 ---- Services/WindowServer/WindowSwitcher.h | 84 -- Services/WindowServer/WindowType.h | 41 - Services/WindowServer/main.cpp | 119 -- Userland/CMakeLists.txt | 1 + Userland/Services/AudioServer/AudioClient.ipc | 6 + Userland/Services/AudioServer/AudioServer.ipc | 21 + Userland/Services/AudioServer/CMakeLists.txt | 13 + Userland/Services/AudioServer/ClientConnection.cpp | 168 +++ Userland/Services/AudioServer/ClientConnection.h | 75 + Userland/Services/AudioServer/Mixer.cpp | 166 +++ Userland/Services/AudioServer/Mixer.h | 144 ++ Userland/Services/AudioServer/main.cpp | 63 + Userland/Services/CMakeLists.txt | 18 + Userland/Services/ChessEngine/CMakeLists.txt | 8 + Userland/Services/ChessEngine/ChessEngine.cpp | 76 + Userland/Services/ChessEngine/ChessEngine.h | 49 + Userland/Services/ChessEngine/MCTSTree.cpp | 180 +++ Userland/Services/ChessEngine/MCTSTree.h | 67 + Userland/Services/ChessEngine/main.cpp | 49 + Userland/Services/Clipboard/CMakeLists.txt | 13 + Userland/Services/Clipboard/ClientConnection.cpp | 103 ++ Userland/Services/Clipboard/ClientConnection.h | 60 + Userland/Services/Clipboard/ClipboardClient.ipc | 4 + Userland/Services/Clipboard/ClipboardServer.ipc | 7 + Userland/Services/Clipboard/Storage.cpp | 62 + Userland/Services/Clipboard/Storage.h | 73 + Userland/Services/Clipboard/main.cpp | 76 + Userland/Services/CrashDaemon/CMakeLists.txt | 6 + Userland/Services/CrashDaemon/main.cpp | 94 ++ Userland/Services/DHCPClient/CMakeLists.txt | 8 + Userland/Services/DHCPClient/DHCPv4.cpp | 59 + Userland/Services/DHCPClient/DHCPv4.h | 299 ++++ Userland/Services/DHCPClient/DHCPv4Client.cpp | 289 ++++ Userland/Services/DHCPClient/DHCPv4Client.h | 79 + Userland/Services/DHCPClient/main.cpp | 99 ++ Userland/Services/EchoServer/CMakeLists.txt | 7 + Userland/Services/EchoServer/Client.cpp | 58 + Userland/Services/EchoServer/Client.h | 49 + Userland/Services/EchoServer/main.cpp | 99 ++ Userland/Services/ImageDecoder/CMakeLists.txt | 12 + .../Services/ImageDecoder/ClientConnection.cpp | 102 ++ Userland/Services/ImageDecoder/ClientConnection.h | 56 + Userland/Services/ImageDecoder/Forward.h | 34 + .../Services/ImageDecoder/ImageDecoderClient.ipc | 4 + .../Services/ImageDecoder/ImageDecoderServer.ipc | 7 + Userland/Services/ImageDecoder/main.cpp | 51 + Userland/Services/LaunchServer/CMakeLists.txt | 13 + .../Services/LaunchServer/ClientConnection.cpp | 159 +++ Userland/Services/LaunchServer/ClientConnection.h | 64 + Userland/Services/LaunchServer/LaunchClient.ipc | 4 + Userland/Services/LaunchServer/LaunchServer.ipc | 12 + Userland/Services/LaunchServer/Launcher.cpp | 309 ++++ Userland/Services/LaunchServer/Launcher.h | 78 + Userland/Services/LaunchServer/main.cpp | 65 + Userland/Services/LookupServer/CMakeLists.txt | 10 + Userland/Services/LookupServer/DNSAnswer.cpp | 46 + Userland/Services/LookupServer/DNSAnswer.h | 51 + Userland/Services/LookupServer/DNSPacket.h | 115 ++ Userland/Services/LookupServer/DNSQuestion.h | 59 + Userland/Services/LookupServer/DNSRequest.cpp | 96 ++ Userland/Services/LookupServer/DNSRequest.h | 65 + Userland/Services/LookupServer/DNSResponse.cpp | 152 ++ Userland/Services/LookupServer/DNSResponse.h | 77 + Userland/Services/LookupServer/LookupServer.cpp | 278 ++++ Userland/Services/LookupServer/LookupServer.h | 56 + Userland/Services/LookupServer/main.cpp | 50 + .../Services/NotificationServer/CMakeLists.txt | 13 + .../NotificationServer/ClientConnection.cpp | 63 + .../Services/NotificationServer/ClientConnection.h | 50 + .../NotificationServer/NotificationClient.ipc | 4 + .../NotificationServer/NotificationServer.ipc | 7 + .../NotificationServer/NotificationWindow.cpp | 123 ++ .../NotificationServer/NotificationWindow.h | 48 + Userland/Services/NotificationServer/main.cpp | 74 + Userland/Services/ProtocolServer/CMakeLists.txt | 20 + .../Services/ProtocolServer/ClientConnection.cpp | 142 ++ .../Services/ProtocolServer/ClientConnection.h | 63 + Userland/Services/ProtocolServer/Download.cpp | 79 + Userland/Services/ProtocolServer/Download.h | 81 ++ Userland/Services/ProtocolServer/Forward.h | 40 + .../Services/ProtocolServer/GeminiDownload.cpp | 84 ++ Userland/Services/ProtocolServer/GeminiDownload.h | 49 + .../Services/ProtocolServer/GeminiProtocol.cpp | 62 + Userland/Services/ProtocolServer/GeminiProtocol.h | 41 + Userland/Services/ProtocolServer/HttpDownload.cpp | 74 + Userland/Services/ProtocolServer/HttpDownload.h | 47 + Userland/Services/ProtocolServer/HttpProtocol.cpp | 67 + Userland/Services/ProtocolServer/HttpProtocol.h | 41 + Userland/Services/ProtocolServer/HttpsDownload.cpp | 82 ++ Userland/Services/ProtocolServer/HttpsDownload.h | 49 + Userland/Services/ProtocolServer/HttpsProtocol.cpp | 67 + Userland/Services/ProtocolServer/HttpsProtocol.h | 41 + Userland/Services/ProtocolServer/Protocol.cpp | 67 + Userland/Services/ProtocolServer/Protocol.h | 57 + .../Services/ProtocolServer/ProtocolClient.ipc | 10 + .../Services/ProtocolServer/ProtocolServer.ipc | 13 + Userland/Services/ProtocolServer/main.cpp | 69 + Userland/Services/SystemMenu/CMakeLists.txt | 7 + Userland/Services/SystemMenu/ShutdownDialog.cpp | 117 ++ Userland/Services/SystemMenu/ShutdownDialog.h | 43 + Userland/Services/SystemMenu/main.cpp | 232 +++ Userland/Services/SystemServer/CMakeLists.txt | 7 + Userland/Services/SystemServer/Service.cpp | 376 +++++ Userland/Services/SystemServer/Service.h | 102 ++ Userland/Services/SystemServer/main.cpp | 242 ++++ Userland/Services/Taskbar/CMakeLists.txt | 9 + Userland/Services/Taskbar/TaskbarButton.cpp | 162 +++ Userland/Services/Taskbar/TaskbarButton.h | 48 + Userland/Services/Taskbar/TaskbarWindow.cpp | 314 ++++ Userland/Services/Taskbar/TaskbarWindow.h | 53 + Userland/Services/Taskbar/WindowIdentifier.h | 63 + Userland/Services/Taskbar/WindowList.cpp | 71 + Userland/Services/Taskbar/WindowList.h | 115 ++ Userland/Services/Taskbar/main.cpp | 57 + Userland/Services/TelnetServer/CMakeLists.txt | 8 + Userland/Services/TelnetServer/Client.cpp | 190 +++ Userland/Services/TelnetServer/Client.h | 69 + Userland/Services/TelnetServer/Command.h | 82 ++ Userland/Services/TelnetServer/Parser.cpp | 89 ++ Userland/Services/TelnetServer/Parser.h | 59 + Userland/Services/TelnetServer/main.cpp | 172 +++ Userland/Services/WebContent/CMakeLists.txt | 13 + Userland/Services/WebContent/ClientConnection.cpp | 169 +++ Userland/Services/WebContent/ClientConnection.h | 76 + Userland/Services/WebContent/Documentation.txt | 27 + Userland/Services/WebContent/Forward.h | 34 + Userland/Services/WebContent/PageHost.cpp | 182 +++ Userland/Services/WebContent/PageHost.h | 79 + Userland/Services/WebContent/WebContentClient.ipc | 18 + Userland/Services/WebContent/WebContentServer.ipc | 18 + Userland/Services/WebContent/main.cpp | 60 + Userland/Services/WebServer/CMakeLists.txt | 7 + Userland/Services/WebServer/Client.cpp | 270 ++++ Userland/Services/WebServer/Client.h | 56 + Userland/Services/WebServer/main.cpp | 101 ++ Userland/Services/WindowServer/AppletManager.cpp | 141 ++ Userland/Services/WindowServer/AppletManager.h | 56 + Userland/Services/WindowServer/Button.cpp | 116 ++ Userland/Services/WindowServer/Button.h | 69 + Userland/Services/WindowServer/CMakeLists.txt | 26 + .../Services/WindowServer/ClientConnection.cpp | 941 ++++++++++++ Userland/Services/WindowServer/ClientConnection.h | 170 +++ Userland/Services/WindowServer/Compositor.cpp | 1040 ++++++++++++++ Userland/Services/WindowServer/Compositor.h | 135 ++ Userland/Services/WindowServer/Cursor.cpp | 185 +++ Userland/Services/WindowServer/Cursor.h | 81 ++ Userland/Services/WindowServer/Event.h | 166 +++ Userland/Services/WindowServer/EventLoop.cpp | 149 ++ Userland/Services/WindowServer/EventLoop.h | 57 + Userland/Services/WindowServer/Menu.cpp | 568 ++++++++ Userland/Services/WindowServer/Menu.h | 169 +++ Userland/Services/WindowServer/MenuBar.cpp | 55 + Userland/Services/WindowServer/MenuBar.h | 61 + Userland/Services/WindowServer/MenuItem.cpp | 111 ++ Userland/Services/WindowServer/MenuItem.h | 104 ++ Userland/Services/WindowServer/MenuManager.cpp | 497 +++++++ Userland/Services/WindowServer/MenuManager.h | 123 ++ Userland/Services/WindowServer/Screen.cpp | 186 +++ Userland/Services/WindowServer/Screen.h | 98 ++ Userland/Services/WindowServer/Window.cpp | 776 ++++++++++ Userland/Services/WindowServer/Window.h | 363 +++++ Userland/Services/WindowServer/WindowClient.ipc | 42 + Userland/Services/WindowServer/WindowFrame.cpp | 382 +++++ Userland/Services/WindowServer/WindowFrame.h | 81 ++ Userland/Services/WindowServer/WindowManager.cpp | 1509 ++++++++++++++++++++ Userland/Services/WindowServer/WindowManager.h | 479 +++++++ Userland/Services/WindowServer/WindowServer.ipc | 117 ++ Userland/Services/WindowServer/WindowSwitcher.cpp | 257 ++++ Userland/Services/WindowServer/WindowSwitcher.h | 84 ++ Userland/Services/WindowServer/WindowType.h | 41 + Userland/Services/WindowServer/main.cpp | 119 ++ 337 files changed, 19754 insertions(+), 19754 deletions(-) delete mode 100644 Services/AudioServer/AudioClient.ipc delete mode 100644 Services/AudioServer/AudioServer.ipc delete mode 100644 Services/AudioServer/CMakeLists.txt delete mode 100644 Services/AudioServer/ClientConnection.cpp delete mode 100644 Services/AudioServer/ClientConnection.h delete mode 100644 Services/AudioServer/Mixer.cpp delete mode 100644 Services/AudioServer/Mixer.h delete mode 100644 Services/AudioServer/main.cpp delete mode 100644 Services/CMakeLists.txt delete mode 100644 Services/ChessEngine/CMakeLists.txt delete mode 100644 Services/ChessEngine/ChessEngine.cpp delete mode 100644 Services/ChessEngine/ChessEngine.h delete mode 100644 Services/ChessEngine/MCTSTree.cpp delete mode 100644 Services/ChessEngine/MCTSTree.h delete mode 100644 Services/ChessEngine/main.cpp delete mode 100644 Services/Clipboard/CMakeLists.txt delete mode 100644 Services/Clipboard/ClientConnection.cpp delete mode 100644 Services/Clipboard/ClientConnection.h delete mode 100644 Services/Clipboard/ClipboardClient.ipc delete mode 100644 Services/Clipboard/ClipboardServer.ipc delete mode 100644 Services/Clipboard/Storage.cpp delete mode 100644 Services/Clipboard/Storage.h delete mode 100644 Services/Clipboard/main.cpp delete mode 100644 Services/CrashDaemon/CMakeLists.txt delete mode 100644 Services/CrashDaemon/main.cpp delete mode 100644 Services/DHCPClient/CMakeLists.txt delete mode 100644 Services/DHCPClient/DHCPv4.cpp delete mode 100644 Services/DHCPClient/DHCPv4.h delete mode 100644 Services/DHCPClient/DHCPv4Client.cpp delete mode 100644 Services/DHCPClient/DHCPv4Client.h delete mode 100644 Services/DHCPClient/main.cpp delete mode 100644 Services/EchoServer/CMakeLists.txt delete mode 100644 Services/EchoServer/Client.cpp delete mode 100644 Services/EchoServer/Client.h delete mode 100644 Services/EchoServer/main.cpp delete mode 100644 Services/ImageDecoder/CMakeLists.txt delete mode 100644 Services/ImageDecoder/ClientConnection.cpp delete mode 100644 Services/ImageDecoder/ClientConnection.h delete mode 100644 Services/ImageDecoder/Forward.h delete mode 100644 Services/ImageDecoder/ImageDecoderClient.ipc delete mode 100644 Services/ImageDecoder/ImageDecoderServer.ipc delete mode 100644 Services/ImageDecoder/main.cpp delete mode 100644 Services/LaunchServer/CMakeLists.txt delete mode 100644 Services/LaunchServer/ClientConnection.cpp delete mode 100644 Services/LaunchServer/ClientConnection.h delete mode 100644 Services/LaunchServer/LaunchClient.ipc delete mode 100644 Services/LaunchServer/LaunchServer.ipc delete mode 100644 Services/LaunchServer/Launcher.cpp delete mode 100644 Services/LaunchServer/Launcher.h delete mode 100644 Services/LaunchServer/main.cpp delete mode 100644 Services/LookupServer/CMakeLists.txt delete mode 100644 Services/LookupServer/DNSAnswer.cpp delete mode 100644 Services/LookupServer/DNSAnswer.h delete mode 100644 Services/LookupServer/DNSPacket.h delete mode 100644 Services/LookupServer/DNSQuestion.h delete mode 100644 Services/LookupServer/DNSRequest.cpp delete mode 100644 Services/LookupServer/DNSRequest.h delete mode 100644 Services/LookupServer/DNSResponse.cpp delete mode 100644 Services/LookupServer/DNSResponse.h delete mode 100644 Services/LookupServer/LookupServer.cpp delete mode 100644 Services/LookupServer/LookupServer.h delete mode 100644 Services/LookupServer/main.cpp delete mode 100644 Services/NotificationServer/CMakeLists.txt delete mode 100644 Services/NotificationServer/ClientConnection.cpp delete mode 100644 Services/NotificationServer/ClientConnection.h delete mode 100644 Services/NotificationServer/NotificationClient.ipc delete mode 100644 Services/NotificationServer/NotificationServer.ipc delete mode 100644 Services/NotificationServer/NotificationWindow.cpp delete mode 100644 Services/NotificationServer/NotificationWindow.h delete mode 100644 Services/NotificationServer/main.cpp delete mode 100644 Services/ProtocolServer/CMakeLists.txt delete mode 100644 Services/ProtocolServer/ClientConnection.cpp delete mode 100644 Services/ProtocolServer/ClientConnection.h delete mode 100644 Services/ProtocolServer/Download.cpp delete mode 100644 Services/ProtocolServer/Download.h delete mode 100644 Services/ProtocolServer/Forward.h delete mode 100644 Services/ProtocolServer/GeminiDownload.cpp delete mode 100644 Services/ProtocolServer/GeminiDownload.h delete mode 100644 Services/ProtocolServer/GeminiProtocol.cpp delete mode 100644 Services/ProtocolServer/GeminiProtocol.h delete mode 100644 Services/ProtocolServer/HttpDownload.cpp delete mode 100644 Services/ProtocolServer/HttpDownload.h delete mode 100644 Services/ProtocolServer/HttpProtocol.cpp delete mode 100644 Services/ProtocolServer/HttpProtocol.h delete mode 100644 Services/ProtocolServer/HttpsDownload.cpp delete mode 100644 Services/ProtocolServer/HttpsDownload.h delete mode 100644 Services/ProtocolServer/HttpsProtocol.cpp delete mode 100644 Services/ProtocolServer/HttpsProtocol.h delete mode 100644 Services/ProtocolServer/Protocol.cpp delete mode 100644 Services/ProtocolServer/Protocol.h delete mode 100644 Services/ProtocolServer/ProtocolClient.ipc delete mode 100644 Services/ProtocolServer/ProtocolServer.ipc delete mode 100644 Services/ProtocolServer/main.cpp delete mode 100644 Services/SystemMenu/CMakeLists.txt delete mode 100644 Services/SystemMenu/ShutdownDialog.cpp delete mode 100644 Services/SystemMenu/ShutdownDialog.h delete mode 100644 Services/SystemMenu/main.cpp delete mode 100644 Services/SystemServer/CMakeLists.txt delete mode 100644 Services/SystemServer/Service.cpp delete mode 100644 Services/SystemServer/Service.h delete mode 100644 Services/SystemServer/main.cpp delete mode 100644 Services/Taskbar/CMakeLists.txt delete mode 100644 Services/Taskbar/TaskbarButton.cpp delete mode 100644 Services/Taskbar/TaskbarButton.h delete mode 100644 Services/Taskbar/TaskbarWindow.cpp delete mode 100644 Services/Taskbar/TaskbarWindow.h delete mode 100644 Services/Taskbar/WindowIdentifier.h delete mode 100644 Services/Taskbar/WindowList.cpp delete mode 100644 Services/Taskbar/WindowList.h delete mode 100644 Services/Taskbar/main.cpp delete mode 100644 Services/TelnetServer/CMakeLists.txt delete mode 100644 Services/TelnetServer/Client.cpp delete mode 100644 Services/TelnetServer/Client.h delete mode 100644 Services/TelnetServer/Command.h delete mode 100644 Services/TelnetServer/Parser.cpp delete mode 100644 Services/TelnetServer/Parser.h delete mode 100644 Services/TelnetServer/main.cpp delete mode 100644 Services/WebContent/CMakeLists.txt delete mode 100644 Services/WebContent/ClientConnection.cpp delete mode 100644 Services/WebContent/ClientConnection.h delete mode 100644 Services/WebContent/Documentation.txt delete mode 100644 Services/WebContent/Forward.h delete mode 100644 Services/WebContent/PageHost.cpp delete mode 100644 Services/WebContent/PageHost.h delete mode 100644 Services/WebContent/WebContentClient.ipc delete mode 100644 Services/WebContent/WebContentServer.ipc delete mode 100644 Services/WebContent/main.cpp delete mode 100644 Services/WebServer/CMakeLists.txt delete mode 100644 Services/WebServer/Client.cpp delete mode 100644 Services/WebServer/Client.h delete mode 100644 Services/WebServer/main.cpp delete mode 100644 Services/WindowServer/AppletManager.cpp delete mode 100644 Services/WindowServer/AppletManager.h delete mode 100644 Services/WindowServer/Button.cpp delete mode 100644 Services/WindowServer/Button.h delete mode 100644 Services/WindowServer/CMakeLists.txt delete mode 100644 Services/WindowServer/ClientConnection.cpp delete mode 100644 Services/WindowServer/ClientConnection.h delete mode 100644 Services/WindowServer/Compositor.cpp delete mode 100644 Services/WindowServer/Compositor.h delete mode 100644 Services/WindowServer/Cursor.cpp delete mode 100644 Services/WindowServer/Cursor.h delete mode 100644 Services/WindowServer/Event.h delete mode 100644 Services/WindowServer/EventLoop.cpp delete mode 100644 Services/WindowServer/EventLoop.h delete mode 100644 Services/WindowServer/Menu.cpp delete mode 100644 Services/WindowServer/Menu.h delete mode 100644 Services/WindowServer/MenuBar.cpp delete mode 100644 Services/WindowServer/MenuBar.h delete mode 100644 Services/WindowServer/MenuItem.cpp delete mode 100644 Services/WindowServer/MenuItem.h delete mode 100644 Services/WindowServer/MenuManager.cpp delete mode 100644 Services/WindowServer/MenuManager.h delete mode 100644 Services/WindowServer/Screen.cpp delete mode 100644 Services/WindowServer/Screen.h delete mode 100644 Services/WindowServer/Window.cpp delete mode 100644 Services/WindowServer/Window.h delete mode 100644 Services/WindowServer/WindowClient.ipc delete mode 100644 Services/WindowServer/WindowFrame.cpp delete mode 100644 Services/WindowServer/WindowFrame.h delete mode 100644 Services/WindowServer/WindowManager.cpp delete mode 100644 Services/WindowServer/WindowManager.h delete mode 100644 Services/WindowServer/WindowServer.ipc delete mode 100644 Services/WindowServer/WindowSwitcher.cpp delete mode 100644 Services/WindowServer/WindowSwitcher.h delete mode 100644 Services/WindowServer/WindowType.h delete mode 100644 Services/WindowServer/main.cpp create mode 100644 Userland/Services/AudioServer/AudioClient.ipc create mode 100644 Userland/Services/AudioServer/AudioServer.ipc create mode 100644 Userland/Services/AudioServer/CMakeLists.txt create mode 100644 Userland/Services/AudioServer/ClientConnection.cpp create mode 100644 Userland/Services/AudioServer/ClientConnection.h create mode 100644 Userland/Services/AudioServer/Mixer.cpp create mode 100644 Userland/Services/AudioServer/Mixer.h create mode 100644 Userland/Services/AudioServer/main.cpp create mode 100644 Userland/Services/CMakeLists.txt create mode 100644 Userland/Services/ChessEngine/CMakeLists.txt create mode 100644 Userland/Services/ChessEngine/ChessEngine.cpp create mode 100644 Userland/Services/ChessEngine/ChessEngine.h create mode 100644 Userland/Services/ChessEngine/MCTSTree.cpp create mode 100644 Userland/Services/ChessEngine/MCTSTree.h create mode 100644 Userland/Services/ChessEngine/main.cpp create mode 100644 Userland/Services/Clipboard/CMakeLists.txt create mode 100644 Userland/Services/Clipboard/ClientConnection.cpp create mode 100644 Userland/Services/Clipboard/ClientConnection.h create mode 100644 Userland/Services/Clipboard/ClipboardClient.ipc create mode 100644 Userland/Services/Clipboard/ClipboardServer.ipc create mode 100644 Userland/Services/Clipboard/Storage.cpp create mode 100644 Userland/Services/Clipboard/Storage.h create mode 100644 Userland/Services/Clipboard/main.cpp create mode 100644 Userland/Services/CrashDaemon/CMakeLists.txt create mode 100644 Userland/Services/CrashDaemon/main.cpp create mode 100644 Userland/Services/DHCPClient/CMakeLists.txt create mode 100644 Userland/Services/DHCPClient/DHCPv4.cpp create mode 100644 Userland/Services/DHCPClient/DHCPv4.h create mode 100644 Userland/Services/DHCPClient/DHCPv4Client.cpp create mode 100644 Userland/Services/DHCPClient/DHCPv4Client.h create mode 100644 Userland/Services/DHCPClient/main.cpp create mode 100644 Userland/Services/EchoServer/CMakeLists.txt create mode 100644 Userland/Services/EchoServer/Client.cpp create mode 100644 Userland/Services/EchoServer/Client.h create mode 100644 Userland/Services/EchoServer/main.cpp create mode 100644 Userland/Services/ImageDecoder/CMakeLists.txt create mode 100644 Userland/Services/ImageDecoder/ClientConnection.cpp create mode 100644 Userland/Services/ImageDecoder/ClientConnection.h create mode 100644 Userland/Services/ImageDecoder/Forward.h create mode 100644 Userland/Services/ImageDecoder/ImageDecoderClient.ipc create mode 100644 Userland/Services/ImageDecoder/ImageDecoderServer.ipc create mode 100644 Userland/Services/ImageDecoder/main.cpp create mode 100644 Userland/Services/LaunchServer/CMakeLists.txt create mode 100644 Userland/Services/LaunchServer/ClientConnection.cpp create mode 100644 Userland/Services/LaunchServer/ClientConnection.h create mode 100644 Userland/Services/LaunchServer/LaunchClient.ipc create mode 100644 Userland/Services/LaunchServer/LaunchServer.ipc create mode 100644 Userland/Services/LaunchServer/Launcher.cpp create mode 100644 Userland/Services/LaunchServer/Launcher.h create mode 100644 Userland/Services/LaunchServer/main.cpp create mode 100644 Userland/Services/LookupServer/CMakeLists.txt create mode 100644 Userland/Services/LookupServer/DNSAnswer.cpp create mode 100644 Userland/Services/LookupServer/DNSAnswer.h create mode 100644 Userland/Services/LookupServer/DNSPacket.h create mode 100644 Userland/Services/LookupServer/DNSQuestion.h create mode 100644 Userland/Services/LookupServer/DNSRequest.cpp create mode 100644 Userland/Services/LookupServer/DNSRequest.h create mode 100644 Userland/Services/LookupServer/DNSResponse.cpp create mode 100644 Userland/Services/LookupServer/DNSResponse.h create mode 100644 Userland/Services/LookupServer/LookupServer.cpp create mode 100644 Userland/Services/LookupServer/LookupServer.h create mode 100644 Userland/Services/LookupServer/main.cpp create mode 100644 Userland/Services/NotificationServer/CMakeLists.txt create mode 100644 Userland/Services/NotificationServer/ClientConnection.cpp create mode 100644 Userland/Services/NotificationServer/ClientConnection.h create mode 100644 Userland/Services/NotificationServer/NotificationClient.ipc create mode 100644 Userland/Services/NotificationServer/NotificationServer.ipc create mode 100644 Userland/Services/NotificationServer/NotificationWindow.cpp create mode 100644 Userland/Services/NotificationServer/NotificationWindow.h create mode 100644 Userland/Services/NotificationServer/main.cpp create mode 100644 Userland/Services/ProtocolServer/CMakeLists.txt create mode 100644 Userland/Services/ProtocolServer/ClientConnection.cpp create mode 100644 Userland/Services/ProtocolServer/ClientConnection.h create mode 100644 Userland/Services/ProtocolServer/Download.cpp create mode 100644 Userland/Services/ProtocolServer/Download.h create mode 100644 Userland/Services/ProtocolServer/Forward.h create mode 100644 Userland/Services/ProtocolServer/GeminiDownload.cpp create mode 100644 Userland/Services/ProtocolServer/GeminiDownload.h create mode 100644 Userland/Services/ProtocolServer/GeminiProtocol.cpp create mode 100644 Userland/Services/ProtocolServer/GeminiProtocol.h create mode 100644 Userland/Services/ProtocolServer/HttpDownload.cpp create mode 100644 Userland/Services/ProtocolServer/HttpDownload.h create mode 100644 Userland/Services/ProtocolServer/HttpProtocol.cpp create mode 100644 Userland/Services/ProtocolServer/HttpProtocol.h create mode 100644 Userland/Services/ProtocolServer/HttpsDownload.cpp create mode 100644 Userland/Services/ProtocolServer/HttpsDownload.h create mode 100644 Userland/Services/ProtocolServer/HttpsProtocol.cpp create mode 100644 Userland/Services/ProtocolServer/HttpsProtocol.h create mode 100644 Userland/Services/ProtocolServer/Protocol.cpp create mode 100644 Userland/Services/ProtocolServer/Protocol.h create mode 100644 Userland/Services/ProtocolServer/ProtocolClient.ipc create mode 100644 Userland/Services/ProtocolServer/ProtocolServer.ipc create mode 100644 Userland/Services/ProtocolServer/main.cpp create mode 100644 Userland/Services/SystemMenu/CMakeLists.txt create mode 100644 Userland/Services/SystemMenu/ShutdownDialog.cpp create mode 100644 Userland/Services/SystemMenu/ShutdownDialog.h create mode 100644 Userland/Services/SystemMenu/main.cpp create mode 100644 Userland/Services/SystemServer/CMakeLists.txt create mode 100644 Userland/Services/SystemServer/Service.cpp create mode 100644 Userland/Services/SystemServer/Service.h create mode 100644 Userland/Services/SystemServer/main.cpp create mode 100644 Userland/Services/Taskbar/CMakeLists.txt create mode 100644 Userland/Services/Taskbar/TaskbarButton.cpp create mode 100644 Userland/Services/Taskbar/TaskbarButton.h create mode 100644 Userland/Services/Taskbar/TaskbarWindow.cpp create mode 100644 Userland/Services/Taskbar/TaskbarWindow.h create mode 100644 Userland/Services/Taskbar/WindowIdentifier.h create mode 100644 Userland/Services/Taskbar/WindowList.cpp create mode 100644 Userland/Services/Taskbar/WindowList.h create mode 100644 Userland/Services/Taskbar/main.cpp create mode 100644 Userland/Services/TelnetServer/CMakeLists.txt create mode 100644 Userland/Services/TelnetServer/Client.cpp create mode 100644 Userland/Services/TelnetServer/Client.h create mode 100644 Userland/Services/TelnetServer/Command.h create mode 100644 Userland/Services/TelnetServer/Parser.cpp create mode 100644 Userland/Services/TelnetServer/Parser.h create mode 100644 Userland/Services/TelnetServer/main.cpp create mode 100644 Userland/Services/WebContent/CMakeLists.txt create mode 100644 Userland/Services/WebContent/ClientConnection.cpp create mode 100644 Userland/Services/WebContent/ClientConnection.h create mode 100644 Userland/Services/WebContent/Documentation.txt create mode 100644 Userland/Services/WebContent/Forward.h create mode 100644 Userland/Services/WebContent/PageHost.cpp create mode 100644 Userland/Services/WebContent/PageHost.h create mode 100644 Userland/Services/WebContent/WebContentClient.ipc create mode 100644 Userland/Services/WebContent/WebContentServer.ipc create mode 100644 Userland/Services/WebContent/main.cpp create mode 100644 Userland/Services/WebServer/CMakeLists.txt create mode 100644 Userland/Services/WebServer/Client.cpp create mode 100644 Userland/Services/WebServer/Client.h create mode 100644 Userland/Services/WebServer/main.cpp create mode 100644 Userland/Services/WindowServer/AppletManager.cpp create mode 100644 Userland/Services/WindowServer/AppletManager.h create mode 100644 Userland/Services/WindowServer/Button.cpp create mode 100644 Userland/Services/WindowServer/Button.h create mode 100644 Userland/Services/WindowServer/CMakeLists.txt create mode 100644 Userland/Services/WindowServer/ClientConnection.cpp create mode 100644 Userland/Services/WindowServer/ClientConnection.h create mode 100644 Userland/Services/WindowServer/Compositor.cpp create mode 100644 Userland/Services/WindowServer/Compositor.h create mode 100644 Userland/Services/WindowServer/Cursor.cpp create mode 100644 Userland/Services/WindowServer/Cursor.h create mode 100644 Userland/Services/WindowServer/Event.h create mode 100644 Userland/Services/WindowServer/EventLoop.cpp create mode 100644 Userland/Services/WindowServer/EventLoop.h create mode 100644 Userland/Services/WindowServer/Menu.cpp create mode 100644 Userland/Services/WindowServer/Menu.h create mode 100644 Userland/Services/WindowServer/MenuBar.cpp create mode 100644 Userland/Services/WindowServer/MenuBar.h create mode 100644 Userland/Services/WindowServer/MenuItem.cpp create mode 100644 Userland/Services/WindowServer/MenuItem.h create mode 100644 Userland/Services/WindowServer/MenuManager.cpp create mode 100644 Userland/Services/WindowServer/MenuManager.h create mode 100644 Userland/Services/WindowServer/Screen.cpp create mode 100644 Userland/Services/WindowServer/Screen.h create mode 100644 Userland/Services/WindowServer/Window.cpp create mode 100644 Userland/Services/WindowServer/Window.h create mode 100644 Userland/Services/WindowServer/WindowClient.ipc create mode 100644 Userland/Services/WindowServer/WindowFrame.cpp create mode 100644 Userland/Services/WindowServer/WindowFrame.h create mode 100644 Userland/Services/WindowServer/WindowManager.cpp create mode 100644 Userland/Services/WindowServer/WindowManager.h create mode 100644 Userland/Services/WindowServer/WindowServer.ipc create mode 100644 Userland/Services/WindowServer/WindowSwitcher.cpp create mode 100644 Userland/Services/WindowServer/WindowSwitcher.h create mode 100644 Userland/Services/WindowServer/WindowType.h create mode 100644 Userland/Services/WindowServer/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b4a9b8b9d0..c37c28d6c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,14 +136,13 @@ add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root) include_directories(Userland/Libraries/LibC) include_directories(Userland/Libraries/LibM) -include_directories(Services) +include_directories(Userland/Services) include_directories(Userland) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/Services) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Services) include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries) include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland) add_subdirectory(AK) add_subdirectory(Kernel) -add_subdirectory(Services) add_subdirectory(Userland) diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake index 886b79f166..6c4f0c00de 100644 --- a/Meta/CMake/utils.cmake +++ b/Meta/CMake/utils.cmake @@ -108,7 +108,7 @@ function(compile_ipc source output) set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source}) add_custom_command( OUTPUT ${output} - COMMAND ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/DevTools/IPCCompiler/IPCCompiler ${source} + COMMAND ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/Userland/DevTools/IPCCompiler/IPCCompiler ${source} VERBATIM DEPENDS IPCCompiler MAIN_DEPENDENCY ${source} diff --git a/Services/AudioServer/AudioClient.ipc b/Services/AudioServer/AudioClient.ipc deleted file mode 100644 index b43db52dd0..0000000000 --- a/Services/AudioServer/AudioClient.ipc +++ /dev/null @@ -1,6 +0,0 @@ -endpoint AudioClient = 82 -{ - FinishedPlayingBuffer(i32 buffer_id) =| - MutedStateChanged(bool muted) =| - MainMixVolumeChanged(i32 volume) =| -} diff --git a/Services/AudioServer/AudioServer.ipc b/Services/AudioServer/AudioServer.ipc deleted file mode 100644 index b48dcd7e46..0000000000 --- a/Services/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/Services/AudioServer/CMakeLists.txt b/Services/AudioServer/CMakeLists.txt deleted file mode 100644 index 9c71197b62..0000000000 --- a/Services/AudioServer/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -compile_ipc(AudioServer.ipc AudioServerEndpoint.h) -compile_ipc(AudioClient.ipc AudioClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - Mixer.cpp - main.cpp - AudioServerEndpoint.h - AudioClientEndpoint.h -) - -serenity_bin(AudioServer) -target_link_libraries(AudioServer LibCore LibThread LibIPC) diff --git a/Services/AudioServer/ClientConnection.cpp b/Services/AudioServer/ClientConnection.cpp deleted file mode 100644 index c034dc5199..0000000000 --- a/Services/AudioServer/ClientConnection.cpp +++ /dev/null @@ -1,168 +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 "ClientConnection.h" -#include "Mixer.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AudioServer { - -static HashMap> s_connections; - -void ClientConnection::for_each(Function callback) -{ - NonnullRefPtrVector connections; - for (auto& it : s_connections) - connections.append(*it.value); - for (auto& connection : connections) - callback(connection); -} - -ClientConnection::ClientConnection(NonnullRefPtr client_socket, int client_id, Mixer& mixer) - : IPC::ClientConnection(*this, move(client_socket), client_id) - , m_mixer(mixer) -{ - s_connections.set(client_id, *this); -} - -ClientConnection::~ClientConnection() -{ -} - -void ClientConnection::die() -{ - s_connections.remove(client_id()); -} - -void ClientConnection::did_finish_playing_buffer(Badge, int buffer_id) -{ - post_message(Messages::AudioClient::FinishedPlayingBuffer(buffer_id)); -} - -void ClientConnection::did_change_muted_state(Badge, bool muted) -{ - post_message(Messages::AudioClient::MutedStateChanged(muted)); -} - -void ClientConnection::did_change_main_mix_volume(Badge, int volume) -{ - post_message(Messages::AudioClient::MainMixVolumeChanged(volume)); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::GetMainMixVolume&) -{ - return make(m_mixer.main_volume()); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::SetMainMixVolume& message) -{ - m_mixer.set_main_volume(message.volume()); - return make(); -} - -OwnPtr ClientConnection::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 ClientConnection::handle(const Messages::AudioServer::GetRemainingSamples&) -{ - int remaining = 0; - if (m_queue) - remaining = m_queue->get_remaining_samples(); - - return make(remaining); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::GetPlayedSamples&) -{ - int played = 0; - if (m_queue) - played = m_queue->get_played_samples(); - - return make(played); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::SetPaused& message) -{ - if (m_queue) - m_queue->set_paused(message.paused()); - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::ClearBuffer& message) -{ - if (m_queue) - m_queue->clear(message.paused()); - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::GetPlayingBuffer&) -{ - int id = -1; - if (m_queue) - id = m_queue->get_playing_buffer(); - return make(id); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::GetMuted&) -{ - return make(m_mixer.is_muted()); -} - -OwnPtr ClientConnection::handle(const Messages::AudioServer::SetMuted& message) -{ - m_mixer.set_muted(message.muted()); - return make(); -} -} diff --git a/Services/AudioServer/ClientConnection.h b/Services/AudioServer/ClientConnection.h deleted file mode 100644 index f08aab49d3..0000000000 --- a/Services/AudioServer/ClientConnection.h +++ /dev/null @@ -1,75 +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 - -namespace Audio { -class Buffer; -} - -namespace AudioServer { - -class BufferQueue; -class Mixer; - -class ClientConnection final : public IPC::ClientConnection - , public AudioServerEndpoint { - C_OBJECT(ClientConnection) -public: - explicit ClientConnection(NonnullRefPtr, int client_id, Mixer& mixer); - ~ClientConnection() override; - - void did_finish_playing_buffer(Badge, int buffer_id); - void did_change_muted_state(Badge, bool muted); - void did_change_main_mix_volume(Badge, int volume); - - 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; - - Mixer& m_mixer; - RefPtr m_queue; -}; - -} diff --git a/Services/AudioServer/Mixer.cpp b/Services/AudioServer/Mixer.cpp deleted file mode 100644 index 66a33ed23d..0000000000 --- a/Services/AudioServer/Mixer.cpp +++ /dev/null @@ -1,166 +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 -#include - -namespace AudioServer { - -Mixer::Mixer() - : m_device(Core::File::construct("/dev/audio", this)) - , m_sound_thread(LibThread::Thread::construct( - [this] { - mix(); - return 0; - }, - "AudioServer[mixer]")) -{ - if (!m_device->open(Core::IODevice::WriteOnly)) { - dbgln("Can't open audio device: {}", 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(); -} - -Mixer::~Mixer() -{ -} - -NonnullRefPtr Mixer::create_queue(ClientConnection& client) -{ - auto queue = adopt(*new BufferQueue(client)); - pthread_mutex_lock(&m_pending_mutex); - m_pending_mixing.append(*queue); - m_added_queue = true; - pthread_cond_signal(&m_pending_cond); - pthread_mutex_unlock(&m_pending_mutex); - return queue; -} - -void Mixer::mix() -{ - decltype(m_pending_mixing) active_mix_queues; - - for (;;) { - if (active_mix_queues.is_empty() || m_added_queue) { - 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); - m_added_queue = false; - } - - 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; - } - } - - if (m_muted) { - m_device->write(m_zero_filled_buffer, 4096); - } else { - Array buffer; - OutputMemoryStream stream { buffer }; - - for (int i = 0; i < mixed_buffer_length; ++i) { - auto& mixed_sample = mixed_buffer[i]; - - mixed_sample.scale(m_main_volume); - mixed_sample.clip(); - - LittleEndian out_sample; - out_sample = mixed_sample.left * NumericLimits::max(); - stream << out_sample; - - out_sample = mixed_sample.right * NumericLimits::max(); - stream << out_sample; - } - - ASSERT(stream.is_end()); - ASSERT(!stream.has_any_error()); - m_device->write(stream.data(), stream.size()); - } - } -} - -void Mixer::set_main_volume(int volume) -{ - if (volume > 100) - m_main_volume = 100; - else - m_main_volume = volume; - ClientConnection::for_each([volume](ClientConnection& client) { - client.did_change_main_mix_volume({}, volume); - }); -} - -void Mixer::set_muted(bool muted) -{ - if (m_muted == muted) - return; - m_muted = muted; - ClientConnection::for_each([muted](ClientConnection& client) { - client.did_change_muted_state({}, muted); - }); -} - -BufferQueue::BufferQueue(ClientConnection& client) - : m_client(client) -{ -} - -void BufferQueue::enqueue(NonnullRefPtr&& buffer) -{ - m_remaining_samples += buffer->sample_count(); - m_queue.enqueue(move(buffer)); -} -} diff --git a/Services/AudioServer/Mixer.h b/Services/AudioServer/Mixer.h deleted file mode 100644 index 74fbba6ede..0000000000 --- a/Services/AudioServer/Mixer.h +++ /dev/null @@ -1,144 +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 "ClientConnection.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AudioServer { - -class ClientConnection; - -class BufferQueue : public RefCounted { -public: - explicit BufferQueue(ClientConnection&); - ~BufferQueue() { } - - 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; - } - - ClientConnection* 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 Mixer : public Core::Object { - C_OBJECT(Mixer) -public: - Mixer(); - virtual ~Mixer() override; - - NonnullRefPtr create_queue(ClientConnection&); - - int main_volume() const { return m_main_volume; } - void set_main_volume(int volume); - - bool is_muted() const { return m_muted; } - void set_muted(bool); - -private: - Vector> m_pending_mixing; - Atomic m_added_queue { false }; - pthread_mutex_t m_pending_mutex; - pthread_cond_t m_pending_cond; - - RefPtr m_device; - - NonnullRefPtr m_sound_thread; - - bool m_muted { false }; - int m_main_volume { 100 }; - - u8* m_zero_filled_buffer { nullptr }; - - void mix(); -}; -} diff --git a/Services/AudioServer/main.cpp b/Services/AudioServer/main.cpp deleted file mode 100644 index 9eca20bfd3..0000000000 --- a/Services/AudioServer/main.cpp +++ /dev/null @@ -1,63 +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 "Mixer.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; - AudioServer::Mixer 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) { - dbgln("AudioServer: accept failed."); - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(client_socket.release_nonnull(), client_id, mixer); - }; - - if (pledge("stdio thread shared_buffer accept", nullptr) < 0) { - perror("pledge"); - return 1; - } - - unveil(nullptr, nullptr); - - return event_loop.exec(); -} diff --git a/Services/CMakeLists.txt b/Services/CMakeLists.txt deleted file mode 100644 index 26003a7d55..0000000000 --- a/Services/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -add_subdirectory(AudioServer) -add_subdirectory(ChessEngine) -add_subdirectory(Clipboard) -add_subdirectory(CrashDaemon) -add_subdirectory(DHCPClient) -add_subdirectory(EchoServer) -add_subdirectory(ImageDecoder) -add_subdirectory(LaunchServer) -add_subdirectory(LookupServer) -add_subdirectory(NotificationServer) -add_subdirectory(ProtocolServer) -add_subdirectory(SystemMenu) -add_subdirectory(SystemServer) -add_subdirectory(Taskbar) -add_subdirectory(TelnetServer) -add_subdirectory(WebContent) -add_subdirectory(WebServer) -add_subdirectory(WindowServer) diff --git a/Services/ChessEngine/CMakeLists.txt b/Services/ChessEngine/CMakeLists.txt deleted file mode 100644 index 288529a100..0000000000 --- a/Services/ChessEngine/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -set(SOURCES - ChessEngine.cpp - main.cpp - MCTSTree.cpp -) - -serenity_bin(ChessEngine) -target_link_libraries(ChessEngine LibChess LibCore) diff --git a/Services/ChessEngine/ChessEngine.cpp b/Services/ChessEngine/ChessEngine.cpp deleted file mode 100644 index 16394d443c..0000000000 --- a/Services/ChessEngine/ChessEngine.cpp +++ /dev/null @@ -1,76 +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 "ChessEngine.h" -#include "MCTSTree.h" -#include - -using namespace Chess::UCI; - -void ChessEngine::handle_uci() -{ - send_command(IdCommand(IdCommand::Type::Name, "ChessEngine")); - send_command(IdCommand(IdCommand::Type::Author, "the SerenityOS developers")); - send_command(UCIOkCommand()); -} - -void ChessEngine::handle_position(const PositionCommand& command) -{ - // FIXME: Implement fen board position. - ASSERT(!command.fen().has_value()); - m_board = Chess::Board(); - for (auto& move : command.moves()) { - ASSERT(m_board.apply_move(move)); - } -} - -void ChessEngine::handle_go(const GoCommand& command) -{ - // FIXME: A better algorithm than naive mcts. - // FIXME: Add different ways to terminate search. - ASSERT(command.movetime.has_value()); - - srand(arc4random()); - - Core::ElapsedTimer elapsed_time; - elapsed_time.start(); - - MCTSTree mcts(m_board); - - // FIXME: optimize simulations enough for use. - mcts.set_eval_method(MCTSTree::EvalMethod::Heuristic); - - int rounds = 0; - while (elapsed_time.elapsed() <= command.movetime.value()) { - mcts.do_round(); - ++rounds; - } - dbg() << "MCTS finished " << rounds << " rounds."; - dbg() << "MCTS evaluation " << mcts.expected_value(); - auto best_move = mcts.best_move(); - dbg() << "MCTS best move " << best_move.to_long_algebraic(); - send_command(BestMoveCommand(best_move)); -} diff --git a/Services/ChessEngine/ChessEngine.h b/Services/ChessEngine/ChessEngine.h deleted file mode 100644 index 54c0cb7c8a..0000000000 --- a/Services/ChessEngine/ChessEngine.h +++ /dev/null @@ -1,49 +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 - -class ChessEngine : public Chess::UCI::Endpoint { - C_OBJECT(ChessEngine) -public: - virtual ~ChessEngine() override { } - - ChessEngine() { } - ChessEngine(NonnullRefPtr in, NonnullRefPtr out) - : Endpoint(in, out) - { - } - - virtual void handle_uci(); - virtual void handle_position(const Chess::UCI::PositionCommand&); - virtual void handle_go(const Chess::UCI::GoCommand&); - -private: - Chess::Board m_board; -}; diff --git a/Services/ChessEngine/MCTSTree.cpp b/Services/ChessEngine/MCTSTree.cpp deleted file mode 100644 index dc195089fe..0000000000 --- a/Services/ChessEngine/MCTSTree.cpp +++ /dev/null @@ -1,180 +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 "MCTSTree.h" -#include -#include - -MCTSTree::MCTSTree(const Chess::Board& board, double exploration_parameter, MCTSTree* parent) - : m_parent(parent) - , m_exploration_parameter(exploration_parameter) - , m_board(board) -{ - if (m_parent) - m_eval_method = m_parent->eval_method(); -} - -MCTSTree& MCTSTree::select_leaf() -{ - if (!expanded() || m_children.size() == 0) - return *this; - - MCTSTree* node = nullptr; - double max_uct = -double(INFINITY); - for (auto& child : m_children) { - double uct = child.uct(m_board.turn()); - if (uct >= max_uct) { - max_uct = uct; - node = &child; - } - } - ASSERT(node); - return node->select_leaf(); -} - -MCTSTree& MCTSTree::expand() -{ - ASSERT(!expanded() || m_children.size() == 0); - - if (!m_moves_generated) { - m_board.generate_moves([&](Chess::Move move) { - Chess::Board clone = m_board; - clone.apply_move(move); - m_children.append(make(clone, m_exploration_parameter, this)); - return IterationDecision::Continue; - }); - m_moves_generated = true; - } - - if (m_children.size() == 0) { - return *this; - } - - for (auto& child : m_children) { - if (child.m_simulations == 0) { - return child; - } - } - ASSERT_NOT_REACHED(); -} - -int MCTSTree::simulate_game() const -{ - ASSERT_NOT_REACHED(); - Chess::Board clone = m_board; - while (!clone.game_finished()) { - clone.apply_move(clone.random_move()); - } - return clone.game_score(); -} - -int MCTSTree::heuristic() const -{ - if (m_board.game_finished()) - return m_board.game_score(); - - double winchance = max(min(double(m_board.material_imbalance()) / 6, 1.0), -1.0); - - double random = double(rand()) / RAND_MAX; - if (winchance >= random) - return 1; - if (winchance <= -random) - return -1; - - return 0; -} - -void MCTSTree::apply_result(int game_score) -{ - m_simulations++; - m_white_points += game_score; - - if (m_parent) - m_parent->apply_result(game_score); -} - -void MCTSTree::do_round() -{ - auto& node = select_leaf().expand(); - - int result; - if (m_eval_method == EvalMethod::Simulation) { - result = node.simulate_game(); - } else { - result = node.heuristic(); - } - node.apply_result(result); -} - -Chess::Move MCTSTree::best_move() const -{ - int score_multiplier = (m_board.turn() == Chess::Color::White) ? 1 : -1; - - Chess::Move best_move = { { 0, 0 }, { 0, 0 } }; - double best_score = -double(INFINITY); - ASSERT(m_children.size()); - for (auto& node : m_children) { - double node_score = node.expected_value() * score_multiplier; - if (node_score >= best_score) { - // The best move is the last move made in the child. - best_move = node.m_board.moves()[node.m_board.moves().size() - 1]; - best_score = node_score; - } - } - - return best_move; -} - -double MCTSTree::expected_value() const -{ - if (m_simulations == 0) - return 0; - - return double(m_white_points) / m_simulations; -} - -double MCTSTree::uct(Chess::Color color) const -{ - // UCT: Upper Confidence Bound Applied to Trees. - // Kocsis, Levente; Szepesvári, Csaba (2006). "Bandit based Monte-Carlo Planning" - - // Fun fact: Szepesvári was my data structures professor. - double expected = expected_value() * ((color == Chess::Color::White) ? 1 : -1); - return expected + m_exploration_parameter * sqrt(log(m_parent->m_simulations) / m_simulations); -} - -bool MCTSTree::expanded() const -{ - if (!m_moves_generated) - return false; - - for (auto& child : m_children) { - if (child.m_simulations == 0) - return false; - } - - return true; -} diff --git a/Services/ChessEngine/MCTSTree.h b/Services/ChessEngine/MCTSTree.h deleted file mode 100644 index 0ae68eae8f..0000000000 --- a/Services/ChessEngine/MCTSTree.h +++ /dev/null @@ -1,67 +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 MCTSTree { -public: - enum EvalMethod { - Simulation, - Heuristic, - }; - - MCTSTree(const Chess::Board& board, double exploration_parameter = sqrt(2), MCTSTree* parent = nullptr); - - MCTSTree& select_leaf(); - MCTSTree& expand(); - int simulate_game() const; - int heuristic() const; - void apply_result(int game_score); - void do_round(); - - Chess::Move best_move() const; - double expected_value() const; - double uct(Chess::Color color) const; - bool expanded() const; - - EvalMethod eval_method() const { return m_eval_method; } - void set_eval_method(EvalMethod method) { m_eval_method = method; } - -private: - NonnullOwnPtrVector m_children; - MCTSTree* m_parent { nullptr }; - int m_white_points { 0 }; - int m_simulations { 0 }; - bool m_moves_generated { false }; - double m_exploration_parameter; - EvalMethod m_eval_method { EvalMethod::Simulation }; - Chess::Board m_board; -}; diff --git a/Services/ChessEngine/main.cpp b/Services/ChessEngine/main.cpp deleted file mode 100644 index 60d6ec8397..0000000000 --- a/Services/ChessEngine/main.cpp +++ /dev/null @@ -1,49 +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 "ChessEngine.h" -#include -#include - -int main() -{ - if (pledge("stdio shared_buffer accept unix rpath cpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - Core::EventLoop loop; - if (pledge("stdio shared_buffer unix", nullptr) < 0) { - perror("pledge"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto engine = ChessEngine::construct(Core::File::standard_input(), Core::File::standard_output()); - return loop.exec(); -} diff --git a/Services/Clipboard/CMakeLists.txt b/Services/Clipboard/CMakeLists.txt deleted file mode 100644 index 4f0e5ab65a..0000000000 --- a/Services/Clipboard/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -compile_ipc(ClipboardServer.ipc ClipboardServerEndpoint.h) -compile_ipc(ClipboardClient.ipc ClipboardClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - ClipboardClientEndpoint.h - ClipboardServerEndpoint.h - Storage.cpp - main.cpp -) - -serenity_bin(Clipboard) -target_link_libraries(Clipboard LibCore LibIPC) diff --git a/Services/Clipboard/ClientConnection.cpp b/Services/Clipboard/ClientConnection.cpp deleted file mode 100644 index 9518a4f0b6..0000000000 --- a/Services/Clipboard/ClientConnection.cpp +++ /dev/null @@ -1,103 +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 -#include -#include -#include -#include - -namespace Clipboard { - -static HashMap> s_connections; - -void ClientConnection::for_each_client(Function callback) -{ - for (auto& it : s_connections) { - callback(*it.value); - } -} - -ClientConnection::ClientConnection(NonnullRefPtr socket, int client_id) - : IPC::ClientConnection(*this, move(socket), client_id) -{ - s_connections.set(client_id, *this); -} - -ClientConnection::~ClientConnection() -{ -} - -void ClientConnection::die() -{ - s_connections.remove(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::ClipboardServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::ClipboardServer::SetClipboardData& message) -{ - auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.shbuf_id()); - if (!shared_buffer) { - did_misbehave("SetClipboardData: Bad shared buffer ID"); - return {}; - } - Storage::the().set_data(*shared_buffer, message.data_size(), message.mime_type(), message.metadata().entries()); - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::ClipboardServer::GetClipboardData&) -{ - auto& storage = Storage::the(); - - i32 shbuf_id = -1; - if (storage.data_size()) { - // FIXME: Optimize case where an app is copy/pasting within itself. - // We can just reuse the SharedBuffer then, since it will have the same peer PID. - // It would be even nicer if a SharedBuffer could have an arbitrary number of clients.. - RefPtr shared_buffer = SharedBuffer::create_with_size(storage.data_size()); - ASSERT(shared_buffer); - memcpy(shared_buffer->data(), storage.data(), storage.data_size()); - shared_buffer->seal(); - shared_buffer->share_with(client_pid()); - shbuf_id = shared_buffer->shbuf_id(); - - // FIXME: This is a workaround for the fact that SharedBuffers will go away if neither side is retaining them. - // After we respond to GetClipboardData, we have to wait for the client to ref the buffer on his side. - m_last_sent_buffer = move(shared_buffer); - } - return make(shbuf_id, storage.data_size(), storage.mime_type(), storage.metadata()); -} - -void ClientConnection::notify_about_clipboard_change() -{ - post_message(Messages::ClipboardClient::ClipboardDataChanged(Storage::the().mime_type())); -} - -} diff --git a/Services/Clipboard/ClientConnection.h b/Services/Clipboard/ClientConnection.h deleted file mode 100644 index 48794f4f88..0000000000 --- a/Services/Clipboard/ClientConnection.h +++ /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. - */ - -#pragma once - -#include -#include -#include -#include - -namespace Clipboard { - -class ClientConnection final - : public IPC::ClientConnection - , public ClipboardServerEndpoint { - - C_OBJECT(ClientConnection); - -public: - explicit ClientConnection(NonnullRefPtr, int client_id); - virtual ~ClientConnection() override; - - virtual void die() override; - - static void for_each_client(Function); - - void notify_about_clipboard_change(); - -private: - virtual OwnPtr handle(const Messages::ClipboardServer::Greet&) override; - virtual OwnPtr handle(const Messages::ClipboardServer::GetClipboardData&) override; - virtual OwnPtr handle(const Messages::ClipboardServer::SetClipboardData&) override; - - RefPtr m_last_sent_buffer; -}; - -} diff --git a/Services/Clipboard/ClipboardClient.ipc b/Services/Clipboard/ClipboardClient.ipc deleted file mode 100644 index 50d695e92a..0000000000 --- a/Services/Clipboard/ClipboardClient.ipc +++ /dev/null @@ -1,4 +0,0 @@ -endpoint ClipboardClient = 804 -{ - ClipboardDataChanged([UTF8] String mime_type) =| -} diff --git a/Services/Clipboard/ClipboardServer.ipc b/Services/Clipboard/ClipboardServer.ipc deleted file mode 100644 index c0c1fab8c8..0000000000 --- a/Services/Clipboard/ClipboardServer.ipc +++ /dev/null @@ -1,7 +0,0 @@ -endpoint ClipboardServer = 802 -{ - Greet() => (i32 client_id) - - GetClipboardData() => (i32 shbuf_id, i32 data_size, [UTF8] String mime_type, IPC::Dictionary metadata) - SetClipboardData(i32 shbuf_id, i32 data_size, [UTF8] String mime_type, IPC::Dictionary metadata) => () -} diff --git a/Services/Clipboard/Storage.cpp b/Services/Clipboard/Storage.cpp deleted file mode 100644 index 3b745dea16..0000000000 --- a/Services/Clipboard/Storage.cpp +++ /dev/null @@ -1,62 +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 - -namespace Clipboard { - -Storage& Storage::the() -{ - static Storage* s_the; - if (!s_the) - s_the = new Storage; - return *s_the; -} - -Storage::Storage() -{ -} - -Storage::~Storage() -{ -} - -void Storage::set_data(NonnullRefPtr data, size_t data_size, const String& mime_type, const HashMap& metadata) -{ - dbg() << "Storage::set_data <- [" << mime_type << "] " << data->data() << " (" << data_size << " bytes)"; - for (auto& it : metadata) { - dbg() << " " << it.key << ": " << it.value; - } - m_shared_buffer = move(data); - m_data_size = data_size; - m_mime_type = mime_type; - m_metadata = metadata; - - if (on_content_change) - on_content_change(); -} - -} diff --git a/Services/Clipboard/Storage.h b/Services/Clipboard/Storage.h deleted file mode 100644 index ce194c15f4..0000000000 --- a/Services/Clipboard/Storage.h +++ /dev/null @@ -1,73 +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 -#include - -namespace Clipboard { - -class Storage { -public: - static Storage& the(); - ~Storage(); - - bool has_data() const { return m_shared_buffer; } - - const String& mime_type() const { return m_mime_type; } - const HashMap& metadata() const { return m_metadata; } - - const u8* data() const - { - if (!has_data()) - return nullptr; - return m_shared_buffer->data(); - } - - size_t data_size() const - { - if (has_data()) - return m_data_size; - return 0; - } - - void set_data(NonnullRefPtr, size_t data_size, const String& mime_type, const HashMap& metadata); - - Function on_content_change; - -private: - Storage(); - - String m_mime_type; - RefPtr m_shared_buffer; - size_t m_data_size { 0 }; - HashMap m_metadata; -}; - -} diff --git a/Services/Clipboard/main.cpp b/Services/Clipboard/main.cpp deleted file mode 100644 index b6cae095ee..0000000000 --- a/Services/Clipboard/main.cpp +++ /dev/null @@ -1,76 +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 -#include -#include -#include -#include - -int main(int, char**) -{ - if (pledge("stdio shared_buffer accept unix rpath cpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } - Core::EventLoop event_loop; - if (pledge("stdio shared_buffer unix accept", nullptr) < 0) { - perror("pledge"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto server = Core::LocalServer::construct(); - bool ok = server->take_over_from_system_server(); - ASSERT(ok); - - if (pledge("stdio shared_buffer accept", nullptr) < 0) { - perror("pledge"); - return 1; - } - - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("Clipboard: accept failed."); - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(client_socket.release_nonnull(), client_id); - }; - - Clipboard::Storage::the().on_content_change = [&] { - Clipboard::ClientConnection::for_each_client([&](auto& client) { - client.notify_about_clipboard_change(); - }); - }; - - return event_loop.exec(); -} diff --git a/Services/CrashDaemon/CMakeLists.txt b/Services/CrashDaemon/CMakeLists.txt deleted file mode 100644 index 5dcf13aacb..0000000000 --- a/Services/CrashDaemon/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_bin(CrashDaemon) -target_link_libraries(CrashDaemon LibC LibCore LibCoreDump) diff --git a/Services/CrashDaemon/main.cpp b/Services/CrashDaemon/main.cpp deleted file mode 100644 index 2453f73699..0000000000 --- a/Services/CrashDaemon/main.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2020, Itamar S. - * 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 -#include -#include -#include - -static void wait_until_coredump_is_ready(const String& coredump_path) -{ - while (true) { - struct stat statbuf; - if (stat(coredump_path.characters(), &statbuf) < 0) { - perror("stat"); - ASSERT_NOT_REACHED(); - } - if (statbuf.st_mode & 0400) // Check if readable - break; - - usleep(10000); // sleep for 10ms - } -} - -static void print_backtrace(const String& coredump_path) -{ - auto coredump = CoreDump::Reader::create(coredump_path); - if (!coredump) { - dbgln("Could not open coredump '{}'", coredump_path); - return; - } - for (auto& entry : coredump->backtrace().entries()) - dbgln("{}", entry.to_string(true)); -} - -static void launch_crash_reporter(const String& coredump_path) -{ - pid_t child; - const char* argv[] = { "CrashReporter", coredump_path.characters(), nullptr, nullptr }; - if ((errno = posix_spawn(&child, "/bin/CrashReporter", nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child) < 0) - perror("disown"); - } -} - -int main() -{ - if (pledge("stdio rpath proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } - - Core::DirectoryWatcher watcher { "/tmp/coredump" }; - while (true) { - auto event = watcher.wait_for_event(); - ASSERT(event.has_value()); - if (event.value().type != Core::DirectoryWatcher::Event::Type::ChildAdded) - continue; - auto coredump_path = event.value().child_path; - dbgln("New coredump file: {}", coredump_path); - wait_until_coredump_is_ready(coredump_path); - print_backtrace(coredump_path); - launch_crash_reporter(coredump_path); - } -} diff --git a/Services/DHCPClient/CMakeLists.txt b/Services/DHCPClient/CMakeLists.txt deleted file mode 100644 index 6fddd4a21f..0000000000 --- a/Services/DHCPClient/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -set(SOURCES - DHCPv4Client.cpp - DHCPv4.cpp - main.cpp -) - -serenity_bin(DHCPClient) -target_link_libraries(DHCPClient LibCore) diff --git a/Services/DHCPClient/DHCPv4.cpp b/Services/DHCPClient/DHCPv4.cpp deleted file mode 100644 index 36430f4eec..0000000000 --- a/Services/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/Services/DHCPClient/DHCPv4.h b/Services/DHCPClient/DHCPv4.h deleted file mode 100644 index a773167683..0000000000 --- a/Services/DHCPClient/DHCPv4.h +++ /dev/null @@ -1,299 +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("%zu", 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/Services/DHCPClient/DHCPv4Client.cpp b/Services/DHCPClient/DHCPv4Client.cpp deleted file mode 100644 index 7a759ed427..0000000000 --- a/Services/DHCPClient/DHCPv4Client.cpp +++ /dev/null @@ -1,289 +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 - -//#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)); - - bool fits = iface.m_ifname.copy_characters_to_buffer(ifr.ifr_name, IFNAMSIZ); - if (!fits) { - dbgln("Interface name doesn't fit into IFNAMSIZ!"); - return; - } - - // 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)) { - dbgln("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 = AK::convert_between_host_and_network_endian(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/Services/DHCPClient/DHCPv4Client.h b/Services/DHCPClient/DHCPv4Client.h deleted file mode 100644 index 60f76a55ef..0000000000 --- a/Services/DHCPClient/DHCPv4Client.h +++ /dev/null @@ -1,79 +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 - -struct InterfaceDescriptor { - String 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/Services/DHCPClient/main.cpp b/Services/DHCPClient/main.cpp deleted file mode 100644 index d81750b299..0000000000 --- a/Services/DHCPClient/main.cpp +++ /dev/null @@ -1,99 +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([[maybe_unused]] int argc, [[maybe_unused]] char** 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); - ASSERT(json.has_value()); - Vector ifnames; - json.value().as_array().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/Services/EchoServer/CMakeLists.txt b/Services/EchoServer/CMakeLists.txt deleted file mode 100644 index e7d67fe14e..0000000000 --- a/Services/EchoServer/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCES - Client.cpp - main.cpp -) - -serenity_bin(EchoServer) -target_link_libraries(EchoServer LibCore) diff --git a/Services/EchoServer/Client.cpp b/Services/EchoServer/Client.cpp deleted file mode 100644 index 874553915b..0000000000 --- a/Services/EchoServer/Client.cpp +++ /dev/null @@ -1,58 +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 "Client.h" - -Client::Client(int id, RefPtr socket) - : m_id(id) - , m_socket(move(socket)) -{ - m_socket->on_ready_to_read = [this] { drain_socket(); }; -} - -void Client::drain_socket() -{ - NonnullRefPtr protect(*this); - while (m_socket->can_read()) { - auto buf = m_socket->read(1024); - - dbg() << "Read " << buf.size() << " bytes: " << buf; - - if (m_socket->eof()) { - quit(); - break; - } - - m_socket->write(buf); - } -} - -void Client::quit() -{ - m_socket->close(); - if (on_exit) - on_exit(); -} diff --git a/Services/EchoServer/Client.h b/Services/EchoServer/Client.h deleted file mode 100644 index 23359fa79b..0000000000 --- a/Services/EchoServer/Client.h +++ /dev/null @@ -1,49 +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 - -class Client : public RefCounted { -public: - static NonnullRefPtr create(int id, RefPtr socket) - { - return adopt(*new Client(id, move(socket))); - } - - Function on_exit; - -protected: - Client(int id, RefPtr socket); - - void drain_socket(); - void quit(); - -private: - int m_id { 0 }; - RefPtr m_socket; -}; diff --git a/Services/EchoServer/main.cpp b/Services/EchoServer/main.cpp deleted file mode 100644 index a4136c3df6..0000000000 --- a/Services/EchoServer/main.cpp +++ /dev/null @@ -1,99 +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 "Client.h" -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - if (pledge("stdio cpath unix fattr inet id accept", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/tmp/rpc", "rwc") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - int port = 7; - - Core::ArgsParser args_parser; - args_parser.add_option(port, "Port to listen on", "port", 'p', "port"); - args_parser.parse(argc, argv); - - if ((u16)port != port) { - warnln("Invalid port number: {}", port); - exit(1); - } - - Core::EventLoop event_loop; - - auto server = Core::TCPServer::construct(); - - if (!server->listen({}, port)) { - warnln("Listening on 0.0.0.0:{} failed", port); - exit(1); - } - - HashMap> clients; - int next_id = 0; - - server->on_ready_to_accept = [&next_id, &clients, &server] { - int id = next_id++; - - auto client_socket = server->accept(); - if (!client_socket) { - perror("accept"); - return; - } - - outln("Client {} connected", id); - - auto client = Client::create(id, move(client_socket)); - client->on_exit = [&clients, id] { - clients.remove(id); - outln("Client {} disconnected", id); - }; - clients.set(id, client); - }; - - outln("Listening on 0.0.0.0:{}", port); - - return event_loop.exec(); -} diff --git a/Services/ImageDecoder/CMakeLists.txt b/Services/ImageDecoder/CMakeLists.txt deleted file mode 100644 index 56482fe31d..0000000000 --- a/Services/ImageDecoder/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -compile_ipc(ImageDecoderServer.ipc ImageDecoderServerEndpoint.h) -compile_ipc(ImageDecoderClient.ipc ImageDecoderClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - main.cpp - ImageDecoderServerEndpoint.h - ImageDecoderClientEndpoint.h -) - -serenity_bin(ImageDecoder) -target_link_libraries(ImageDecoder LibGfx LibIPC) diff --git a/Services/ImageDecoder/ClientConnection.cpp b/Services/ImageDecoder/ClientConnection.cpp deleted file mode 100644 index 1e516ccdb9..0000000000 --- a/Services/ImageDecoder/ClientConnection.cpp +++ /dev/null @@ -1,102 +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 -#include -#include -#include -#include -#include -#include - -namespace ImageDecoder { - -static HashMap> s_connections; - -ClientConnection::ClientConnection(NonnullRefPtr socket, int client_id) - : IPC::ClientConnection(*this, move(socket), client_id) -{ - s_connections.set(client_id, *this); -} - -ClientConnection::~ClientConnection() -{ -} - -void ClientConnection::die() -{ - s_connections.remove(client_id()); - exit(0); -} - -OwnPtr ClientConnection::handle(const Messages::ImageDecoderServer::Greet& message) -{ - set_client_pid(message.client_pid()); - return make(client_id(), getpid()); -} - -OwnPtr ClientConnection::handle(const Messages::ImageDecoderServer::DecodeImage& message) -{ - auto encoded_buffer = SharedBuffer::create_from_shbuf_id(message.encoded_shbuf_id()); - if (!encoded_buffer) { -#ifdef IMAGE_DECODER_DEBUG - dbgln("Could not map encoded data buffer"); -#endif - return {}; - } - - if (message.encoded_size() > (size_t)encoded_buffer->size()) { -#ifdef IMAGE_DECODER_DEBUG - dbgln("Encoded buffer is smaller than encoded size"); -#endif - return {}; - } - -#ifdef IMAGE_DECODER_DEBUG - dbg() << "Trying to decode " << message.encoded_size() << " bytes of image(?) data in shbuf_id=" << message.encoded_shbuf_id() << " (shbuf size: " << encoded_buffer->size() << ")"; -#endif - - auto decoder = Gfx::ImageDecoder::create(encoded_buffer->data(), message.encoded_size()); - auto bitmap = decoder->bitmap(); - - if (!bitmap) { -#ifdef IMAGE_DECODER_DEBUG - dbgln("Could not decode image from encoded data"); -#endif - return make(-1, Gfx::IntSize(), (i32)Gfx::BitmapFormat::Invalid, Vector()); - } - - // FIXME: We should fix ShareableBitmap so you can send it in responses as well as requests.. - m_shareable_bitmap = bitmap->to_bitmap_backed_by_shared_buffer(); - m_shareable_bitmap->shared_buffer()->share_with(client_pid()); - Vector palette; - if (m_shareable_bitmap->is_indexed()) { - palette = m_shareable_bitmap->palette_to_vector(); - } - return make(m_shareable_bitmap->shbuf_id(), m_shareable_bitmap->size(), (i32)m_shareable_bitmap->format(), palette); -} - -} diff --git a/Services/ImageDecoder/ClientConnection.h b/Services/ImageDecoder/ClientConnection.h deleted file mode 100644 index 1447c3b063..0000000000 --- a/Services/ImageDecoder/ClientConnection.h +++ /dev/null @@ -1,56 +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 -#include -#include -#include - -namespace ImageDecoder { - -class ClientConnection final - : public IPC::ClientConnection - , public ImageDecoderServerEndpoint { - C_OBJECT(ClientConnection); - -public: - explicit ClientConnection(NonnullRefPtr, int client_id); - ~ClientConnection() override; - - virtual void die() override; - -private: - virtual OwnPtr handle(const Messages::ImageDecoderServer::Greet&) override; - virtual OwnPtr handle(const Messages::ImageDecoderServer::DecodeImage&) override; - - RefPtr m_shareable_bitmap; -}; - -} diff --git a/Services/ImageDecoder/Forward.h b/Services/ImageDecoder/Forward.h deleted file mode 100644 index e43ca83960..0000000000 --- a/Services/ImageDecoder/Forward.h +++ /dev/null @@ -1,34 +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 - -namespace WebContent { - -class ClientConnection; -class PageHost; - -} diff --git a/Services/ImageDecoder/ImageDecoderClient.ipc b/Services/ImageDecoder/ImageDecoderClient.ipc deleted file mode 100644 index 49dc3862c2..0000000000 --- a/Services/ImageDecoder/ImageDecoderClient.ipc +++ /dev/null @@ -1,4 +0,0 @@ -endpoint ImageDecoderClient = 7002 -{ - Dummy() =| -} diff --git a/Services/ImageDecoder/ImageDecoderServer.ipc b/Services/ImageDecoder/ImageDecoderServer.ipc deleted file mode 100644 index 295454282f..0000000000 --- a/Services/ImageDecoder/ImageDecoderServer.ipc +++ /dev/null @@ -1,7 +0,0 @@ -endpoint ImageDecoderServer = 7001 -{ - Greet(i32 client_pid) => (i32 client_id, i32 server_pid) - - DecodeImage(i32 encoded_shbuf_id, u32 encoded_size) => (i32 decoded_shbuf_id, Gfx::IntSize size, i32 bitmap_format, Vector palette) - -} diff --git a/Services/ImageDecoder/main.cpp b/Services/ImageDecoder/main.cpp deleted file mode 100644 index d370f0d00b..0000000000 --- a/Services/ImageDecoder/main.cpp +++ /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. - */ - -#include -#include -#include -#include - -int main(int, char**) -{ - Core::EventLoop event_loop; - if (pledge("stdio shared_buffer unix", nullptr) < 0) { - perror("pledge"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server(); - IPC::new_client_connection(socket.release_nonnull(), 1); - if (pledge("stdio shared_buffer", nullptr) < 0) { - perror("pledge"); - return 1; - } - return event_loop.exec(); -} diff --git a/Services/LaunchServer/CMakeLists.txt b/Services/LaunchServer/CMakeLists.txt deleted file mode 100644 index 29308ce7f1..0000000000 --- a/Services/LaunchServer/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -compile_ipc(LaunchServer.ipc LaunchServerEndpoint.h) -compile_ipc(LaunchClient.ipc LaunchClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - Launcher.cpp - main.cpp - LaunchClientEndpoint.h - LaunchServerEndpoint.h -) - -serenity_bin(LaunchServer) -target_link_libraries(LaunchServer LibCore LibIPC LibDesktop) diff --git a/Services/LaunchServer/ClientConnection.cpp b/Services/LaunchServer/ClientConnection.cpp deleted file mode 100644 index 7ac167c1ae..0000000000 --- a/Services/LaunchServer/ClientConnection.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2020, Nicholas Hollett - * 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 "Launcher.h" -#include -#include -#include - -namespace LaunchServer { - -static HashMap> s_connections; -ClientConnection::ClientConnection(NonnullRefPtr client_socket, int client_id) - : IPC::ClientConnection(*this, move(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::LaunchServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::OpenURL& request) -{ - if (!m_allowlist.is_empty()) { - bool allowed = false; - for (auto& allowed_handler : m_allowlist) { - if (allowed_handler.handler_name == request.handler_name() - && (allowed_handler.any_url || allowed_handler.urls.contains_slow(request.url()))) { - allowed = true; - break; - } - } - if (!allowed) { - // You are not on the list, go home! - did_misbehave(String::formatted("Client requested a combination of handler/URL that was not on the list: '{}' with '{}'", request.handler_name(), request.url()).characters()); - return {}; - } - } - - URL url(request.url()); - auto result = Launcher::the().open_url(url, request.handler_name()); - return make(result); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::GetHandlersForURL& request) -{ - URL url(request.url()); - auto result = Launcher::the().handlers_for_url(url); - return make(result); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::GetHandlersWithDetailsForURL& request) -{ - URL url(request.url()); - auto result = Launcher::the().handlers_with_details_for_url(url); - return make(result); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::AddAllowedURL& request) -{ - if (m_allowlist_is_sealed) { - did_misbehave("Got request to add more allowed handlers after list was sealed"); - return {}; - } - - if (!request.url().is_valid()) { - did_misbehave("Got request to allow invalid URL"); - return {}; - } - - m_allowlist.empend(String(), false, Vector { request.url() }); - - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL& request) -{ - if (m_allowlist_is_sealed) { - did_misbehave("Got request to add more allowed handlers after list was sealed"); - return {}; - } - - if (request.handler_name().is_empty()) { - did_misbehave("Got request to allow empty handler name"); - return {}; - } - - m_allowlist.empend(request.handler_name(), true, Vector()); - - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs& request) -{ - if (m_allowlist_is_sealed) { - did_misbehave("Got request to add more allowed handlers after list was sealed"); - return {}; - } - - if (request.handler_name().is_empty()) { - did_misbehave("Got request to allow empty handler name"); - return {}; - } - - if (request.urls().is_empty()) { - did_misbehave("Got request to allow empty URL list"); - return {}; - } - - m_allowlist.empend(request.handler_name(), false, request.urls()); - - return make(); -} - -OwnPtr ClientConnection::handle(const Messages::LaunchServer::SealAllowlist&) -{ - if (m_allowlist_is_sealed) { - did_misbehave("Got more than one request to seal the allowed handlers list"); - return {}; - } - - return make(); -} - -} diff --git a/Services/LaunchServer/ClientConnection.h b/Services/LaunchServer/ClientConnection.h deleted file mode 100644 index 77eef53374..0000000000 --- a/Services/LaunchServer/ClientConnection.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2020, Nicholas Hollett - * 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 LaunchServer { - -class ClientConnection final : public IPC::ClientConnection - , public LaunchServerEndpoint { - C_OBJECT(ClientConnection) -public: - ~ClientConnection() override; - - virtual void die() override; - -private: - explicit ClientConnection(NonnullRefPtr, int client_id); - - virtual OwnPtr handle(const Messages::LaunchServer::Greet&) override; - virtual OwnPtr handle(const Messages::LaunchServer::OpenURL&) override; - virtual OwnPtr handle(const Messages::LaunchServer::GetHandlersForURL&) override; - virtual OwnPtr handle(const Messages::LaunchServer::GetHandlersWithDetailsForURL&) override; - virtual OwnPtr handle(const Messages::LaunchServer::AddAllowedURL&) override; - virtual OwnPtr handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL&) override; - virtual OwnPtr handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs&) override; - virtual OwnPtr handle(const Messages::LaunchServer::SealAllowlist&) override; - - struct AllowlistEntry { - String handler_name; - bool any_url { false }; - Vector urls; - }; - - Vector m_allowlist; - bool m_allowlist_is_sealed { false }; -}; -} diff --git a/Services/LaunchServer/LaunchClient.ipc b/Services/LaunchServer/LaunchClient.ipc deleted file mode 100644 index abd4e9ba3d..0000000000 --- a/Services/LaunchServer/LaunchClient.ipc +++ /dev/null @@ -1,4 +0,0 @@ -endpoint LaunchClient = 102 -{ - Dummy() =| -} diff --git a/Services/LaunchServer/LaunchServer.ipc b/Services/LaunchServer/LaunchServer.ipc deleted file mode 100644 index 4f50221f4b..0000000000 --- a/Services/LaunchServer/LaunchServer.ipc +++ /dev/null @@ -1,12 +0,0 @@ -endpoint LaunchServer = 101 -{ - Greet() => (i32 client_id) - OpenURL(URL url, String handler_name) => (bool response) - GetHandlersForURL(URL url) => (Vector handlers) - GetHandlersWithDetailsForURL(URL url) => (Vector handlers_details) - - AddAllowedURL(URL url) => () - AddAllowedHandlerWithAnyURL(String handler_name) => () - AddAllowedHandlerWithOnlySpecificURLs(String handler_name, Vector urls) => () - SealAllowlist() => () -} diff --git a/Services/LaunchServer/Launcher.cpp b/Services/LaunchServer/Launcher.cpp deleted file mode 100644 index ad6d025035..0000000000 --- a/Services/LaunchServer/Launcher.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (c) 2020, Nicholas Hollett , 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 "Launcher.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace LaunchServer { - -static Launcher* s_the; -static bool spawn(String executable, String argument); - -String Handler::name_from_executable(const StringView& executable) -{ - auto separator = executable.find_last_of('/'); - if (separator.has_value()) { - auto start = separator.value() + 1; - return executable.substring_view(start, executable.length() - start); - } - return executable; -} - -void Handler::from_executable(Type handler_type, const String& executable) -{ - this->handler_type = handler_type; - this->name = name_from_executable(executable); - this->executable = executable; -} - -String Handler::to_details_str() const -{ - StringBuilder builder; - JsonObjectSerializer obj { builder }; - obj.add("executable", executable); - obj.add("name", name); - switch (handler_type) { - case Type::Application: - obj.add("type", "app"); - break; - case Type::UserDefault: - obj.add("type", "userdefault"); - break; - case Type::UserPreferred: - obj.add("type", "userpreferred"); - break; - default: - break; - } - obj.finish(); - return builder.build(); -} - -Launcher::Launcher() -{ - ASSERT(s_the == nullptr); - s_the = this; -} - -Launcher& Launcher::the() -{ - ASSERT(s_the); - return *s_the; -} - -void Launcher::load_handlers(const String& af_dir) -{ - Desktop::AppFile::for_each([&](auto af) { - auto app_name = af->name(); - auto app_executable = af->executable(); - HashTable file_types; - for (auto& file_type : af->launcher_file_types()) - file_types.set(file_type); - HashTable protocols; - for (auto& protocol : af->launcher_protocols()) - protocols.set(protocol); - m_handlers.set(app_executable, { Handler::Type::Default, app_name, app_executable, file_types, protocols }); - }, - af_dir); -} - -void Launcher::load_config(const Core::ConfigFile& cfg) -{ - for (auto key : cfg.keys("FileType")) { - auto handler = cfg.read_entry("FileType", key).trim_whitespace(); - if (handler.is_empty()) - continue; - m_file_handlers.set(key.to_lowercase(), handler); - } - - for (auto key : cfg.keys("Protocol")) { - auto handler = cfg.read_entry("Protocol", key).trim_whitespace(); - if (handler.is_empty()) - continue; - m_protocol_handlers.set(key.to_lowercase(), handler); - } -} - -Vector Launcher::handlers_for_url(const URL& url) -{ - Vector handlers; - if (url.protocol() == "file") { - for_each_handler_for_path(url.path(), [&](auto& handler) -> bool { - handlers.append(handler.executable); - return true; - }); - } else { - for_each_handler(url.protocol(), m_protocol_handlers, [&](const auto& handler) -> bool { - if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.protocol())) { - handlers.append(handler.executable); - return true; - } - return false; - }); - } - return handlers; -} - -Vector Launcher::handlers_with_details_for_url(const URL& url) -{ - Vector handlers; - if (url.protocol() == "file") { - for_each_handler_for_path(url.path(), [&](auto& handler) -> bool { - handlers.append(handler.to_details_str()); - return true; - }); - } else { - for_each_handler(url.protocol(), m_protocol_handlers, [&](const auto& handler) -> bool { - if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.protocol())) { - handlers.append(handler.to_details_str()); - return true; - } - return false; - }); - } - return handlers; -} - -bool Launcher::open_url(const URL& url, const String& handler_name) -{ - if (!handler_name.is_null()) - return open_with_handler_name(url, handler_name); - - if (url.protocol() == "file") - return open_file_url(url); - - return open_with_user_preferences(m_protocol_handlers, url.protocol(), url.to_string()); -} - -bool Launcher::open_with_handler_name(const URL& url, const String& handler_name) -{ - auto handler_optional = m_handlers.get(handler_name); - if (!handler_optional.has_value()) - return false; - - auto& handler = handler_optional.value(); - String argument; - if (url.protocol() == "file") - argument = url.path(); - else - argument = url.to_string(); - return spawn(handler.executable, argument); -} - -bool spawn(String executable, String argument) -{ - pid_t child_pid; - const char* argv[] = { executable.characters(), argument.characters(), nullptr }; - if ((errno = posix_spawn(&child_pid, executable.characters(), nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - return false; - } else { - if (disown(child_pid) < 0) - perror("disown"); - } - return true; -} - -Handler Launcher::get_handler_for_executable(Handler::Type handler_type, const String& executable) const -{ - Handler handler; - auto existing_handler = m_handlers.get(executable); - if (existing_handler.has_value()) { - handler = existing_handler.value(); - handler.handler_type = handler_type; - } else { - handler.from_executable(handler_type, executable); - } - return handler; -} - -bool Launcher::open_with_user_preferences(const HashMap& user_preferences, const String key, const String argument, const String default_program) -{ - auto program_path = user_preferences.get(key); - if (program_path.has_value()) - return spawn(program_path.value(), argument); - - // There wasn't a handler for this, so try the fallback instead - program_path = user_preferences.get("*"); - if (program_path.has_value()) - return spawn(program_path.value(), argument); - - // Absolute worst case, try the provided default program, if any - if (!default_program.is_empty()) - return spawn(default_program, argument); - - return false; -} - -void Launcher::for_each_handler(const String& key, HashMap& user_preference, Function f) -{ - auto user_preferred = user_preference.get(key); - if (user_preferred.has_value()) - f(get_handler_for_executable(Handler::Type::UserPreferred, user_preferred.value())); - - size_t counted = 0; - for (auto& handler : m_handlers) { - // Skip over the existing item in the list - if (user_preferred.has_value() && user_preferred.value() == handler.value.executable) - continue; - if (f(handler.value)) - counted++; - } - - auto user_default = user_preference.get("*"); - if (counted == 0 && user_default.has_value()) - f(get_handler_for_executable(Handler::Type::UserDefault, user_default.value())); -} - -void Launcher::for_each_handler_for_path(const String& path, Function f) -{ - struct stat st; - if (stat(path.characters(), &st) < 0) { - perror("stat"); - return; - } - - // TODO: Make directory opening configurable - if (S_ISDIR(st.st_mode)) { - f(get_handler_for_executable(Handler::Type::Default, "/bin/FileManager")); - return; - } - - if ((st.st_mode & S_IFMT) == S_IFREG && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) - f(get_handler_for_executable(Handler::Type::Application, path)); - - auto extension = LexicalPath(path).extension().to_lowercase(); - - for_each_handler(extension, m_file_handlers, [&](const auto& handler) -> bool { - if (handler.handler_type != Handler::Type::Default || handler.file_types.contains(extension)) - return f(handler); - return false; - }); -} - -bool Launcher::open_file_url(const URL& url) -{ - struct stat st; - if (stat(url.path().characters(), &st) < 0) { - perror("stat"); - return false; - } - - // TODO: Make directory opening configurable - if (S_ISDIR(st.st_mode)) - return spawn("/bin/FileManager", url.path()); - - if ((st.st_mode & S_IFMT) == S_IFREG && st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) - return spawn(url.path(), {}); - - auto extension_parts = url.path().to_lowercase().split('.'); - String extension = {}; - if (extension_parts.size() > 1) - extension = extension_parts.last(); - return open_with_user_preferences(m_file_handlers, extension, url.path(), "/bin/TextEditor"); -} -} diff --git a/Services/LaunchServer/Launcher.h b/Services/LaunchServer/Launcher.h deleted file mode 100644 index 8708cdc258..0000000000 --- a/Services/LaunchServer/Launcher.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020, Nicholas Hollett - * 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 LaunchServer { - -struct Handler { - enum class Type { - Default = 0, - Application, - UserPreferred, - UserDefault - }; - Type handler_type; - String name; - String executable; - HashTable file_types {}; - HashTable protocols {}; - - static String name_from_executable(const StringView&); - void from_executable(Type, const String&); - String to_details_str() const; -}; - -class Launcher { -public: - Launcher(); - static Launcher& the(); - - void load_handlers(const String& af_dir = Desktop::AppFile::APP_FILES_DIRECTORY); - void load_config(const Core::ConfigFile&); - bool open_url(const URL&, const String& handler_name); - Vector handlers_for_url(const URL&); - Vector handlers_with_details_for_url(const URL&); - -private: - HashMap m_handlers; - HashMap m_protocol_handlers; - HashMap m_file_handlers; - - Handler get_handler_for_executable(Handler::Type, const String&) const; - void for_each_handler(const String& key, HashMap& user_preferences, Function f); - void for_each_handler_for_path(const String&, Function f); - bool open_file_url(const URL&); - bool open_with_user_preferences(const HashMap& user_preferences, const String key, const String argument, const String default_program = {}); - bool open_with_handler_name(const URL&, const String& handler_name); -}; -} diff --git a/Services/LaunchServer/main.cpp b/Services/LaunchServer/main.cpp deleted file mode 100644 index 2535d1e8bb..0000000000 --- a/Services/LaunchServer/main.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020, Nicholas Hollett - * 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 "Launcher.h" -#include -#include -#include -#include -#include - -int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) -{ - Core::EventLoop event_loop; - auto server = Core::LocalServer::construct(); - - auto launcher = LaunchServer::Launcher(); - - launcher.load_handlers(); - launcher.load_config(Core::ConfigFile::get_for_app("LaunchServer")); - - if (pledge("stdio accept rpath proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } - - bool ok = server->take_over_from_system_server(); - ASSERT(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("LaunchServer: accept failed."); - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - dbgln("Received connection"); - IPC::new_client_connection(client_socket.release_nonnull(), client_id); - }; - - return event_loop.exec(); -} diff --git a/Services/LookupServer/CMakeLists.txt b/Services/LookupServer/CMakeLists.txt deleted file mode 100644 index 89769d4abc..0000000000 --- a/Services/LookupServer/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -set(SOURCES - DNSAnswer.cpp - DNSRequest.cpp - DNSResponse.cpp - LookupServer.cpp - main.cpp -) - -serenity_bin(LookupServer) -target_link_libraries(LookupServer LibCore) diff --git a/Services/LookupServer/DNSAnswer.cpp b/Services/LookupServer/DNSAnswer.cpp deleted file mode 100644 index 775c23784e..0000000000 --- a/Services/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/Services/LookupServer/DNSAnswer.h b/Services/LookupServer/DNSAnswer.h deleted file mode 100644 index 794603dd30..0000000000 --- a/Services/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/Services/LookupServer/DNSPacket.h b/Services/LookupServer/DNSPacket.h deleted file mode 100644 index 1cddc372c7..0000000000 --- a/Services/LookupServer/DNSPacket.h +++ /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. - */ - -#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/Services/LookupServer/DNSQuestion.h b/Services/LookupServer/DNSQuestion.h deleted file mode 100644 index ec696905e6..0000000000 --- a/Services/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/Services/LookupServer/DNSRequest.cpp b/Services/LookupServer/DNSRequest.cpp deleted file mode 100644 index 561e988ac9..0000000000 --- a/Services/LookupServer/DNSRequest.cpp +++ /dev/null @@ -1,96 +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 - -const u16 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()); - - DuplexMemoryStream stream; - - stream << ReadonlyBytes { &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.bytes(); - } - stream << '\0'; - stream << htons(question.record_type()); - stream << htons(question.class_code()); - } - - return stream.copy_into_contiguous_buffer(); -} diff --git a/Services/LookupServer/DNSRequest.h b/Services/LookupServer/DNSRequest.h deleted file mode 100644 index 2b55dd75fb..0000000000 --- a/Services/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/Services/LookupServer/DNSResponse.cpp b/Services/LookupServer/DNSResponse.cpp deleted file mode 100644 index 54f4a985e8..0000000000 --- a/Services/LookupServer/DNSResponse.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 "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)) { - dbgln("DNS response not large enough ({} out of {}) to be a DNS packet.", raw_size, sizeof(DNSPacket)); - return {}; - } - - auto& response_header = *(const DNSPacket*)(raw_data); -#ifdef LOOKUPSERVER_DEBUG - dbgln("Got response (ID: {})", response_header.id()); - dbgln(" Question count: {}", response_header.question_count()); - dbgln(" Answer count: {}", response_header.answer_count()); - dbgln(" Authority count: {}", response_header.authority_count()); - dbgln("Additional count: {}", response_header.additional_count()); -#endif - - 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); - offset += 4; -#ifdef LOOKUPSERVER_DEBUG - auto& question = response.m_questions.last(); - dbgln("Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); -#endif - } - - 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? - dbgln("data=(unimplemented record type {})", record.type()); - } -#ifdef LOOKUPSERVER_DEBUG - dbgln("Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data); -#endif - 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/Services/LookupServer/DNSResponse.h b/Services/LookupServer/DNSResponse.h deleted file mode 100644 index 2bfe17fecd..0000000000 --- a/Services/LookupServer/DNSResponse.h +++ /dev/null @@ -1,77 +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/Services/LookupServer/LookupServer.cpp b/Services/LookupServer/LookupServer.cpp deleted file mode 100644 index 16761ec7e4..0000000000 --- a/Services/LookupServer/LookupServer.cpp +++ /dev/null @@ -1,278 +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 -#include - -//#define LOOKUPSERVER_DEBUG - -LookupServer::LookupServer() -{ - auto config = Core::ConfigFile::get_for_system("LookupServer"); - dbgln("Using network config file at {}", config->file_name()); - m_nameservers = config->read_entry("DNS", "Nameservers", "1.1.1.1,1.0.0.1").split(','); - - 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 fields = 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') { - dbgln("Invalid lookup_type '{}'", lookup_type); - return; - } - auto hostname = String((const char*)client_buffer + 1, nrecv - 1, Chomp); -#ifdef LOOKUPSERVER_DEBUG - dbgln("Got request for '{}'", hostname); -#endif - - 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()) { - for (auto& nameserver : m_nameservers) { -#ifdef LOOKUPSERVER_DEBUG - dbgln("Doing lookup using nameserver '{}'", nameserver); -#endif - bool did_get_response = false; - int retries = 3; - do { - if (lookup_type == 'L') - responses = lookup(hostname, nameserver, did_get_response, T_A); - else if (lookup_type == 'R') - responses = lookup(hostname, nameserver, did_get_response, T_PTR); - if (did_get_response) - break; - } while (--retries); - if (!responses.is_empty()) { - break; - } else { - if (!did_get_response) - dbgln("Never got a response from '{}', trying next nameserver", nameserver); - else - dbgln("Received response from '{}' but no result(s), trying next nameserver", nameserver); - } - } - if (responses.is_empty()) { - fprintf(stderr, "LookupServer: Tried all nameservers but never got a response :(\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, const String& nameserver, bool& did_get_response, 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) { -#ifdef LOOKUPSERVER_DEBUG - dbgln("Cache hit: {} -> {}, expired: {}", hostname, cached_answer.record_data(), cached_answer.has_expired()); -#endif - 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(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 {}; - - did_get_response = true; - - 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()) { - dbgln("LookupServer: ID mismatch ({} vs {}) :(", 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, nameserver, did_get_response, record_type, ShouldRandomizeCase::No); - } - return {}; - } - - if (response.question_count() != request.question_count()) { - dbgln("LookupServer: Question count ({} vs {}) :(", 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) { - dbgln("Request and response questions do not match"); - dbgln(" Request: name=_{}_, type={}, class={}", request_question.name(), response_question.record_type(), response_question.class_code()); - dbgln(" Response: name=_{}_, type={}, class={}", response_question.name(), response_question.record_type(), response_question.class_code()); - return {}; - } - } - - if (response.answer_count() < 1) { - dbgln("LookupServer: Not enough answers ({}) :(", 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/Services/LookupServer/LookupServer.h b/Services/LookupServer/LookupServer.h deleted file mode 100644 index 7b5a08140a..0000000000 --- a/Services/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, const String& nameserver, bool& did_get_response, unsigned short record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes); - - struct CachedLookup { - DNSQuestion question; - Vector answers; - }; - - RefPtr m_local_server; - Vector m_nameservers; - HashMap m_etc_hosts; - HashMap m_lookup_cache; -}; diff --git a/Services/LookupServer/main.cpp b/Services/LookupServer/main.cpp deleted file mode 100644 index 23d5933bac..0000000000 --- a/Services/LookupServer/main.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 "LookupServer.h" -#include -#include -#include - -int main([[maybe_unused]] int argc, [[maybe_unused]] char** 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/Services/NotificationServer/CMakeLists.txt b/Services/NotificationServer/CMakeLists.txt deleted file mode 100644 index a28d9f16a5..0000000000 --- a/Services/NotificationServer/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -compile_ipc(NotificationServer.ipc NotificationServerEndpoint.h) -compile_ipc(NotificationClient.ipc NotificationClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - main.cpp - NotificationWindow.cpp - NotificationServerEndpoint.h - NotificationClientEndpoint.h -) - -serenity_bin(NotificationServer) -target_link_libraries(NotificationServer LibGUI LibIPC) diff --git a/Services/NotificationServer/ClientConnection.cpp b/Services/NotificationServer/ClientConnection.cpp deleted file mode 100644 index 9c6cc8051a..0000000000 --- a/Services/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 "NotificationWindow.h" -#include -#include - -namespace NotificationServer { - -static HashMap> s_connections; - -ClientConnection::ClientConnection(NonnullRefPtr client_socket, int client_id) - : IPC::ClientConnection(*this, move(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/Services/NotificationServer/ClientConnection.h b/Services/NotificationServer/ClientConnection.h deleted file mode 100644 index af4e36d0aa..0000000000 --- a/Services/NotificationServer/ClientConnection.h +++ /dev/null @@ -1,50 +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 NotificationServer { - -class ClientConnection final : public IPC::ClientConnection - , public NotificationServerEndpoint { - C_OBJECT(ClientConnection) -public: - ~ClientConnection() override; - - virtual void die() override; - -private: - explicit ClientConnection(NonnullRefPtr, int client_id); - - virtual OwnPtr handle(const Messages::NotificationServer::Greet&) override; - virtual OwnPtr handle(const Messages::NotificationServer::ShowNotification&) override; -}; - -} diff --git a/Services/NotificationServer/NotificationClient.ipc b/Services/NotificationServer/NotificationClient.ipc deleted file mode 100644 index fc85168f76..0000000000 --- a/Services/NotificationServer/NotificationClient.ipc +++ /dev/null @@ -1,4 +0,0 @@ -endpoint NotificationClient = 92 -{ - Dummy() =| -} diff --git a/Services/NotificationServer/NotificationServer.ipc b/Services/NotificationServer/NotificationServer.ipc deleted file mode 100644 index e342ebf2d3..0000000000 --- a/Services/NotificationServer/NotificationServer.ipc +++ /dev/null @@ -1,7 +0,0 @@ -endpoint NotificationServer = 95 -{ - // Basic protocol - Greet() => (i32 client_id) - - ShowNotification([UTF8] String text, [UTF8] String title, Gfx::ShareableBitmap icon) => () -} diff --git a/Services/NotificationServer/NotificationWindow.cpp b/Services/NotificationServer/NotificationWindow.cpp deleted file mode 100644 index e5739b1c3b..0000000000 --- a/Services/NotificationServer/NotificationWindow.cpp +++ /dev/null @@ -1,123 +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 -#include -#include - -namespace NotificationServer { - -static Vector> s_windows; - -void update_notification_window_locations() -{ - Gfx::IntRect last_window_rect; - for (auto& window : s_windows) { - Gfx::IntPoint 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::IntRect 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::IntRect 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& image = widget.add(); - image.set_bitmap(icon.bitmap()); - } - - auto& left_container = widget.add(); - left_container.set_layout(); - - auto& title_label = left_container.add(title); - title_label.set_font(Gfx::FontDatabase::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_fixed_width(36); - 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/Services/NotificationServer/NotificationWindow.h b/Services/NotificationServer/NotificationWindow.h deleted file mode 100644 index 607365fe6e..0000000000 --- a/Services/NotificationServer/NotificationWindow.h +++ /dev/null @@ -1,48 +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 { - -void update_notification_window_locations(); - -class NotificationWindow final : public GUI::Window { - C_OBJECT(NotificationWindow); - -public: - virtual ~NotificationWindow() override; - void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; }; - -private: - NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap&); - - Gfx::IntRect m_original_rect; -}; - -} diff --git a/Services/NotificationServer/main.cpp b/Services/NotificationServer/main.cpp deleted file mode 100644 index 91cd06e0d7..0000000000 --- a/Services/NotificationServer/main.cpp +++ /dev/null @@ -1,74 +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 "NotificationWindow.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; - } - - auto app = GUI::Application::construct(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) { - dbgln("NotificationServer: accept failed."); - return; - } - static int s_next_client_id = 0; - int client_id = ++s_next_client_id; - IPC::new_client_connection(client_socket.release_nonnull(), 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; - } - - GUI::Desktop::the().on_rect_change = [](auto&) { NotificationServer::update_notification_window_locations(); }; - - return app->exec(); -} diff --git a/Services/ProtocolServer/CMakeLists.txt b/Services/ProtocolServer/CMakeLists.txt deleted file mode 100644 index 4fb0757759..0000000000 --- a/Services/ProtocolServer/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -compile_ipc(ProtocolServer.ipc ProtocolServerEndpoint.h) -compile_ipc(ProtocolClient.ipc ProtocolClientEndpoint.h) - -set(SOURCES - ClientConnection.cpp - Download.cpp - GeminiDownload.cpp - GeminiProtocol.cpp - HttpDownload.cpp - HttpProtocol.cpp - HttpsDownload.cpp - HttpsProtocol.cpp - main.cpp - Protocol.cpp - ProtocolServerEndpoint.h - ProtocolClientEndpoint.h -) - -serenity_bin(ProtocolServer) -target_link_libraries(ProtocolServer LibCore LibIPC LibGemini LibHTTP) diff --git a/Services/ProtocolServer/ClientConnection.cpp b/Services/ProtocolServer/ClientConnection.cpp deleted file mode 100644 index e966d2f2f4..0000000000 --- a/Services/ProtocolServer/ClientConnection.cpp +++ /dev/null @@ -1,142 +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 ProtocolServer { - -static HashMap> s_connections; - -ClientConnection::ClientConnection(NonnullRefPtr socket, int client_id) - : IPC::ClientConnection(*this, move(socket), client_id) -{ - s_connections.set(client_id, *this); -} - -ClientConnection::~ClientConnection() -{ -} - -void ClientConnection::die() -{ - s_connections.remove(client_id()); - if (s_connections.is_empty()) - Core::EventLoop::current().quit(0); -} - -OwnPtr ClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message) -{ - bool supported = Protocol::find_by_name(message.protocol().to_lowercase()); - return make(supported); -} - -OwnPtr ClientConnection::handle(const Messages::ProtocolServer::StartDownload& message) -{ - const auto& url = message.url(); - if (!url.is_valid()) { - dbgln("StartDownload: Invalid URL requested: '{}'", url); - return make(-1, Optional {}); - } - auto* protocol = Protocol::find_by_name(url.protocol()); - if (!protocol) { - dbgln("StartDownload: No protocol handler for URL: '{}'", url); - return make(-1, Optional {}); - } - auto download = protocol->start_download(*this, message.method(), url, message.request_headers().entries(), message.request_body()); - if (!download) { - dbgln("StartDownload: Protocol handler failed to start download: '{}'", url); - return make(-1, Optional {}); - } - auto id = download->id(); - auto fd = download->download_fd(); - m_downloads.set(id, move(download)); - auto response = make(id, fd); - response->on_destruction = [fd] { close(fd); }; - return response; -} - -OwnPtr ClientConnection::handle(const Messages::ProtocolServer::StopDownload& message) -{ - auto* download = const_cast(m_downloads.get(message.download_id()).value_or(nullptr)); - bool success = false; - if (download) { - download->stop(); - m_downloads.remove(message.download_id()); - success = true; - } - return make(success); -} - -void ClientConnection::did_receive_headers(Badge, Download& download) -{ - IPC::Dictionary response_headers; - for (auto& it : download.response_headers()) - response_headers.add(it.key, it.value); - - post_message(Messages::ProtocolClient::HeadersBecameAvailable(download.id(), move(response_headers), download.status_code())); -} - -void ClientConnection::did_finish_download(Badge, Download& download, bool success) -{ - ASSERT(download.total_size().has_value()); - - post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.total_size().value())); - - m_downloads.remove(download.id()); -} - -void ClientConnection::did_progress_download(Badge, Download& download) -{ - post_message(Messages::ProtocolClient::DownloadProgress(download.id(), download.total_size(), download.downloaded_size())); -} - -void ClientConnection::did_request_certificates(Badge, Download& download) -{ - post_message(Messages::ProtocolClient::CertificateRequested(download.id())); -} - -OwnPtr ClientConnection::handle(const Messages::ProtocolServer::Greet&) -{ - return make(client_id()); -} - -OwnPtr ClientConnection::handle(const Messages::ProtocolServer::SetCertificate& message) -{ - auto* download = const_cast(m_downloads.get(message.download_id()).value_or(nullptr)); - bool success = false; - if (download) { - download->set_certificate(message.certificate(), message.key()); - success = true; - } - return make(success); -} - -} diff --git a/Services/ProtocolServer/ClientConnection.h b/Services/ProtocolServer/ClientConnection.h deleted file mode 100644 index 778f3eff81..0000000000 --- a/Services/ProtocolServer/ClientConnection.h +++ /dev/null @@ -1,63 +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 ProtocolServer { - -class ClientConnection final - : public IPC::ClientConnection - , public ProtocolServerEndpoint { - C_OBJECT(ClientConnection); - -public: - explicit ClientConnection(NonnullRefPtr, int client_id); - ~ClientConnection() override; - - virtual void die() override; - - void did_receive_headers(Badge, Download&); - void did_finish_download(Badge, Download&, bool success); - void did_progress_download(Badge, Download&); - void did_request_certificates(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::SetCertificate&) override; - - HashMap> m_downloads; -}; - -} diff --git a/Services/ProtocolServer/Download.cpp b/Services/ProtocolServer/Download.cpp deleted file mode 100644 index 11a7d28933..0000000000 --- a/Services/ProtocolServer/Download.cpp +++ /dev/null @@ -1,79 +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 - -namespace ProtocolServer { - -// FIXME: What about rollover? -static i32 s_next_id = 1; - -Download::Download(ClientConnection& client, NonnullOwnPtr&& output_stream) - : m_client(client) - , m_id(s_next_id++) - , m_output_stream(move(output_stream)) -{ -} - -Download::~Download() -{ -} - -void Download::stop() -{ - m_client.did_finish_download({}, *this, false); -} - -void Download::set_response_headers(const HashMap& response_headers) -{ - m_response_headers = response_headers; - m_client.did_receive_headers({}, *this); -} - -void Download::set_certificate(String, String) -{ -} - -void Download::did_finish(bool success) -{ - m_client.did_finish_download({}, *this, success); -} - -void Download::did_progress(Optional total_size, u32 downloaded_size) -{ - m_total_size = total_size; - m_downloaded_size = downloaded_size; - m_client.did_progress_download({}, *this); -} - -void Download::did_request_certificates() -{ - m_client.did_request_certificates({}, *this); -} - -} diff --git a/Services/ProtocolServer/Download.h b/Services/ProtocolServer/Download.h deleted file mode 100644 index 35c60269f4..0000000000 --- a/Services/ProtocolServer/Download.h +++ /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. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace ProtocolServer { - -class Download { -public: - virtual ~Download(); - - i32 id() const { return m_id; } - URL url() const { return m_url; } - - Optional status_code() const { return m_status_code; } - Optional total_size() const { return m_total_size; } - size_t downloaded_size() const { return m_downloaded_size; } - const HashMap& response_headers() const { return m_response_headers; } - - void stop(); - virtual void set_certificate(String, String); - - // FIXME: Want Badge, but can't make one from HttpProtocol, etc. - void set_download_fd(int fd) { m_download_fd = fd; } - int download_fd() const { return m_download_fd; } - -protected: - explicit Download(ClientConnection&, NonnullOwnPtr&&); - - void did_finish(bool success); - void did_progress(Optional total_size, u32 downloaded_size); - void set_status_code(u32 status_code) { m_status_code = status_code; } - void did_request_certificates(); - void set_response_headers(const HashMap&); - void set_downloaded_size(size_t size) { m_downloaded_size = size; } - const OutputFileStream& output_stream() const { return *m_output_stream; } - -private: - ClientConnection& m_client; - i32 m_id { 0 }; - int m_download_fd { -1 }; // Passed to client. - URL m_url; - Optional m_status_code; - Optional m_total_size {}; - size_t m_downloaded_size { 0 }; - NonnullOwnPtr m_output_stream; - HashMap m_response_headers; -}; - -} diff --git a/Services/ProtocolServer/Forward.h b/Services/ProtocolServer/Forward.h deleted file mode 100644 index 06eec6c7ab..0000000000 --- a/Services/ProtocolServer/Forward.h +++ /dev/null @@ -1,40 +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 - -namespace ProtocolServer { - -class ClientConnection; -class Download; -class GeminiProtocol; -class HttpDownload; -class HttpProtocol; -class HttpsDownload; -class HttpsProtocol; -class Protocol; - -} diff --git a/Services/ProtocolServer/GeminiDownload.cpp b/Services/ProtocolServer/GeminiDownload.cpp deleted file mode 100644 index 0bba75519d..0000000000 --- a/Services/ProtocolServer/GeminiDownload.cpp +++ /dev/null @@ -1,84 +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 - -namespace ProtocolServer { - -GeminiDownload::GeminiDownload(ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) - : Download(client, move(output_stream)) - , m_job(job) -{ - m_job->on_finish = [this](bool success) { - if (auto* response = m_job->response()) { - set_downloaded_size(this->output_stream().size()); - if (!response->meta().is_empty()) { - HashMap headers; - headers.set("meta", response->meta()); - // Note: We're setting content-type to meta only on status==SUCCESS - // we should perhaps have a better mechanism for this, since we - // are already shoehorning the concept of "headers" here - if (response->status() >= 20 && response->status() < 30) { - headers.set("content-type", response->meta()); - } - set_response_headers(headers); - } - } - - // signal 100% download progress so any listeners can react - // appropriately - did_progress(downloaded_size(), downloaded_size()); - - did_finish(success); - }; - m_job->on_progress = [this](Optional total, u32 current) { - did_progress(total, current); - }; - m_job->on_certificate_requested = [this](auto&) { - did_request_certificates(); - }; -} - -void GeminiDownload::set_certificate(String certificate, String key) -{ - m_job->set_certificate(move(certificate), move(key)); -} - -GeminiDownload::~GeminiDownload() -{ - m_job->on_finish = nullptr; - m_job->on_progress = nullptr; - m_job->shutdown(); -} - -NonnullOwnPtr GeminiDownload::create_with_job(Badge, ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) -{ - return adopt_own(*new GeminiDownload(client, move(job), move(output_stream))); -} - -} diff --git a/Services/ProtocolServer/GeminiDownload.h b/Services/ProtocolServer/GeminiDownload.h deleted file mode 100644 index fcd81c121f..0000000000 --- a/Services/ProtocolServer/GeminiDownload.h +++ /dev/null @@ -1,49 +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 - -namespace ProtocolServer { - -class GeminiDownload final : public Download { -public: - virtual ~GeminiDownload() override; - static NonnullOwnPtr create_with_job(Badge, ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - -private: - explicit GeminiDownload(ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - - virtual void set_certificate(String certificate, String key) override; - - NonnullRefPtr m_job; -}; - -} diff --git a/Services/ProtocolServer/GeminiProtocol.cpp b/Services/ProtocolServer/GeminiProtocol.cpp deleted file mode 100644 index c09b53ca42..0000000000 --- a/Services/ProtocolServer/GeminiProtocol.cpp +++ /dev/null @@ -1,62 +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 -#include -#include - -namespace ProtocolServer { - -GeminiProtocol::GeminiProtocol() - : Protocol("gemini") -{ -} - -GeminiProtocol::~GeminiProtocol() -{ -} - -OwnPtr GeminiProtocol::start_download(ClientConnection& client, const String&, const URL& url, const HashMap&, ReadonlyBytes) -{ - Gemini::GeminiRequest request; - request.set_url(url); - - auto pipe_result = get_pipe_for_download(); - if (pipe_result.is_error()) - return {}; - - auto output_stream = make(pipe_result.value().write_fd); - output_stream->make_unbuffered(); - auto job = Gemini::GeminiJob::construct(request, *output_stream); - auto download = GeminiDownload::create_with_job({}, client, (Gemini::GeminiJob&)*job, move(output_stream)); - download->set_download_fd(pipe_result.value().read_fd); - job->start(); - return download; -} - -} diff --git a/Services/ProtocolServer/GeminiProtocol.h b/Services/ProtocolServer/GeminiProtocol.h deleted file mode 100644 index 23a4d7c717..0000000000 --- a/Services/ProtocolServer/GeminiProtocol.h +++ /dev/null @@ -1,41 +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 - -namespace ProtocolServer { - -class GeminiProtocol final : public Protocol { -public: - GeminiProtocol(); - virtual ~GeminiProtocol() override; - - virtual OwnPtr start_download(ClientConnection&, const String& method, const URL&, const HashMap&, ReadonlyBytes body) override; -}; - -} diff --git a/Services/ProtocolServer/HttpDownload.cpp b/Services/ProtocolServer/HttpDownload.cpp deleted file mode 100644 index 8ba945d335..0000000000 --- a/Services/ProtocolServer/HttpDownload.cpp +++ /dev/null @@ -1,74 +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 - -namespace ProtocolServer { - -HttpDownload::HttpDownload(ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) - : Download(client, move(output_stream)) - , m_job(job) -{ - m_job->on_headers_received = [this](auto& headers, auto response_code) { - if (response_code.has_value()) - set_status_code(response_code.value()); - set_response_headers(headers); - }; - - m_job->on_finish = [this](bool success) { - if (auto* response = m_job->response()) { - set_status_code(response->code()); - set_response_headers(response->headers()); - set_downloaded_size(this->output_stream().size()); - } - - // 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() -{ - m_job->on_finish = nullptr; - m_job->on_progress = nullptr; - m_job->shutdown(); -} - -NonnullOwnPtr HttpDownload::create_with_job(Badge, ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) -{ - return adopt_own(*new HttpDownload(client, move(job), move(output_stream))); -} - -} diff --git a/Services/ProtocolServer/HttpDownload.h b/Services/ProtocolServer/HttpDownload.h deleted file mode 100644 index 50095bd0e5..0000000000 --- a/Services/ProtocolServer/HttpDownload.h +++ /dev/null @@ -1,47 +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 - -namespace ProtocolServer { - -class HttpDownload final : public Download { -public: - virtual ~HttpDownload() override; - static NonnullOwnPtr create_with_job(Badge, ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - -private: - explicit HttpDownload(ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - - NonnullRefPtr m_job; -}; - -} diff --git a/Services/ProtocolServer/HttpProtocol.cpp b/Services/ProtocolServer/HttpProtocol.cpp deleted file mode 100644 index acc10a88ec..0000000000 --- a/Services/ProtocolServer/HttpProtocol.cpp +++ /dev/null @@ -1,67 +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 - -namespace ProtocolServer { - -HttpProtocol::HttpProtocol() - : Protocol("http") -{ -} - -HttpProtocol::~HttpProtocol() -{ -} - -OwnPtr HttpProtocol::start_download(ClientConnection& client, const String& method, const URL& url, const HashMap& headers, ReadonlyBytes body) -{ - HTTP::HttpRequest request; - if (method.equals_ignoring_case("post")) - request.set_method(HTTP::HttpRequest::Method::POST); - else - request.set_method(HTTP::HttpRequest::Method::GET); - request.set_url(url); - request.set_headers(headers); - request.set_body(body); - - auto pipe_result = get_pipe_for_download(); - if (pipe_result.is_error()) - return {}; - - auto output_stream = make(pipe_result.value().write_fd); - output_stream->make_unbuffered(); - auto job = HTTP::HttpJob::construct(request, *output_stream); - auto download = HttpDownload::create_with_job({}, client, (HTTP::HttpJob&)*job, move(output_stream)); - download->set_download_fd(pipe_result.value().read_fd); - job->start(); - return download; -} - -} diff --git a/Services/ProtocolServer/HttpProtocol.h b/Services/ProtocolServer/HttpProtocol.h deleted file mode 100644 index 8c4a564f37..0000000000 --- a/Services/ProtocolServer/HttpProtocol.h +++ /dev/null @@ -1,41 +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 - -namespace ProtocolServer { - -class HttpProtocol final : public Protocol { -public: - HttpProtocol(); - virtual ~HttpProtocol() override; - - virtual OwnPtr start_download(ClientConnection&, const String& method, const URL&, const HashMap& headers, ReadonlyBytes body) override; -}; - -} diff --git a/Services/ProtocolServer/HttpsDownload.cpp b/Services/ProtocolServer/HttpsDownload.cpp deleted file mode 100644 index 991dd730d8..0000000000 --- a/Services/ProtocolServer/HttpsDownload.cpp +++ /dev/null @@ -1,82 +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 - -namespace ProtocolServer { - -HttpsDownload::HttpsDownload(ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) - : Download(client, move(output_stream)) - , m_job(job) -{ - m_job->on_headers_received = [this](auto& headers, auto response_code) { - if (response_code.has_value()) - set_status_code(response_code.value()); - set_response_headers(headers); - }; - - m_job->on_finish = [this](bool success) { - if (auto* response = m_job->response()) { - set_status_code(response->code()); - set_response_headers(response->headers()); - set_downloaded_size(this->output_stream().size()); - } - - // 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); - }; - m_job->on_certificate_requested = [this](auto&) { - did_request_certificates(); - }; -} - -void HttpsDownload::set_certificate(String certificate, String key) -{ - m_job->set_certificate(move(certificate), move(key)); -} - -HttpsDownload::~HttpsDownload() -{ - m_job->on_finish = nullptr; - m_job->on_progress = nullptr; - m_job->shutdown(); -} - -NonnullOwnPtr HttpsDownload::create_with_job(Badge, ClientConnection& client, NonnullRefPtr job, NonnullOwnPtr&& output_stream) -{ - return adopt_own(*new HttpsDownload(client, move(job), move(output_stream))); -} - -} diff --git a/Services/ProtocolServer/HttpsDownload.h b/Services/ProtocolServer/HttpsDownload.h deleted file mode 100644 index 254172b3f7..0000000000 --- a/Services/ProtocolServer/HttpsDownload.h +++ /dev/null @@ -1,49 +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 - -namespace ProtocolServer { - -class HttpsDownload final : public Download { -public: - virtual ~HttpsDownload() override; - static NonnullOwnPtr create_with_job(Badge, ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - -private: - explicit HttpsDownload(ClientConnection&, NonnullRefPtr, NonnullOwnPtr&&); - - virtual void set_certificate(String certificate, String key) override; - - NonnullRefPtr m_job; -}; - -} diff --git a/Services/ProtocolServer/HttpsProtocol.cpp b/Services/ProtocolServer/HttpsProtocol.cpp deleted file mode 100644 index ef8e63fd0d..0000000000 --- a/Services/ProtocolServer/HttpsProtocol.cpp +++ /dev/null @@ -1,67 +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 - -namespace ProtocolServer { - -HttpsProtocol::HttpsProtocol() - : Protocol("https") -{ -} - -HttpsProtocol::~HttpsProtocol() -{ -} - -OwnPtr HttpsProtocol::start_download(ClientConnection& client, const String& method, const URL& url, const HashMap& headers, ReadonlyBytes body) -{ - HTTP::HttpRequest request; - if (method.equals_ignoring_case("post")) - request.set_method(HTTP::HttpRequest::Method::POST); - else - request.set_method(HTTP::HttpRequest::Method::GET); - request.set_url(url); - request.set_headers(headers); - request.set_body(body); - - auto pipe_result = get_pipe_for_download(); - if (pipe_result.is_error()) - return {}; - - auto output_stream = make(pipe_result.value().write_fd); - output_stream->make_unbuffered(); - auto job = HTTP::HttpsJob::construct(request, *output_stream); - auto download = HttpsDownload::create_with_job({}, client, (HTTP::HttpsJob&)*job, move(output_stream)); - download->set_download_fd(pipe_result.value().read_fd); - job->start(); - return download; -} - -} diff --git a/Services/ProtocolServer/HttpsProtocol.h b/Services/ProtocolServer/HttpsProtocol.h deleted file mode 100644 index 40e59aa271..0000000000 --- a/Services/ProtocolServer/HttpsProtocol.h +++ /dev/null @@ -1,41 +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 - -namespace ProtocolServer { - -class HttpsProtocol final : public Protocol { -public: - HttpsProtocol(); - virtual ~HttpsProtocol() override; - - virtual OwnPtr start_download(ClientConnection&, const String& method, const URL&, const HashMap& headers, ReadonlyBytes body) override; -}; - -} diff --git a/Services/ProtocolServer/Protocol.cpp b/Services/ProtocolServer/Protocol.cpp deleted file mode 100644 index ee8248dfef..0000000000 --- a/Services/ProtocolServer/Protocol.cpp +++ /dev/null @@ -1,67 +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 - -namespace ProtocolServer { - -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(); -} - -Result Protocol::get_pipe_for_download() -{ - int fd_pair[2] { 0 }; - if (pipe(fd_pair) != 0) { - auto saved_errno = errno; - dbgln("Protocol: pipe() failed: {}", strerror(saved_errno)); - return String { strerror(saved_errno) }; - } - fcntl(fd_pair[1], F_SETFL, fcntl(fd_pair[1], F_GETFL) | O_NONBLOCK); - return Pipe { fd_pair[0], fd_pair[1] }; -} - -} diff --git a/Services/ProtocolServer/Protocol.h b/Services/ProtocolServer/Protocol.h deleted file mode 100644 index 89db931afb..0000000000 --- a/Services/ProtocolServer/Protocol.h +++ /dev/null @@ -1,57 +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 - -namespace ProtocolServer { - -class Protocol { -public: - virtual ~Protocol(); - - const String& name() const { return m_name; } - virtual OwnPtr start_download(ClientConnection&, const String& method, const URL&, const HashMap& headers, ReadonlyBytes body) = 0; - - static Protocol* find_by_name(const String&); - -protected: - explicit Protocol(const String& name); - struct Pipe { - int read_fd { -1 }; - int write_fd { -1 }; - }; - static Result get_pipe_for_download(); - -private: - String m_name; -}; - -} diff --git a/Services/ProtocolServer/ProtocolClient.ipc b/Services/ProtocolServer/ProtocolClient.ipc deleted file mode 100644 index 88f4cfc96d..0000000000 --- a/Services/ProtocolServer/ProtocolClient.ipc +++ /dev/null @@ -1,10 +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) =| - HeadersBecameAvailable(i32 download_id, IPC::Dictionary response_headers, Optional status_code) =| - - // Certificate requests - CertificateRequested(i32 download_id) => () -} diff --git a/Services/ProtocolServer/ProtocolServer.ipc b/Services/ProtocolServer/ProtocolServer.ipc deleted file mode 100644 index a89eab506b..0000000000 --- a/Services/ProtocolServer/ProtocolServer.ipc +++ /dev/null @@ -1,13 +0,0 @@ -endpoint ProtocolServer = 9 -{ - // Basic protocol - Greet() => (i32 client_id) - - // Test if a specific protocol is supported, e.g "http" - IsSupportedProtocol(String protocol) => (bool supported) - - // Download API - StartDownload(String method, URL url, IPC::Dictionary request_headers, ByteBuffer request_body) => (i32 download_id, Optional response_fd) - StopDownload(i32 download_id) => (bool success) - SetCertificate(i32 download_id, String certificate, String key) => (bool success) -} diff --git a/Services/ProtocolServer/main.cpp b/Services/ProtocolServer/main.cpp deleted file mode 100644 index 62fc908dd1..0000000000 --- a/Services/ProtocolServer/main.cpp +++ /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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int, char**) -{ - if (pledge("stdio inet shared_buffer accept unix rpath cpath fattr sendfd recvfd", nullptr) < 0) { - perror("pledge"); - return 1; - } - - // Ensure the certificates are read out here. - [[maybe_unused]] auto& certs = DefaultRootCACertificates::the(); - - Core::EventLoop event_loop; - // FIXME: Establish a connection to LookupServer and then drop "unix"? - if (pledge("stdio inet shared_buffer accept unix sendfd recvfd", 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; - } - - [[maybe_unused]] auto gemini = new ProtocolServer::GeminiProtocol; - [[maybe_unused]] auto http = new ProtocolServer::HttpProtocol; - [[maybe_unused]] auto https = new ProtocolServer::HttpsProtocol; - - auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server(); - ASSERT(socket); - IPC::new_client_connection(socket.release_nonnull(), 1); - return event_loop.exec(); -} diff --git a/Services/SystemMenu/CMakeLists.txt b/Services/SystemMenu/CMakeLists.txt deleted file mode 100644 index 8d6a6adee8..0000000000 --- a/Services/SystemMenu/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCES - main.cpp - ShutdownDialog.cpp -) - -serenity_bin(SystemMenu) -target_link_libraries(SystemMenu LibGUI LibDesktop) diff --git a/Services/SystemMenu/ShutdownDialog.cpp b/Services/SystemMenu/ShutdownDialog.cpp deleted file mode 100644 index 5f01b7308e..0000000000 --- a/Services/SystemMenu/ShutdownDialog.cpp +++ /dev/null @@ -1,117 +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 "ShutdownDialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct Option { - String title; - Vector cmd; - bool enabled; - bool default_action; -}; - -static const Vector