mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
ProtocolServer: Put everything in the ProtocolServer namespace
This commit is contained in:
parent
2949c3e5e1
commit
a4902e0eec
21 changed files with 158 additions and 56 deletions
|
@ -2,6 +2,7 @@ compile_ipc(ProtocolServer.ipc ProtocolServerEndpoint.h)
|
||||||
compile_ipc(ProtocolClient.ipc ProtocolClientEndpoint.h)
|
compile_ipc(ProtocolClient.ipc ProtocolClientEndpoint.h)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
|
ClientConnection.cpp
|
||||||
Download.cpp
|
Download.cpp
|
||||||
GeminiDownload.cpp
|
GeminiDownload.cpp
|
||||||
GeminiProtocol.cpp
|
GeminiProtocol.cpp
|
||||||
|
@ -11,7 +12,6 @@ set(SOURCES
|
||||||
HttpsProtocol.cpp
|
HttpsProtocol.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
Protocol.cpp
|
Protocol.cpp
|
||||||
PSClientConnection.cpp
|
|
||||||
ProtocolServerEndpoint.h
|
ProtocolServerEndpoint.h
|
||||||
ProtocolClientEndpoint.h
|
ProtocolClientEndpoint.h
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,34 +27,36 @@
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <AK/SharedBuffer.h>
|
#include <AK/SharedBuffer.h>
|
||||||
#include <ProtocolServer/Download.h>
|
#include <ProtocolServer/Download.h>
|
||||||
#include <ProtocolServer/PSClientConnection.h>
|
#include <ProtocolServer/ClientConnection.h>
|
||||||
#include <ProtocolServer/Protocol.h>
|
#include <ProtocolServer/Protocol.h>
|
||||||
#include <ProtocolServer/ProtocolClientEndpoint.h>
|
#include <ProtocolServer/ProtocolClientEndpoint.h>
|
||||||
|
|
||||||
static HashMap<int, RefPtr<PSClientConnection>> s_connections;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
PSClientConnection::PSClientConnection(Core::LocalSocket& socket, int client_id)
|
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||||
|
|
||||||
|
ClientConnection::ClientConnection(Core::LocalSocket& socket, int client_id)
|
||||||
: IPC::ClientConnection<ProtocolServerEndpoint>(*this, socket, client_id)
|
: IPC::ClientConnection<ProtocolServerEndpoint>(*this, socket, client_id)
|
||||||
{
|
{
|
||||||
s_connections.set(client_id, *this);
|
s_connections.set(client_id, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
PSClientConnection::~PSClientConnection()
|
ClientConnection::~ClientConnection()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSClientConnection::die()
|
void ClientConnection::die()
|
||||||
{
|
{
|
||||||
s_connections.remove(client_id());
|
s_connections.remove(client_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> PSClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message)
|
OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> ClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message)
|
||||||
{
|
{
|
||||||
bool supported = Protocol::find_by_name(message.protocol().to_lowercase());
|
bool supported = Protocol::find_by_name(message.protocol().to_lowercase());
|
||||||
return make<Messages::ProtocolServer::IsSupportedProtocolResponse>(supported);
|
return make<Messages::ProtocolServer::IsSupportedProtocolResponse>(supported);
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::ProtocolServer::StartDownloadResponse> PSClientConnection::handle(const Messages::ProtocolServer::StartDownload& message)
|
OwnPtr<Messages::ProtocolServer::StartDownloadResponse> ClientConnection::handle(const Messages::ProtocolServer::StartDownload& message)
|
||||||
{
|
{
|
||||||
URL url(message.url());
|
URL url(message.url());
|
||||||
if (!url.is_valid())
|
if (!url.is_valid())
|
||||||
|
@ -70,7 +72,7 @@ OwnPtr<Messages::ProtocolServer::StartDownloadResponse> PSClientConnection::hand
|
||||||
return make<Messages::ProtocolServer::StartDownloadResponse>(id);
|
return make<Messages::ProtocolServer::StartDownloadResponse>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::ProtocolServer::StopDownloadResponse> PSClientConnection::handle(const Messages::ProtocolServer::StopDownload& message)
|
OwnPtr<Messages::ProtocolServer::StopDownloadResponse> ClientConnection::handle(const Messages::ProtocolServer::StopDownload& message)
|
||||||
{
|
{
|
||||||
auto* download = const_cast<Download*>(m_downloads.get(message.download_id()).value_or(nullptr));
|
auto* download = const_cast<Download*>(m_downloads.get(message.download_id()).value_or(nullptr));
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -81,7 +83,7 @@ OwnPtr<Messages::ProtocolServer::StopDownloadResponse> PSClientConnection::handl
|
||||||
return make<Messages::ProtocolServer::StopDownloadResponse>(success);
|
return make<Messages::ProtocolServer::StopDownloadResponse>(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSClientConnection::did_finish_download(Badge<Download>, Download& download, bool success)
|
void ClientConnection::did_finish_download(Badge<Download>, Download& download, bool success)
|
||||||
{
|
{
|
||||||
RefPtr<SharedBuffer> buffer;
|
RefPtr<SharedBuffer> buffer;
|
||||||
if (success && download.payload().size() > 0 && !download.payload().is_null()) {
|
if (success && download.payload().size() > 0 && !download.payload().is_null()) {
|
||||||
|
@ -101,18 +103,20 @@ void PSClientConnection::did_finish_download(Badge<Download>, Download& download
|
||||||
m_downloads.remove(download.id());
|
m_downloads.remove(download.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSClientConnection::did_progress_download(Badge<Download>, Download& download)
|
void ClientConnection::did_progress_download(Badge<Download>, Download& download)
|
||||||
{
|
{
|
||||||
post_message(Messages::ProtocolClient::DownloadProgress(download.id(), download.total_size(), download.downloaded_size()));
|
post_message(Messages::ProtocolClient::DownloadProgress(download.id(), download.total_size(), download.downloaded_size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::ProtocolServer::GreetResponse> PSClientConnection::handle(const Messages::ProtocolServer::Greet&)
|
OwnPtr<Messages::ProtocolServer::GreetResponse> ClientConnection::handle(const Messages::ProtocolServer::Greet&)
|
||||||
{
|
{
|
||||||
return make<Messages::ProtocolServer::GreetResponse>(client_id());
|
return make<Messages::ProtocolServer::GreetResponse>(client_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::ProtocolServer::DisownSharedBufferResponse> PSClientConnection::handle(const Messages::ProtocolServer::DisownSharedBuffer& message)
|
OwnPtr<Messages::ProtocolServer::DisownSharedBufferResponse> ClientConnection::handle(const Messages::ProtocolServer::DisownSharedBuffer& message)
|
||||||
{
|
{
|
||||||
m_shared_buffers.remove(message.shbuf_id());
|
m_shared_buffers.remove(message.shbuf_id());
|
||||||
return make<Messages::ProtocolServer::DisownSharedBufferResponse>();
|
return make<Messages::ProtocolServer::DisownSharedBufferResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -29,15 +29,18 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <LibIPC/ClientConnection.h>
|
#include <LibIPC/ClientConnection.h>
|
||||||
#include <ProtocolServer/ProtocolServerEndpoint.h>
|
#include <ProtocolServer/ProtocolServerEndpoint.h>
|
||||||
|
#include <ProtocolServer/Forward.h>
|
||||||
|
|
||||||
class Download;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class PSClientConnection final : public IPC::ClientConnection<ProtocolServerEndpoint>
|
class ClientConnection final
|
||||||
|
: public IPC::ClientConnection<ProtocolServerEndpoint>
|
||||||
, public ProtocolServerEndpoint {
|
, public ProtocolServerEndpoint {
|
||||||
C_OBJECT(PSClientConnection)
|
C_OBJECT(ClientConnection);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PSClientConnection(Core::LocalSocket&, int client_id);
|
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||||
~PSClientConnection() override;
|
~ClientConnection() override;
|
||||||
|
|
||||||
virtual void die() override;
|
virtual void die() override;
|
||||||
|
|
||||||
|
@ -54,3 +57,5 @@ private:
|
||||||
HashMap<i32, OwnPtr<Download>> m_downloads;
|
HashMap<i32, OwnPtr<Download>> m_downloads;
|
||||||
HashMap<i32, RefPtr<AK::SharedBuffer>> m_shared_buffers;
|
HashMap<i32, RefPtr<AK::SharedBuffer>> m_shared_buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -26,12 +26,14 @@
|
||||||
|
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <ProtocolServer/Download.h>
|
#include <ProtocolServer/Download.h>
|
||||||
#include <ProtocolServer/PSClientConnection.h>
|
#include <ProtocolServer/ClientConnection.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
// FIXME: What about rollover?
|
// FIXME: What about rollover?
|
||||||
static i32 s_next_id = 1;
|
static i32 s_next_id = 1;
|
||||||
|
|
||||||
Download::Download(PSClientConnection& client)
|
Download::Download(ClientConnection& client)
|
||||||
: m_client(client)
|
: m_client(client)
|
||||||
, m_id(s_next_id++)
|
, m_id(s_next_id++)
|
||||||
{
|
{
|
||||||
|
@ -68,3 +70,5 @@ void Download::did_progress(Optional<u32> total_size, u32 downloaded_size)
|
||||||
m_downloaded_size = downloaded_size;
|
m_downloaded_size = downloaded_size;
|
||||||
m_client.did_progress_download({}, *this);
|
m_client.did_progress_download({}, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -31,8 +31,9 @@
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
|
#include <ProtocolServer/Forward.h>
|
||||||
|
|
||||||
class PSClientConnection;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class Download {
|
class Download {
|
||||||
public:
|
public:
|
||||||
|
@ -49,7 +50,7 @@ public:
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Download(PSClientConnection&);
|
explicit Download(ClientConnection&);
|
||||||
|
|
||||||
void did_finish(bool success);
|
void did_finish(bool success);
|
||||||
void did_progress(Optional<u32> total_size, u32 downloaded_size);
|
void did_progress(Optional<u32> total_size, u32 downloaded_size);
|
||||||
|
@ -57,7 +58,7 @@ protected:
|
||||||
void set_response_headers(const HashMap<String, String, CaseInsensitiveStringTraits>&);
|
void set_response_headers(const HashMap<String, String, CaseInsensitiveStringTraits>&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PSClientConnection& m_client;
|
ClientConnection& m_client;
|
||||||
i32 m_id { 0 };
|
i32 m_id { 0 };
|
||||||
URL m_url;
|
URL m_url;
|
||||||
Optional<u32> m_total_size {};
|
Optional<u32> m_total_size {};
|
||||||
|
@ -65,3 +66,5 @@ private:
|
||||||
ByteBuffer m_payload;
|
ByteBuffer m_payload;
|
||||||
HashMap<String, String, CaseInsensitiveStringTraits> m_response_headers;
|
HashMap<String, String, CaseInsensitiveStringTraits> m_response_headers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
38
Services/ProtocolServer/Forward.h
Normal file
38
Services/ProtocolServer/Forward.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
|
* 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 HttpProtocol;
|
||||||
|
class HttpsProtocol;
|
||||||
|
class Protocol;
|
||||||
|
|
||||||
|
}
|
|
@ -24,11 +24,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibGemini/GeminiResponse.h>
|
|
||||||
#include <LibGemini/GeminiJob.h>
|
#include <LibGemini/GeminiJob.h>
|
||||||
|
#include <LibGemini/GeminiResponse.h>
|
||||||
#include <ProtocolServer/GeminiDownload.h>
|
#include <ProtocolServer/GeminiDownload.h>
|
||||||
|
|
||||||
GeminiDownload::GeminiDownload(PSClientConnection& client, NonnullRefPtr<Gemini::GeminiJob> job)
|
namespace ProtocolServer {
|
||||||
|
|
||||||
|
GeminiDownload::GeminiDownload(ClientConnection& client, NonnullRefPtr<Gemini::GeminiJob> job)
|
||||||
: Download(client)
|
: Download(client)
|
||||||
, m_job(job)
|
, m_job(job)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +62,9 @@ GeminiDownload::~GeminiDownload()
|
||||||
m_job->shutdown();
|
m_job->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<GeminiDownload> GeminiDownload::create_with_job(Badge<GeminiProtocol>, PSClientConnection& client, NonnullRefPtr<Gemini::GeminiJob> job)
|
NonnullOwnPtr<GeminiDownload> GeminiDownload::create_with_job(Badge<GeminiProtocol>, ClientConnection& client, NonnullRefPtr<Gemini::GeminiJob> job)
|
||||||
{
|
{
|
||||||
return adopt_own(*new GeminiDownload(client, move(job)));
|
return adopt_own(*new GeminiDownload(client, move(job)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,18 +28,20 @@
|
||||||
|
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <LibCore/Forward.h>
|
#include <LibCore/Forward.h>
|
||||||
#include <LibGemini/GeminiJob.h>
|
#include <LibGemini/Forward.h>
|
||||||
#include <ProtocolServer/Download.h>
|
#include <ProtocolServer/Download.h>
|
||||||
|
|
||||||
class GeminiProtocol;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class GeminiDownload final : public Download {
|
class GeminiDownload final : public Download {
|
||||||
public:
|
public:
|
||||||
virtual ~GeminiDownload() override;
|
virtual ~GeminiDownload() override;
|
||||||
static NonnullOwnPtr<GeminiDownload> create_with_job(Badge<GeminiProtocol>, PSClientConnection&, NonnullRefPtr<Gemini::GeminiJob>);
|
static NonnullOwnPtr<GeminiDownload> create_with_job(Badge<GeminiProtocol>, ClientConnection&, NonnullRefPtr<Gemini::GeminiJob>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GeminiDownload(PSClientConnection&, NonnullRefPtr<Gemini::GeminiJob>);
|
explicit GeminiDownload(ClientConnection&, NonnullRefPtr<Gemini::GeminiJob>);
|
||||||
|
|
||||||
NonnullRefPtr<Gemini::GeminiJob> m_job;
|
NonnullRefPtr<Gemini::GeminiJob> m_job;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -24,11 +24,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibGemini/GeminiRequest.h>
|
|
||||||
#include <LibGemini/GeminiJob.h>
|
#include <LibGemini/GeminiJob.h>
|
||||||
|
#include <LibGemini/GeminiRequest.h>
|
||||||
#include <ProtocolServer/GeminiDownload.h>
|
#include <ProtocolServer/GeminiDownload.h>
|
||||||
#include <ProtocolServer/GeminiProtocol.h>
|
#include <ProtocolServer/GeminiProtocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
GeminiProtocol::GeminiProtocol()
|
GeminiProtocol::GeminiProtocol()
|
||||||
: Protocol("gemini")
|
: Protocol("gemini")
|
||||||
{
|
{
|
||||||
|
@ -38,7 +40,7 @@ GeminiProtocol::~GeminiProtocol()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Download> GeminiProtocol::start_download(PSClientConnection& client, const URL& url)
|
OwnPtr<Download> GeminiProtocol::start_download(ClientConnection& client, const URL& url)
|
||||||
{
|
{
|
||||||
Gemini::GeminiRequest request;
|
Gemini::GeminiRequest request;
|
||||||
request.set_url(url);
|
request.set_url(url);
|
||||||
|
@ -47,3 +49,5 @@ OwnPtr<Download> GeminiProtocol::start_download(PSClientConnection& client, cons
|
||||||
job->start();
|
job->start();
|
||||||
return download;
|
return download;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,10 +28,14 @@
|
||||||
|
|
||||||
#include <ProtocolServer/Protocol.h>
|
#include <ProtocolServer/Protocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class GeminiProtocol final : public Protocol {
|
class GeminiProtocol final : public Protocol {
|
||||||
public:
|
public:
|
||||||
GeminiProtocol();
|
GeminiProtocol();
|
||||||
virtual ~GeminiProtocol() override;
|
virtual ~GeminiProtocol() override;
|
||||||
|
|
||||||
virtual OwnPtr<Download> start_download(PSClientConnection&, const URL&) override;
|
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
#include <LibHTTP/HttpResponse.h>
|
#include <LibHTTP/HttpResponse.h>
|
||||||
#include <ProtocolServer/HttpDownload.h>
|
#include <ProtocolServer/HttpDownload.h>
|
||||||
|
|
||||||
HttpDownload::HttpDownload(PSClientConnection& client, NonnullRefPtr<HTTP::HttpJob> job)
|
namespace ProtocolServer {
|
||||||
|
|
||||||
|
HttpDownload::HttpDownload(ClientConnection& client, NonnullRefPtr<HTTP::HttpJob> job)
|
||||||
: Download(client)
|
: Download(client)
|
||||||
, m_job(job)
|
, m_job(job)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +59,9 @@ HttpDownload::~HttpDownload()
|
||||||
m_job->shutdown();
|
m_job->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<HttpDownload> HttpDownload::create_with_job(Badge<HttpProtocol>, PSClientConnection& client, NonnullRefPtr<HTTP::HttpJob> job)
|
NonnullOwnPtr<HttpDownload> HttpDownload::create_with_job(Badge<HttpProtocol>, ClientConnection& client, NonnullRefPtr<HTTP::HttpJob> job)
|
||||||
{
|
{
|
||||||
return adopt_own(*new HttpDownload(client, move(job)));
|
return adopt_own(*new HttpDownload(client, move(job)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,18 +28,20 @@
|
||||||
|
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <LibCore/Forward.h>
|
#include <LibCore/Forward.h>
|
||||||
#include <LibHTTP/HttpJob.h>
|
#include <LibHTTP/Forward.h>
|
||||||
#include <ProtocolServer/Download.h>
|
#include <ProtocolServer/Download.h>
|
||||||
|
|
||||||
class HttpProtocol;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class HttpDownload final : public Download {
|
class HttpDownload final : public Download {
|
||||||
public:
|
public:
|
||||||
virtual ~HttpDownload() override;
|
virtual ~HttpDownload() override;
|
||||||
static NonnullOwnPtr<HttpDownload> create_with_job(Badge<HttpProtocol>, PSClientConnection&, NonnullRefPtr<HTTP::HttpJob>);
|
static NonnullOwnPtr<HttpDownload> create_with_job(Badge<HttpProtocol>, ClientConnection&, NonnullRefPtr<HTTP::HttpJob>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit HttpDownload(PSClientConnection&, NonnullRefPtr<HTTP::HttpJob>);
|
explicit HttpDownload(ClientConnection&, NonnullRefPtr<HTTP::HttpJob>);
|
||||||
|
|
||||||
NonnullRefPtr<HTTP::HttpJob> m_job;
|
NonnullRefPtr<HTTP::HttpJob> m_job;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <ProtocolServer/HttpDownload.h>
|
#include <ProtocolServer/HttpDownload.h>
|
||||||
#include <ProtocolServer/HttpProtocol.h>
|
#include <ProtocolServer/HttpProtocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
HttpProtocol::HttpProtocol()
|
HttpProtocol::HttpProtocol()
|
||||||
: Protocol("http")
|
: Protocol("http")
|
||||||
{
|
{
|
||||||
|
@ -38,7 +40,7 @@ HttpProtocol::~HttpProtocol()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Download> HttpProtocol::start_download(PSClientConnection& client, const URL& url)
|
OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const URL& url)
|
||||||
{
|
{
|
||||||
HTTP::HttpRequest request;
|
HTTP::HttpRequest request;
|
||||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||||
|
@ -48,3 +50,5 @@ OwnPtr<Download> HttpProtocol::start_download(PSClientConnection& client, const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return HttpDownload::create_with_job({}, client, (HTTP::HttpJob&)*job);
|
return HttpDownload::create_with_job({}, client, (HTTP::HttpJob&)*job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,10 +28,14 @@
|
||||||
|
|
||||||
#include <ProtocolServer/Protocol.h>
|
#include <ProtocolServer/Protocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class HttpProtocol final : public Protocol {
|
class HttpProtocol final : public Protocol {
|
||||||
public:
|
public:
|
||||||
HttpProtocol();
|
HttpProtocol();
|
||||||
virtual ~HttpProtocol() override;
|
virtual ~HttpProtocol() override;
|
||||||
|
|
||||||
virtual OwnPtr<Download> start_download(PSClientConnection&, const URL&) override;
|
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
#include <LibHTTP/HttpsJob.h>
|
#include <LibHTTP/HttpsJob.h>
|
||||||
#include <ProtocolServer/HttpsDownload.h>
|
#include <ProtocolServer/HttpsDownload.h>
|
||||||
|
|
||||||
HttpsDownload::HttpsDownload(PSClientConnection& client, NonnullRefPtr<HTTP::HttpsJob> job)
|
namespace ProtocolServer {
|
||||||
|
|
||||||
|
HttpsDownload::HttpsDownload(ClientConnection& client, NonnullRefPtr<HTTP::HttpsJob> job)
|
||||||
: Download(client)
|
: Download(client)
|
||||||
, m_job(job)
|
, m_job(job)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +59,9 @@ HttpsDownload::~HttpsDownload()
|
||||||
m_job->shutdown();
|
m_job->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<HttpsDownload> HttpsDownload::create_with_job(Badge<HttpsProtocol>, PSClientConnection& client, NonnullRefPtr<HTTP::HttpsJob> job)
|
NonnullOwnPtr<HttpsDownload> HttpsDownload::create_with_job(Badge<HttpsProtocol>, ClientConnection& client, NonnullRefPtr<HTTP::HttpsJob> job)
|
||||||
{
|
{
|
||||||
return adopt_own(*new HttpsDownload(client, move(job)));
|
return adopt_own(*new HttpsDownload(client, move(job)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -31,15 +31,17 @@
|
||||||
#include <LibHTTP/HttpsJob.h>
|
#include <LibHTTP/HttpsJob.h>
|
||||||
#include <ProtocolServer/Download.h>
|
#include <ProtocolServer/Download.h>
|
||||||
|
|
||||||
class HttpsProtocol;
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class HttpsDownload final : public Download {
|
class HttpsDownload final : public Download {
|
||||||
public:
|
public:
|
||||||
virtual ~HttpsDownload() override;
|
virtual ~HttpsDownload() override;
|
||||||
static NonnullOwnPtr<HttpsDownload> create_with_job(Badge<HttpsProtocol>, PSClientConnection&, NonnullRefPtr<HTTP::HttpsJob>);
|
static NonnullOwnPtr<HttpsDownload> create_with_job(Badge<HttpsProtocol>, ClientConnection&, NonnullRefPtr<HTTP::HttpsJob>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit HttpsDownload(PSClientConnection&, NonnullRefPtr<HTTP::HttpsJob>);
|
explicit HttpsDownload(ClientConnection&, NonnullRefPtr<HTTP::HttpsJob>);
|
||||||
|
|
||||||
NonnullRefPtr<HTTP::HttpsJob> m_job;
|
NonnullRefPtr<HTTP::HttpsJob> m_job;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <ProtocolServer/HttpsDownload.h>
|
#include <ProtocolServer/HttpsDownload.h>
|
||||||
#include <ProtocolServer/HttpsProtocol.h>
|
#include <ProtocolServer/HttpsProtocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
HttpsProtocol::HttpsProtocol()
|
HttpsProtocol::HttpsProtocol()
|
||||||
: Protocol("https")
|
: Protocol("https")
|
||||||
{
|
{
|
||||||
|
@ -38,7 +40,7 @@ HttpsProtocol::~HttpsProtocol()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Download> HttpsProtocol::start_download(PSClientConnection& client, const URL& url)
|
OwnPtr<Download> HttpsProtocol::start_download(ClientConnection& client, const URL& url)
|
||||||
{
|
{
|
||||||
HTTP::HttpRequest request;
|
HTTP::HttpRequest request;
|
||||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||||
|
@ -48,3 +50,5 @@ OwnPtr<Download> HttpsProtocol::start_download(PSClientConnection& client, const
|
||||||
job->start();
|
job->start();
|
||||||
return download;
|
return download;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,10 +28,14 @@
|
||||||
|
|
||||||
#include <ProtocolServer/Protocol.h>
|
#include <ProtocolServer/Protocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
class HttpsProtocol final : public Protocol {
|
class HttpsProtocol final : public Protocol {
|
||||||
public:
|
public:
|
||||||
HttpsProtocol();
|
HttpsProtocol();
|
||||||
virtual ~HttpsProtocol() override;
|
virtual ~HttpsProtocol() override;
|
||||||
|
|
||||||
virtual OwnPtr<Download> start_download(PSClientConnection&, const URL&) override;
|
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <ProtocolServer/Protocol.h>
|
#include <ProtocolServer/Protocol.h>
|
||||||
|
|
||||||
|
namespace ProtocolServer {
|
||||||
|
|
||||||
static HashMap<String, Protocol*>& all_protocols()
|
static HashMap<String, Protocol*>& all_protocols()
|
||||||
{
|
{
|
||||||
static HashMap<String, Protocol*> map;
|
static HashMap<String, Protocol*> map;
|
||||||
|
@ -47,3 +49,5 @@ Protocol::~Protocol()
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
|
#include <ProtocolServer/Forward.h>
|
||||||
|
|
||||||
class Download;
|
namespace ProtocolServer {
|
||||||
class PSClientConnection;
|
|
||||||
|
|
||||||
class Protocol {
|
class Protocol {
|
||||||
public:
|
public:
|
||||||
virtual ~Protocol();
|
virtual ~Protocol();
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
virtual OwnPtr<Download> start_download(PSClientConnection&, const URL&) = 0;
|
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) = 0;
|
||||||
|
|
||||||
static Protocol* find_by_name(const String&);
|
static Protocol* find_by_name(const String&);
|
||||||
|
|
||||||
|
@ -47,3 +47,5 @@ protected:
|
||||||
private:
|
private:
|
||||||
String m_name;
|
String m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <ProtocolServer/GeminiProtocol.h>
|
#include <ProtocolServer/GeminiProtocol.h>
|
||||||
#include <ProtocolServer/HttpProtocol.h>
|
#include <ProtocolServer/HttpProtocol.h>
|
||||||
#include <ProtocolServer/HttpsProtocol.h>
|
#include <ProtocolServer/HttpsProtocol.h>
|
||||||
#include <ProtocolServer/PSClientConnection.h>
|
#include <ProtocolServer/ClientConnection.h>
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
|
@ -53,9 +53,9 @@ int main(int, char**)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)*new GeminiProtocol;
|
(void)*new ProtocolServer::GeminiProtocol;
|
||||||
(void)*new HttpProtocol;
|
(void)*new ProtocolServer::HttpProtocol;
|
||||||
(void)*new HttpsProtocol;
|
(void)*new ProtocolServer::HttpsProtocol;
|
||||||
auto server = Core::LocalServer::construct();
|
auto server = Core::LocalServer::construct();
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
ASSERT(ok);
|
ASSERT(ok);
|
||||||
|
@ -67,7 +67,7 @@ int main(int, char**)
|
||||||
}
|
}
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
int client_id = ++s_next_client_id;
|
||||||
IPC::new_client_connection<PSClientConnection>(*client_socket, client_id);
|
IPC::new_client_connection<ProtocolServer::ClientConnection>(*client_socket, client_id);
|
||||||
};
|
};
|
||||||
return event_loop.exec();
|
return event_loop.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue