Compare commits

..

No commits in common. "5c250ac434114f2b1e2a161151bc041131c50146" and "a98f2e8552a8554e406f8c0abb5e0fdf4397964b" have entirely different histories.

7 changed files with 23 additions and 154 deletions

View file

@ -10,7 +10,7 @@ FROM archlinux@sha256:a10e51dd0694d6c4142754e9d06cbce7baf91ace8031a30df37064d109
RUN pacman -Syyu --noconfirm \ RUN pacman -Syyu --noconfirm \
&& pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \ && pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \
&& pacman -Syyu --noconfirm cmake make gcc ninja meson shellcheck \ && pacman -Syyu --noconfirm cmake make gcc ninja meson shellcheck \
&& pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0 gtest && pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0
# Create a non-root user 'dev' # Create a non-root user 'dev'
RUN useradd -ms /bin/bash dev \ RUN useradd -ms /bin/bash dev \
@ -37,25 +37,23 @@ ADD https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}/L
# Create the LLVM directory and extract only binaries into it # Create the LLVM directory and extract only binaries into it
RUN sudo mkdir -p /home/LLVM-${LLVM_VER} RUN sudo mkdir -p /home/LLVM-${LLVM_VER}
RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 \
#RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 \ LLVM-${LLVM_VER}-Linux-X64/bin/clang-19 \
# LLVM-${LLVM_VER}-Linux-X64/bin/clangd \ LLVM-${LLVM_VER}-Linux-X64/bin/clang \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-19 \ LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang \ LLVM-${LLVM_VER}-Linux-X64/bin/lld \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \ LLVM-${LLVM_VER}-Linux-X64/bin/ld.lld \
# LLVM-${LLVM_VER}-Linux-X64/bin/lld \ LLVM-${LLVM_VER}-Linux-X64/bin/ld64.lld \
# LLVM-${LLVM_VER}-Linux-X64/bin/ld.lld \ LLVM-${LLVM_VER}-Linux-X64/bin/clang-scan-deps \
# LLVM-${LLVM_VER}-Linux-X64/bin/ld64.lld \ LLVM-${LLVM_VER}-Linux-X64/bin/llvm-symbolizer \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-scan-deps \ LLVM-${LLVM_VER}-Linux-X64/bin/clang-format \
# LLVM-${LLVM_VER}-Linux-X64/bin/llvm-symbolizer \ LLVM-${LLVM_VER}-Linux-X64/bin/clang-tidy \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-format \ LLVM-${LLVM_VER}-Linux-X64/bin/clang-apply-replacements \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-tidy \ LLVM-${LLVM_VER}-Linux-X64/include/ \
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-apply-replacements \ LLVM-${LLVM_VER}-Linux-X64/lib/ \
# LLVM-${LLVM_VER}-Linux-X64/include/ \ LLVM-${LLVM_VER}-Linux-X64/libexec/ \
# LLVM-${LLVM_VER}-Linux-X64/lib/ \ LLVM-${LLVM_VER}-Linux-X64/local/ \
# LLVM-${LLVM_VER}-Linux-X64/libexec/ \ LLVM-${LLVM_VER}-Linux-X64/share/
# LLVM-${LLVM_VER}-Linux-X64/local/ \
# LLVM-${LLVM_VER}-Linux-X64/share/
# Add /home/LLVM-${LLVM_VER}/bin to the PATH environment variable # Add /home/LLVM-${LLVM_VER}/bin to the PATH environment variable
ENV PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}" ENV PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"

View file

@ -1,4 +1,3 @@
#include <spdlog/common.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <boost/asio/co_spawn.hpp> #include <boost/asio/co_spawn.hpp>
@ -8,8 +7,6 @@
#include <larra/printer_stream.hpp> #include <larra/printer_stream.hpp>
#include <print> #include <print>
namespace iq = larra::xmpp::iq;
auto Coroutine() -> boost::asio::awaitable<void> { auto Coroutine() -> boost::asio::awaitable<void> {
SPDLOG_INFO("Connecting client..."); SPDLOG_INFO("Connecting client...");
@ -17,28 +14,11 @@ auto Coroutine() -> boost::asio::awaitable<void> {
auto client = co_await larra::xmpp::client::CreateClient<larra::xmpp::PrintStream<boost::asio::ip::tcp::socket>>( auto client = co_await larra::xmpp::client::CreateClient<larra::xmpp::PrintStream<boost::asio::ip::tcp::socket>>(
larra::xmpp::PlainUserAccount{.jid = {.username = "test1", .server = "localhost"}, .password = "test1"}, larra::xmpp::PlainUserAccount{.jid = {.username = "test1", .server = "localhost"}, .password = "test1"},
{.useTls = larra::xmpp::client::Options::kNever}); {.useTls = larra::xmpp::client::Options::kNever});
// TODO(unknown):
// rfc6120 7.1
// After a client authenticates with a server,
// it MUST bind a specific resource to the stream so that the server can properly address the client.
co_await std::visit( co_await std::visit(
[](auto& client) -> boost::asio::awaitable<void> { [](auto& client) -> boost::asio::awaitable<void> {
co_await client.UpdateListOfContacts();
},
client);
// rfc6120 2.2
// Upon authenticating with a server and binding a resource (thus becoming a connected resource as defined in [XMPPCORE]),
// a client SHOULD request the roster before sending initial presence
co_await std::visit(
[](auto& client) -> boost::asio::awaitable<void> {
SPDLOG_INFO("Send presence: Available");
co_await client.Send(larra::xmpp::presence::c2s::Available{}); co_await client.Send(larra::xmpp::presence::c2s::Available{});
}, },
client); client);
} catch(const std::exception& err) { } catch(const std::exception& err) {
SPDLOG_ERROR("{}", err.what()); SPDLOG_ERROR("{}", err.what());
co_return; co_return;
@ -47,7 +27,7 @@ auto Coroutine() -> boost::asio::awaitable<void> {
} }
auto main() -> int { auto main() -> int {
spdlog::set_level(spdlog::level::debug); spdlog::set_level(spdlog::level::trace);
boost::asio::io_context io_context; boost::asio::io_context io_context;
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached); boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
io_context.run(); io_context.run();

View file

@ -21,14 +21,6 @@
#include <larra/user_account.hpp> #include <larra/user_account.hpp>
#include <larra/xml_stream.hpp> #include <larra/xml_stream.hpp>
#include <ranges> #include <ranges>
#include <utility>
#include "larra/iq.hpp"
#include "larra/roster.hpp"
namespace rng = std::ranges;
namespace views = std::views;
namespace iq = larra::xmpp::iq;
namespace larra::xmpp { namespace larra::xmpp {
constexpr auto kDefaultXmppPort = 5222; constexpr auto kDefaultXmppPort = 5222;
@ -37,6 +29,9 @@ constexpr auto kDefaultXmppPort = 5222;
namespace larra::xmpp::client { namespace larra::xmpp::client {
namespace rng = std::ranges;
namespace views = std::views;
template <typename Connection> template <typename Connection>
struct Client { struct Client {
constexpr Client(BareJid jid, XmlStream<Connection> connection) : jid(std::move(jid)), connection(std::move(connection)) {}; constexpr Client(BareJid jid, XmlStream<Connection> connection) : jid(std::move(jid)), connection(std::move(connection)) {};
@ -76,24 +71,6 @@ struct Client {
[[nodiscard]] constexpr auto Jid() const -> const BareJid& { [[nodiscard]] constexpr auto Jid() const -> const BareJid& {
return this->jid; return this->jid;
} }
auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
SPDLOG_INFO("Send IQ: Get::Roster");
co_await std::visit(
[&](auto&& query) -> boost::asio::awaitable<void> {
co_await this->Send(query);
}, ::iq::MakeGetRoster(jid));
//IqRoster roster = co_await connection.template Read<IqRoster>();
//const auto& roster_result = std::get<::iq::ResultRoster>(roster);
::iq::ResultRoster roster_result = co_await connection.template Read<::iq::ResultRoster>();
for (const auto& jid : roster_result.payload.items) {
SPDLOG_INFO("\t'{}'", ToString(jid));
}
co_return;
}
private: private:
bool active = true; bool active = true;

View file

@ -2,7 +2,6 @@
#include <larra/serialization.hpp> #include <larra/serialization.hpp>
#include <larra/stream_error.hpp> #include <larra/stream_error.hpp>
#include <larra/utils.hpp> #include <larra/utils.hpp>
#include <optional>
#include <string> #include <string>
namespace larra::xmpp { namespace larra::xmpp {
@ -12,8 +11,6 @@ namespace iq {
template <auto& Name, typename PayloadType> template <auto& Name, typename PayloadType>
struct BaseImplWithPayload { struct BaseImplWithPayload {
std::string id; std::string id;
std::optional<std::string> from{};
std::optional<std::string> to{};
PayloadType payload; PayloadType payload;
static const inline std::string kName = Name; static const inline std::string kName = Name;
static constexpr auto kDefaultName = "iq"; static constexpr auto kDefaultName = "iq";
@ -22,32 +19,16 @@ struct BaseImplWithPayload {
[[nodiscard]] constexpr auto Id(this Self&& self, std::string id) -> std::decay_t<Self> { [[nodiscard]] constexpr auto Id(this Self&& self, std::string id) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"id", BaseImplWithPayload>(std::forward<Self>(self), std::move(id)); return utils::FieldSetHelper::With<"id", BaseImplWithPayload>(std::forward<Self>(self), std::move(id));
} }
template <typename Self>
[[nodiscard]] constexpr auto To(this Self&& self, std::string to) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"to", BaseImplWithPayload>(std::forward<Self>(self), std::move(to));
}
template <typename Self>
[[nodiscard]] constexpr auto From(this Self&& self, std::string from) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"from", BaseImplWithPayload>(std::forward<Self>(self), std::move(from));
}
template <typename NewPayloadType, typename Self> template <typename NewPayloadType, typename Self>
[[nodiscard]] constexpr auto Payload(this Self&& self, NewPayloadType value) { [[nodiscard]] constexpr auto Payload(this Self&& self, NewPayloadType value) {
return utils::FieldSetHelper::With<"payload", BaseImplWithPayload, false>(std::forward<Self>(self), std::move(value)); return utils::FieldSetHelper::With<"payload", BaseImplWithPayload, false>(std::forward<Self>(self), std::move(value));
} }
friend constexpr auto operator<<(xmlpp::Element* element, const BaseImplWithPayload& self) { friend constexpr auto operator<<(xmlpp::Element* element, const BaseImplWithPayload& self) {
element->set_attribute("id", self.id); element->set_attribute("id", self.id);
if (self.to) {
element->set_attribute("to", *self.to);
}
if (self.from) {
element->set_attribute("from", *self.from);
}
element->set_attribute("type", kName); element->set_attribute("type", kName);
using S = Serialization<PayloadType>; using S = Serialization<PayloadType>;
S::Serialize(element->add_child_element(S::kDefaultName, S::kPrefix), self.payload); S::Serialize(element->add_child_element(S::kDefaultName, S::kPrefix), self.payload);
} }
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> BaseImplWithPayload { [[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> BaseImplWithPayload {
auto node = element->get_attribute("type"); auto node = element->get_attribute("type");
if(!node) { if(!node) {
@ -60,9 +41,6 @@ struct BaseImplWithPayload {
if(!idNode) { if(!idNode) {
throw std::runtime_error("Not found attribute id for parse Iq"); throw std::runtime_error("Not found attribute id for parse Iq");
} }
auto from = element->get_attribute("from");
auto to = element->get_attribute("to");
using S = Serialization<PayloadType>; using S = Serialization<PayloadType>;
auto payload = element->get_first_child(S::kDefaultName); auto payload = element->get_first_child(S::kDefaultName);
@ -73,11 +51,7 @@ struct BaseImplWithPayload {
if(!payload2) { if(!payload2) {
throw std::runtime_error("Invalid payload for parse Iq"); throw std::runtime_error("Invalid payload for parse Iq");
} }
return { return {.id = idNode->get_value(), .payload = S::Parse(payload2)};
.id = idNode->get_value(),
.from = (from ? std::optional{from->get_value()} : std::nullopt),
.to = (to ? std::optional{to->get_value()} : std::nullopt),
.payload = S::Parse(payload2)};
} }
}; };
static constexpr auto kGetName = "get"; static constexpr auto kGetName = "get";

View file

@ -1,56 +0,0 @@
#pragma once
#include <libxml++/libxml++.h>
#include <spdlog/spdlog.h>
#include <larra/jid.hpp>
#include <ranges>
#include <vector>
#include <larra/iq.hpp>
namespace larra::xmpp::iq {
struct Roster {
static constexpr auto kDefaultName = "query";
static constexpr auto kDefaultNamespace = "jabber:iq:roster";
std::vector<BareJid> items;
friend constexpr auto operator<<(xmlpp::Element* element, const Roster& roster) {
element->set_attribute("xmlns", "jabber:iq:roster");
}
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Roster {
const auto& item_nodes = element->get_children("item");
if(item_nodes.empty()) {
SPDLOG_DEBUG("No items at Iq::Roster");
}
return {
.items = item_nodes
| std::views::transform([](const xmlpp::Node* node) {
auto item_element = dynamic_cast<const xmlpp::Element*>(node);
if (!item_element) {
throw std::runtime_error("Can't convert xmlpp::Node to xmlpp::Element");
}
auto jid_ptr = item_element->get_attribute("jid");
if (!jid_ptr) {
throw std::runtime_error("Not found attribute 'jid' for parse Roster item");
}
return BareJid::Parse(jid_ptr->get_value());
})
| std::ranges::to<std::vector<BareJid>>()};
}
};
using GetRoster = Get<Roster>;
using ResultRoster = Result<Roster>;
using IqRoster = Iq<Roster>;
auto MakeGetRoster(const BareJid& jid) {
IqRoster iq_roster{std::in_place_type<GetRoster>, GetRoster{.id="1", .from=ToString(jid), .payload=Roster{}}};
return iq_roster;
}
} // namespace larra::xmpp::iq

View file

@ -87,10 +87,6 @@ struct SerializationBase {
}) { }) {
return T::StartCheck(element); return T::StartCheck(element);
} else { } else {
if (element)
{
SPDLOG_DEBUG("kDefaultName: {}, get_name: {}", kDefaultName, element->get_name());
}
return element && element->get_name() == kDefaultName; return element && element->get_name() == kDefaultName;
} }
}; };

View file