summaryrefslogtreecommitdiff
path: root/Servers/ProtocolServer/Protocol.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-23 21:45:33 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-23 21:50:32 +0100
commitfd4349a9f21b5e5eab660dd5c375e4bdf3413fd7 (patch)
treee4a17b017725a47669da53ff8737b4ce05b3cbc5 /Servers/ProtocolServer/Protocol.cpp
parent61f611bf3cbdaa726a86c14524912ebff591d868 (diff)
downloadserenity-fd4349a9f21b5e5eab660dd5c375e4bdf3413fd7.zip
ProtocolServer+LibProtocol: Introduce a server for handling downloads
This patch adds ProtocolServer, a server that handles network requests on behalf of its clients. The first protocol implemented is HTTP. The idea here is to use a plug-in architecture where any number of protocols can be added and implemented without having to mess around with each client program that wants to use the protocol. A simple client API is provided through LibProtocol::Client. :^)
Diffstat (limited to 'Servers/ProtocolServer/Protocol.cpp')
-rw-r--r--Servers/ProtocolServer/Protocol.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Servers/ProtocolServer/Protocol.cpp b/Servers/ProtocolServer/Protocol.cpp
new file mode 100644
index 0000000000..7d29458eb5
--- /dev/null
+++ b/Servers/ProtocolServer/Protocol.cpp
@@ -0,0 +1,23 @@
+#include <AK/HashMap.h>
+#include <ProtocolServer/Protocol.h>
+
+static HashMap<String, Protocol*>& all_protocols()
+{
+ static HashMap<String, Protocol*> 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();
+}