From 78fa6befd5ece68044816125021bb1999982e946 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Fri, 29 Nov 2024 23:12:04 +0100 Subject: [PATCH] wip --- src/apps/hideo-chat/ws/main.cpp | 21 +++++++++++++++ src/apps/hideo-chat/ws/manifest.json | 11 ++++++++ src/libs/karm-crypto/_embed.h | 9 +++++++ src/libs/karm-crypto/crypt.h | 5 ++++ src/libs/karm-crypto/rand.h | 5 ++++ src/libs/karm-crypto/readme.md | 3 +++ src/libs/karm-net/router.h | 39 ++++++++++++++++++++++++++++ src/libs/karm-net/server.h | 38 +++++++++++++++++++++++++++ src/libs/karm-store/query.h | 8 ++++++ src/libs/karm-store/store.h | 5 ++++ 10 files changed, 144 insertions(+) create mode 100644 src/apps/hideo-chat/ws/main.cpp create mode 100644 src/apps/hideo-chat/ws/manifest.json create mode 100644 src/libs/karm-crypto/_embed.h create mode 100644 src/libs/karm-crypto/crypt.h create mode 100644 src/libs/karm-crypto/rand.h create mode 100644 src/libs/karm-crypto/readme.md create mode 100644 src/libs/karm-net/router.h create mode 100644 src/libs/karm-net/server.h create mode 100644 src/libs/karm-store/query.h create mode 100644 src/libs/karm-store/store.h diff --git a/src/apps/hideo-chat/ws/main.cpp b/src/apps/hideo-chat/ws/main.cpp new file mode 100644 index 0000000000..45926b1e74 --- /dev/null +++ b/src/apps/hideo-chat/ws/main.cpp @@ -0,0 +1,21 @@ +#include +#include + +namespace Hideo::Chat { + +Strong app() { + return Net::router({ + Net::get( + "/user/:id", + [](Net::Scope const &, Net::Route::Params, Strong, Strong) -> Async::Task<> { + co_return Ok(); + } + ), + }); +} + +} // namespace Hideo::Chat + +Async::Task<> entryPointAsync(Sys::Context &) { + return Net::servAsync(Hideo::Chat::app()); +} diff --git a/src/apps/hideo-chat/ws/manifest.json b/src/apps/hideo-chat/ws/manifest.json new file mode 100644 index 0000000000..883aebaeb9 --- /dev/null +++ b/src/apps/hideo-chat/ws/manifest.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", + "id": "hideo-chat.ws", + "props": { + "cpp-excluded": true + }, + "type": "exe", + "requires": [ + "karm-net" + ] +} diff --git a/src/libs/karm-crypto/_embed.h b/src/libs/karm-crypto/_embed.h new file mode 100644 index 0000000000..a90a9bedfa --- /dev/null +++ b/src/libs/karm-crypto/_embed.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace Karm::Crypto::_Embed { + +Res<> sRand(MutBytes buf); + +} // namespace Karm::Crypto::_Embed diff --git a/src/libs/karm-crypto/crypt.h b/src/libs/karm-crypto/crypt.h new file mode 100644 index 0000000000..84bc78df8e --- /dev/null +++ b/src/libs/karm-crypto/crypt.h @@ -0,0 +1,5 @@ +#pragma once + +namespace Karm::Crypto { + +} // namespace Karm::Crypto diff --git a/src/libs/karm-crypto/rand.h b/src/libs/karm-crypto/rand.h new file mode 100644 index 0000000000..84bc78df8e --- /dev/null +++ b/src/libs/karm-crypto/rand.h @@ -0,0 +1,5 @@ +#pragma once + +namespace Karm::Crypto { + +} // namespace Karm::Crypto diff --git a/src/libs/karm-crypto/readme.md b/src/libs/karm-crypto/readme.md new file mode 100644 index 0000000000..fddcb6f97d --- /dev/null +++ b/src/libs/karm-crypto/readme.md @@ -0,0 +1,3 @@ +# Karm Crypto + +"People say not to roll your own crypto... Oh well..." diff --git a/src/libs/karm-net/router.h b/src/libs/karm-net/router.h new file mode 100644 index 0000000000..e9ba482bbd --- /dev/null +++ b/src/libs/karm-net/router.h @@ -0,0 +1,39 @@ +#pragma once + +#include "server.h" + +namespace Karm::Net { + +struct Route { + using Params = Map; + + using Handler = Func(Scope const &scope, Params params, Strong recv, Strong send)>; + + virtual ~Route() = default; + + virtual bool accept(Scope const &scope) const = 0; + + virtual Async::Task<> handleAsync(Scope const &scope, Strong recv, Strong send) = 0; +}; + +struct HttpRoute : public Route {}; + +Strong get(Str path, Route::Handler handler); + +Strong post(Str path, Route::Handler handler); + +Strong put(Str path, Route::Handler handler); + +Strong del(Str path, Route::Handler handler); + +struct WsRoute : public Route {}; + +Strong ws(Str path, Route::Handler handler); + +struct Router : public App { + Vec> routes; +}; + +Strong router(Vec> routes); + +} // namespace Karm::Net diff --git a/src/libs/karm-net/server.h b/src/libs/karm-net/server.h new file mode 100644 index 0000000000..c0032e983d --- /dev/null +++ b/src/libs/karm-net/server.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace Karm::Net { + +struct Scope { + enum struct _Type { + WEBSOCKET, + HTTP, + }; + + using enum _Type; + + _Type type; + Mime::Url url; + Map headers; +}; + +struct Recv { +}; + +struct Send { +}; + +struct App { + virtual ~App() = default; + virtual Async::Task<> handleAsync(Scope, Strong, Strong) = 0; +}; + +struct ServProps { +}; + +Async::Task<> servAsync(Strong app, ServProps props = {}); + +} // namespace Karm::Net diff --git a/src/libs/karm-store/query.h b/src/libs/karm-store/query.h new file mode 100644 index 0000000000..49d20c6eaf --- /dev/null +++ b/src/libs/karm-store/query.h @@ -0,0 +1,8 @@ +#pragma once + +namespace Karm::Store { + +struct Query { +}; + +} // namespace Karm::Store diff --git a/src/libs/karm-store/store.h b/src/libs/karm-store/store.h new file mode 100644 index 0000000000..f6a91d6209 --- /dev/null +++ b/src/libs/karm-store/store.h @@ -0,0 +1,5 @@ +#pragma once + +namespace Karm::Store { + +} // namespace Karm::Store