Compare commits

..

3 commits

Author SHA1 Message Date
5c250ac434 tmp3
Some checks failed
PR Check / on-push-commit-check (push) Failing after 3m35s
2024-11-09 12:22:42 +00:00
7078c25c2a tmp2 2024-11-08 14:20:08 +00:00
c77614992d temp1 2024-11-07 15:49:55 +01:00
7 changed files with 154 additions and 23 deletions

View file

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

View file

@ -1,3 +1,4 @@
#include <spdlog/common.h>
#include <spdlog/spdlog.h>
#include <boost/asio/co_spawn.hpp>
@ -7,6 +8,8 @@
#include <larra/printer_stream.hpp>
#include <print>
namespace iq = larra::xmpp::iq;
auto Coroutine() -> boost::asio::awaitable<void> {
SPDLOG_INFO("Connecting client...");
@ -14,11 +17,28 @@ auto Coroutine() -> boost::asio::awaitable<void> {
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"},
{.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(
[](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{});
},
client);
} catch(const std::exception& err) {
SPDLOG_ERROR("{}", err.what());
co_return;
@ -27,7 +47,7 @@ auto Coroutine() -> boost::asio::awaitable<void> {
}
auto main() -> int {
spdlog::set_level(spdlog::level::trace);
spdlog::set_level(spdlog::level::debug);
boost::asio::io_context io_context;
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
io_context.run();

View file

@ -21,6 +21,14 @@
#include <larra/user_account.hpp>
#include <larra/xml_stream.hpp>
#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 {
constexpr auto kDefaultXmppPort = 5222;
@ -29,9 +37,6 @@ constexpr auto kDefaultXmppPort = 5222;
namespace larra::xmpp::client {
namespace rng = std::ranges;
namespace views = std::views;
template <typename Connection>
struct Client {
constexpr Client(BareJid jid, XmlStream<Connection> connection) : jid(std::move(jid)), connection(std::move(connection)) {};
@ -71,6 +76,24 @@ struct Client {
[[nodiscard]] constexpr auto Jid() const -> const BareJid& {
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:
bool active = true;

View file

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

View file

@ -0,0 +1,56 @@
#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,6 +87,10 @@ struct SerializationBase {
}) {
return T::StartCheck(element);
} else {
if (element)
{
SPDLOG_DEBUG("kDefaultName: {}, get_name: {}", kDefaultName, element->get_name());
}
return element && element->get_name() == kDefaultName;
}
};

0
library/query.hpp Normal file
View file