c++23 p0798, drop tl code

master
bqv 2 years ago
parent 6028a22ce2
commit d5d756ff03
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

1177
.depend

File diff suppressed because it is too large Load Diff

@ -209,7 +209,7 @@ xmpp_stanza_t *weechat::account::get_devicelist()
} }
void weechat::account::add_mam_query(const std::string id, const std::string with, void weechat::account::add_mam_query(const std::string id, const std::string with,
tl::optional<time_t> start, tl::optional<time_t> end) std::optional<time_t> start, std::optional<time_t> end)
{ {
if (!mam_queries.contains(id)) if (!mam_queries.contains(id))
{ {

@ -10,7 +10,7 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <unordered_map> #include <unordered_map>
#include <tl/optional.hpp> #include <optional>
#include "fmt/core.h" #include "fmt/core.h"
#include "strophe.h" #include "strophe.h"
@ -43,8 +43,8 @@ namespace weechat
{ {
std::string id; std::string id;
std::string with; std::string with;
tl::optional<time_t> start; std::optional<time_t> start;
tl::optional<time_t> end; std::optional<time_t> end;
}; };
public: public:
@ -99,7 +99,7 @@ namespace weechat
xmpp_stanza_t *get_devicelist(); xmpp_stanza_t *get_devicelist();
void add_mam_query(const std::string id, const std::string with, void add_mam_query(const std::string id, const std::string with,
tl::optional<time_t> start, tl::optional<time_t> end); std::optional<time_t> start, std::optional<time_t> end);
bool mam_query_search(mam_query* out, const std::string id); bool mam_query_search(mam_query* out, const std::string id);
void mam_query_remove(const std::string id); void mam_query_remove(const std::string id);
void mam_query_free_all(); void mam_query_free_all();

@ -9,7 +9,7 @@
#include <time.h> #include <time.h>
#include <regex> #include <regex>
#include <fmt/core.h> #include <fmt/core.h>
#include <tl/optional.hpp> #include <optional>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
@ -641,7 +641,7 @@ weechat::channel::member *weechat::channel::remove_member(const char *id, const
} }
int weechat::channel::send_message(std::string to, std::string body, int weechat::channel::send_message(std::string to, std::string body,
tl::optional<std::string> oob) std::optional<std::string> oob)
{ {
xmpp_stanza_t *message = xmpp_message_new(account.context, xmpp_stanza_t *message = xmpp_message_new(account.context,
type == weechat::channel::chat_type::MUC type == weechat::channel::chat_type::MUC

@ -9,7 +9,7 @@
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <tl/optional.hpp> #include <optional>
#define CHANNEL_MEMBERS_SPEAKING_LIMIT 128 #define CHANNEL_MEMBERS_SPEAKING_LIMIT 128
@ -155,7 +155,7 @@ namespace weechat
member *remove_member(const char *id, const char *reason); member *remove_member(const char *id, const char *reason);
int send_message(std::string to, std::string body, int send_message(std::string to, std::string body,
tl::optional<std::string> oob = {}); std::optional<std::string> oob = {});
int send_message(const char *to, const char *body); int send_message(const char *to, const char *body);
void send_reads(); void send_reads();

@ -154,7 +154,7 @@ weechat::config::config()
weechat::config::~config() {} weechat::config::~config() {}
tl::optional<weechat::config> weechat::config::instance; std::optional<weechat::config> weechat::config::instance;
bool weechat::config::init() { instance.emplace(); return true; } bool weechat::config::init() { instance.emplace(); return true; }
bool weechat::config::read() { return instance->file.read(); } bool weechat::config::read() { return instance->file.read(); }

@ -9,7 +9,7 @@
#include <string> #include <string>
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include <tl/optional.hpp> #include <optional>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "fmt/core.h" #include "fmt/core.h"
#include "plugin.hh" #include "plugin.hh"
@ -32,13 +32,13 @@ namespace weechat
struct config_breadcrumb { struct config_breadcrumb {
config_breadcrumb(std::string name) config_breadcrumb(std::string name)
: name(name), parent(tl::nullopt) {} : name(name), parent(std::nullopt) {}
config_breadcrumb(std::string name, config_breadcrumb& parent) config_breadcrumb(std::string name, config_breadcrumb& parent)
: name(name), parent(parent) {} : name(name), parent(parent) {}
std::string name; std::string name;
tl::optional<config_breadcrumb&> parent; std::optional<std::reference_wrapper<config_breadcrumb>> parent;
}; };
struct config_free { void operator() (struct t_config_file *ptr) { weechat_config_free(ptr); } }; struct config_free { void operator() (struct t_config_file *ptr) { weechat_config_free(ptr); } };
@ -381,7 +381,7 @@ namespace weechat
config(); config();
~config(); ~config();
static tl::optional<config> instance; static std::optional<config> instance;
public: public:
static bool init(); static bool init();

@ -3,6 +3,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <stdexcept> #include <stdexcept>
#include <optional>
#include <strophe.h> #include <strophe.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,6 +27,7 @@
#include "omemo.hh" #include "omemo.hh"
#include "pgp.hh" #include "pgp.hh"
#include "util.hh" #include "util.hh"
extern "C" { extern "C" {
#include "diff/diff.h" #include "diff/diff.h"
} }
@ -844,7 +846,7 @@ xmpp_stanza_t *weechat::connection::get_caps(xmpp_stanza_t *reply, char **hash)
} }
xmpp_stanza_t *field, *value, *text; xmpp_stanza_t *field, *value, *text;
// This->is utter bullshit, TODO: anything but this-> // This is utter bullshit, TODO: anything but this
#define FEATURE1(VAR, TYPE, VALUE) \ #define FEATURE1(VAR, TYPE, VALUE) \
field = xmpp_stanza_new(account.context); \ field = xmpp_stanza_new(account.context); \
xmpp_stanza_set_name(field, "field"); \ xmpp_stanza_set_name(field, "field"); \
@ -1199,8 +1201,8 @@ bool weechat::connection::iq_handler(xmpp_stanza_t *stanza)
if (channel != account.channels.end() && set__last__text) if (channel != account.channels.end() && set__last__text)
{ {
channel->second.fetch_mam(id, channel->second.fetch_mam(id,
*mam_query.start.map([](time_t& t){ return &t; }).disjunction(nullptr), mam_query.start.transform([](time_t& t) { return &t; }).value_or(nullptr),
*mam_query.end.map([](time_t& t){ return &t; }).disjunction(nullptr), mam_query.end.transform([](time_t& t) { return &t; }).value_or(nullptr),
set__last__text); set__last__text);
} }
else if (!set__last) else if (!set__last)

@ -28,7 +28,7 @@ endif
CPPFLAGS+=$(DBGCFLAGS) -O0 \ CPPFLAGS+=$(DBGCFLAGS) -O0 \
-fno-omit-frame-pointer -fPIC \ -fno-omit-frame-pointer -fPIC \
-fvisibility=hidden -fvisibility-inlines-hidden \ -fvisibility=hidden -fvisibility-inlines-hidden \
-std=c++20 -gdwarf-4 \ -std=c++23 -gdwarf-4 \
-Wall -Wextra -pedantic \ -Wall -Wextra -pedantic \
-Wno-missing-field-initializers \ -Wno-missing-field-initializers \
$(INCLUDES) $(INCLUDES)
@ -177,7 +177,7 @@ debug: xmpp.so
weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so' weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so'
.PHONY: depend .PHONY: depend
depend: $(SRCS) $(HDRS) depend: $(DEPS) $(SRCS) $(HDRS)
$(RM) -f ./.depend $(RM) -f ./.depend
echo > ./.depend echo > ./.depend
for src in $(SRCS) ; do \ for src in $(SRCS) ; do \

@ -14,7 +14,7 @@
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <limits.h> #include <limits.h>
#include <tl/optional.hpp> #include <optional>
#include <range/v3/all.hpp> #include <range/v3/all.hpp>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
@ -1691,7 +1691,7 @@ int bks_store_bundle(struct signal_protocol_address *address,
return 0; return 0;
} }
tl::optional<libsignal::pre_key_bundle> bks_load_bundle(struct signal_protocol_address *address, t_omemo *omemo) std::optional<libsignal::pre_key_bundle> bks_load_bundle(struct signal_protocol_address *address, t_omemo *omemo)
{ {
std::string k_bundle_pk = fmt::format("bundle_pk_{}_{}", address->name, address->device_id); std::string k_bundle_pk = fmt::format("bundle_pk_{}_{}", address->name, address->device_id);
std::string k_bundle_sk = fmt::format("bundle_sk_{}_{}", address->name, address->device_id); std::string k_bundle_sk = fmt::format("bundle_sk_{}_{}", address->name, address->device_id);

@ -7,6 +7,7 @@
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <string_view> #include <string_view>
#include <memory>
#include <numeric> #include <numeric>
#include <fmt/core.h> #include <fmt/core.h>
#include <gpgme.h> #include <gpgme.h>

@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <tl/optional.hpp> #include <optional>
namespace weechat namespace weechat
{ {
@ -21,7 +21,7 @@ namespace weechat
char *avatar_hash = nullptr; char *avatar_hash = nullptr;
char *status_text = nullptr; char *status_text = nullptr;
char *status = nullptr; char *status = nullptr;
tl::optional<std::string> idle; std::optional<std::string> idle;
char *display_name = nullptr; char *display_name = nullptr;
char *email = nullptr; char *email = nullptr;
char *role = nullptr; char *role = nullptr;

@ -26,7 +26,7 @@ std::string get_name(xmpp_stanza_t *stanza) {
return {}; return {};
} }
tl::optional<std::string> get_attribute(xmpp_stanza_t *stanza, const char *name) { std::optional<std::string> get_attribute(xmpp_stanza_t *stanza, const char *name) {
const char *result = NULL; const char *result = NULL;
result = xmpp_stanza_get_attribute(stanza, name); result = xmpp_stanza_get_attribute(stanza, name);
if (result) if (result)
@ -124,14 +124,14 @@ void xml::message::bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) {
node::bind(context, stanza); node::bind(context, stanza);
} }
tl::optional<std::string> xml::presence::show() { std::optional<std::string> xml::presence::show() {
auto child = get_children("show"); auto child = get_children("show");
if (child.size() > 0) if (child.size() > 0)
return child.front().get().text; return child.front().get().text;
return {}; return {};
} }
tl::optional<std::string> xml::presence::status() { std::optional<std::string> xml::presence::status() {
auto child = get_children("status"); auto child = get_children("status");
if (child.size() > 0) if (child.size() > 0)
return child.front().get().text; return child.front().get().text;

@ -15,12 +15,12 @@
#include <chrono> #include <chrono>
#include <variant> #include <variant>
#include <fmt/core.h> #include <fmt/core.h>
#include <tl/optional.hpp> #include <optional>
#include <strophe.h> #include <strophe.h>
std::string get_name(xmpp_stanza_t *stanza); std::string get_name(xmpp_stanza_t *stanza);
tl::optional<std::string> get_attribute(xmpp_stanza_t *stanza, const char *name); std::optional<std::string> get_attribute(xmpp_stanza_t *stanza, const char *name);
std::string get_text(xmpp_stanza_t *stanza); std::string get_text(xmpp_stanza_t *stanza);
@ -60,10 +60,10 @@ namespace xml {
xmpp_ctx_t *context; xmpp_ctx_t *context;
tl::optional<std::string> name; std::optional<std::string> name;
tl::optional<std::string> id; std::optional<std::string> id;
tl::optional<std::string> ns; std::optional<std::string> ns;
std::map<std::string, std::string> attributes; std::map<std::string, std::string> attributes;
std::vector<node> children; std::vector<node> children;
@ -72,7 +72,7 @@ namespace xml {
virtual void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza); virtual void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza);
inline tl::optional<std::string> inline std::optional<std::string>
get_attr(const std::string& name) { get_attr(const std::string& name) {
auto attribute = attributes.find(name); auto attribute = attributes.find(name);
if (attribute != attributes.end()) if (attribute != attributes.end())
@ -233,10 +233,10 @@ namespace xml {
bind(context, stanza); bind(context, stanza);
} }
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
tl::optional<std::string> type; std::optional<std::string> type;
void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override; void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override;
}; };
@ -248,13 +248,13 @@ namespace xml {
bind(context, stanza); bind(context, stanza);
} }
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
tl::optional<std::string> type; std::optional<std::string> type;
tl::optional<std::string> show(); std::optional<std::string> show();
tl::optional<std::string> status(); std::optional<std::string> status();
void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override; void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override;
}; };
@ -265,10 +265,10 @@ namespace xml {
bind(context, stanza); bind(context, stanza);
} }
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
tl::optional<std::string> type; std::optional<std::string> type;
void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override; void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override;
}; };
@ -279,8 +279,8 @@ namespace xml {
bind(context, stanza); bind(context, stanza);
} }
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override; void bind(xmpp_ctx_t *context, xmpp_stanza_t *stanza) override;
}; };

@ -17,29 +17,29 @@ namespace xml {
/* Current Jabber OpenPGP Usage */ /* Current Jabber OpenPGP Usage */
class xep0027 : virtual public node { class xep0027 : virtual public node {
private: private:
tl::optional<tl::optional<std::string>> _signature; std::optional<std::optional<std::string>> _signature;
tl::optional<tl::optional<std::string>> _encrypted; std::optional<std::optional<std::string>> _encrypted;
public: public:
tl::optional<std::string>& signature() { std::optional<std::string>& signature() {
if (!_signature) if (!_signature)
{ {
auto child = get_children<jabber::x::signed_>("x"); auto child = get_children<jabber::x::signed_>("x");
if (child.size() > 0) if (child.size() > 0)
_signature = child.front().get().text; _signature = child.front().get().text;
else else
_signature.emplace(tl::nullopt); _signature.emplace(std::nullopt);
} }
return *_signature; return *_signature;
} }
tl::optional<std::string>& encrypted() { std::optional<std::string>& encrypted() {
if (!_encrypted) if (!_encrypted)
{ {
auto child = get_children<jabber::x::encrypted>("x"); auto child = get_children<jabber::x::encrypted>("x");
if (child.size() > 0) if (child.size() > 0)
_encrypted = child.front().get().text; _encrypted = child.front().get().text;
else else
_encrypted.emplace(tl::nullopt); _encrypted.emplace(std::nullopt);
} }
return *_encrypted; return *_encrypted;
} }

@ -108,8 +108,8 @@ namespace xml {
}; };
std::string reason; std::string reason;
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
}; };
struct destroy { struct destroy {
@ -121,7 +121,7 @@ namespace xml {
}; };
std::string reason; std::string reason;
tl::optional<jid> target; std::optional<jid> target;
}; };
struct invite { struct invite {
@ -135,8 +135,8 @@ namespace xml {
}; };
std::string reason; std::string reason;
tl::optional<jid> from; std::optional<jid> from;
tl::optional<jid> to; std::optional<jid> to;
}; };
class item { class item {
@ -152,7 +152,7 @@ namespace xml {
} }
std::string reason; std::string reason;
tl::optional<jid> target; std::optional<jid> target;
std::string nick; std::string nick;
}; };
@ -186,10 +186,10 @@ namespace xml {
std::vector<actor> actors; std::vector<actor> actors;
std::vector<continue_> continues; std::vector<continue_> continues;
std::string reason; std::string reason;
tl::optional<enum affiliation> affiliation; std::optional<enum affiliation> affiliation;
tl::optional<jid> target; std::optional<jid> target;
tl::optional<std::string> nick; std::optional<std::string> nick;
tl::optional<enum role> role; std::optional<enum role> role;
}; };
public: public:
@ -300,10 +300,10 @@ namespace xml {
description = child.get().text; description = child.get().text;
} }
tl::optional<jid> by; std::optional<jid> by;
tl::optional<enum action> type; std::optional<enum action> type;
tl::optional<enum condition> condition; std::optional<enum condition> condition;
tl::optional<std::string> description; std::optional<std::string> description;
const char* reason() { const char* reason() {
if (condition) if (condition)
@ -331,9 +331,9 @@ namespace xml {
}; };
private: private:
tl::optional<bool> _muc; std::optional<bool> _muc;
tl::optional<tl::optional<x>> _muc_user; std::optional<std::optional<x>> _muc_user;
tl::optional<tl::optional<error>> _error; std::optional<std::optional<error>> _error;
public: public:
bool muc() { bool muc() {
if (!_muc) if (!_muc)
@ -344,26 +344,26 @@ namespace xml {
return *_muc; return *_muc;
} }
tl::optional<x>& muc_user() { std::optional<x>& muc_user() {
if (!_muc_user) if (!_muc_user)
{ {
auto child = get_children<jabber_org::protocol::muc::user>("x"); auto child = get_children<jabber_org::protocol::muc::user>("x");
if (child.size() > 0) if (child.size() > 0)
_muc_user = child.front().get(); _muc_user = child.front().get();
else else
_muc_user.emplace(tl::nullopt); _muc_user.emplace(std::nullopt);
} }
return *_muc_user; return *_muc_user;
} }
tl::optional<error>& error() { std::optional<error>& error() {
if (!_error) if (!_error)
{ {
auto child = get_children("error"); auto child = get_children("error");
if (child.size() > 0) if (child.size() > 0)
_error = child.front().get(); _error = child.front().get();
else else
_error.emplace(tl::nullopt); _error.emplace(std::nullopt);
} }
return *_error; return *_error;
} }

@ -29,23 +29,23 @@ namespace xml{
verification = *attr; verification = *attr;
}; };
tl::optional<std::string> ext; std::optional<std::string> ext;
std::string hashalgo; std::string hashalgo;
std::string node; std::string node;
std::string verification; std::string verification;
}; };
private: private:
tl::optional<tl::optional<caps>> _capabilities; std::optional<std::optional<caps>> _capabilities;
public: public:
tl::optional<caps> capabilities() { std::optional<caps> capabilities() {
if (!_capabilities) if (!_capabilities)
{ {
auto child = get_children<jabber_org::protocol::caps>("c"); auto child = get_children<jabber_org::protocol::caps>("c");
if (child.size() > 0) if (child.size() > 0)
_capabilities = caps(child.front().get()); _capabilities = caps(child.front().get());
else else
_capabilities.emplace(tl::nullopt); _capabilities.emplace(std::nullopt);
} }
return *_capabilities; return *_capabilities;
} }

@ -19,24 +19,24 @@ namespace xml {
/* Last User Interaction in Presence */ /* Last User Interaction in Presence */
class xep0319 : virtual public node { class xep0319 : virtual public node {
private: private:
tl::optional<tl::optional<std::chrono::system_clock::time_point>> _idle_since; std::optional<std::optional<std::chrono::system_clock::time_point>> _idle_since;
public: public:
tl::optional<std::chrono::system_clock::time_point> idle_since() { std::optional<std::chrono::system_clock::time_point> idle_since() {
if (!_idle_since) if (!_idle_since)
{ {
auto children = get_children<urn::xmpp::idle::_1>("idle"); auto children = get_children<urn::xmpp::idle::_1>("idle");
if (children.size() <= 0) if (children.size() <= 0)
_idle_since.emplace(tl::nullopt); _idle_since.emplace(std::nullopt);
else { else {
auto since = children.front().get().get_attr("since"); auto since = children.front().get().get_attr("since");
if (!since) if (!since)
_idle_since.emplace(tl::nullopt); _idle_since.emplace(std::nullopt);
else { else {
try { try {
_idle_since = get_time(*since); _idle_since = get_time(*since);
} }
catch (const std::invalid_argument& ex) { catch (const std::invalid_argument& ex) {
_idle_since.emplace(tl::nullopt); _idle_since.emplace(std::nullopt);
} }
} }
} }

Loading…
Cancel
Save