From 35a2b37cdb52ee7ecaf1da412fd0242569159d24 Mon Sep 17 00:00:00 2001
From: Tony Olagbaiye <me@fron.io>
Date: Tue, 11 Jan 2022 15:11:11 +0000
Subject: [PATCH] wip

---
 account.cpp | 12 ++++++++
 plugin.hh   | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 strophe.ipp |  8 +++++
 weechat.cpp | 32 ++++++++++++++++++++
 4 files changed, 137 insertions(+)

diff --git a/account.cpp b/account.cpp
index 553a29e..83f64f5 100644
--- a/account.cpp
+++ b/account.cpp
@@ -144,6 +144,10 @@ weechat::xmpp::account::account(std::string name)
             + " << xmpp.account_default." + it->first;
 
         auto [option, success] = this->m_options.try_emplace(it->first,
+<<<<<<< Updated upstream
+=======
+          weechat::config_option(
+>>>>>>> Stashed changes
             weechat::globals::plugin.config().file(),
             weechat::globals::plugin.config().section_account(),
             option_name, it->second.type,
@@ -151,7 +155,11 @@ weechat::xmpp::account::account(std::string name)
             it->second.range, 0, 0, it->second.value, it->second.value, false,
             std::function([this](weechat::config_option&, std::string){ return true; }),
             std::function([this](weechat::config_option&){ }),
+<<<<<<< Updated upstream
             std::function([this](weechat::config_option&){ }));
+=======
+            std::function([this](weechat::config_option&){ })));
+>>>>>>> Stashed changes
         if (!success)
             throw weechat::error("duplicate option key");
         //option.change_cb(it->first, nullptr, this->m_options[it->first]);
@@ -314,6 +322,10 @@ void weechat::xmpp::account::disconnect_all()
 std::pair<std::map<std::string, weechat::xmpp::account>::iterator, bool>
 weechat::xmpp::account::create(std::string name)
 {
+<<<<<<< Updated upstream
+=======
+    weechat::xmpp::account v(name);
+>>>>>>> Stashed changes
     return weechat::xmpp::globals::accounts.try_emplace(name, name);
 }
 
diff --git a/plugin.hh b/plugin.hh
index 2c3f968..47469f0 100644
--- a/plugin.hh
+++ b/plugin.hh
@@ -531,7 +531,11 @@ namespace weechat {
         return globals::plugin->config_new(
             globals::plugin, name,
             [] (const void *pointer, void *, struct t_config_file *file) {
+<<<<<<< Updated upstream
                 auto func = *reinterpret_cast<const config_file::reload_callback*>(pointer);
+=======
+                auto& func = *reinterpret_cast<const config_file::reload_callback*>(pointer);
+>>>>>>> Stashed changes
                 config_file file_(file);
                 return func(file_);
             }, &reload_cb, nullptr);
@@ -540,6 +544,7 @@ namespace weechat {
                                                        const char *name,
                                                        bool user_can_add_options,
                                                        bool user_can_delete_options,
+<<<<<<< Updated upstream
                                                        config_section::read_callback& read_cb,
                                                        config_section::write_callback& write_cb,
                                                        config_section::write_default_callback& write_default_cb,
@@ -574,11 +579,51 @@ namespace weechat {
             [] (const void *pointer, void *, struct t_config_file *file,
                 struct t_config_section *section, struct t_config_option *option) {
                 auto func = *reinterpret_cast<const config_section::delete_option_callback*>(pointer);
+=======
+                                                       config_section::read_callback *read_cb,
+                                                       config_section::write_callback *write_cb,
+                                                       config_section::write_default_callback *write_default_cb,
+                                                       config_section::create_option_callback *create_cb,
+                                                       config_section::delete_option_callback *delete_cb) {
+        return globals::plugin->config_new_section(
+            file, name, user_can_add_options, user_can_delete_options,
+            read_cb ? static_cast<config_section::read_fn>([] (const void *pointer, void *, struct t_config_file *file,
+                struct t_config_section *section, const char *key, const char *value) {
+                auto& func = *reinterpret_cast<const config_section::read_callback*>(pointer);
+                config_file file_(file);
+                config_section section_(section);
+                return func(file_, section_, key, value);
+            }) : nullptr, read_cb, nullptr,
+            write_cb ? static_cast<config_section::write_fn>([] (const void *pointer, void *, struct t_config_file *file, const char *name) {
+                auto& func = *reinterpret_cast<const config_section::write_callback*>(pointer);
+                config_file file_(file);
+                return func(file_, name);
+            }) : nullptr, write_cb, nullptr,
+            write_default_cb ? static_cast<config_section::write_default_fn>([] (const void *pointer, void *, struct t_config_file *file, const char *name) {
+                auto& func = *reinterpret_cast<const config_section::write_default_callback*>(pointer);
+                config_file file_(file);
+                return func(file_, name);
+            }) : nullptr, write_default_cb, nullptr,
+            create_cb ? static_cast<config_section::create_option_fn>([] (const void *pointer, void *, struct t_config_file *file,
+                struct t_config_section *section, const char *key, const char *value) {
+                auto& func = *reinterpret_cast<const config_section::create_option_callback*>(pointer);
+                config_file file_(file);
+                config_section section_(section);
+                return func(file_, section_, key, value);
+            }) : nullptr, create_cb, nullptr,
+            delete_cb ? static_cast<config_section::delete_option_fn>([] (const void *pointer, void *, struct t_config_file *file,
+                struct t_config_section *section, struct t_config_option *option) {
+                auto& func = *reinterpret_cast<const config_section::delete_option_callback*>(pointer);
+>>>>>>> Stashed changes
                 config_file file_(file);
                 config_section section_(section);
                 config_option option_(option);
                 return func(file_, section_, option_);
+<<<<<<< Updated upstream
             }, &delete_cb, nullptr);
+=======
+            }) : nullptr, delete_cb, nullptr);
+>>>>>>> Stashed changes
     }
     inline struct t_config_section *config_search_section(struct t_config_file *config_file,
                                                           const char *section_name) {
@@ -593,13 +638,20 @@ namespace weechat {
                                                      const char *default_value,
                                                      const char *value,
                                                      bool null_value_allowed,
+<<<<<<< Updated upstream
                                                      config_option::check_callback& check_value_cb,
                                                      config_option::change_callback& change_cb,
                                                      config_option::delete_callback& delete_cb) {
+=======
+                                                     config_option::check_callback *check_value_cb,
+                                                     config_option::change_callback *change_cb,
+                                                     config_option::delete_callback *delete_cb) {
+>>>>>>> Stashed changes
         return globals::plugin->config_new_option(
             config_file, section,
             name, type, description, string_values,
             min, max, default_value, value, null_value_allowed,
+<<<<<<< Updated upstream
             [] (const void *pointer, void *, struct t_config_option *option, const char *value) {
                 auto func = *reinterpret_cast<const config_option::check_callback*>(pointer);
                 config_option option_(option);
@@ -615,6 +667,23 @@ namespace weechat {
                 config_option option_(option);
                 return func(option_);
             }, &delete_cb, nullptr);
+=======
+            check_value_cb ? static_cast<config_option::check_fn>([] (const void *pointer, void *, struct t_config_option *option, const char *value) {
+                auto& func = *reinterpret_cast<const config_option::check_callback*>(pointer);
+                config_option option_(option);
+                return static_cast<int>(func(option_, value));
+            }) : nullptr, check_value_cb, nullptr,
+            change_cb ? static_cast<config_option::change_fn>([] (const void *pointer, void *, struct t_config_option *option) {
+                auto& func = *reinterpret_cast<const config_option::change_callback*>(pointer);
+                config_option option_(option);
+                return func(option_);
+            }) : nullptr, change_cb, nullptr,
+            delete_cb ? static_cast<config_option::delete_fn>([] (const void *pointer, void *, struct t_config_option *option) {
+                auto& func = *reinterpret_cast<const config_option::delete_callback*>(pointer);
+                config_option option_(option);
+                return func(option_);
+            }) : nullptr, delete_cb, nullptr);
+>>>>>>> Stashed changes
     }
     inline struct t_config_option *config_search_option(struct t_config_file *config_file,
                                                         struct t_config_section *section,
@@ -813,7 +882,11 @@ namespace weechat {
             globals::plugin,
             interval, align_second, max_calls,
             callback ? static_cast<hook::timer_fn>([] (const void *pointer, void *, int remaining_calls) {
+<<<<<<< Updated upstream
                 auto func = *reinterpret_cast<const hook::timer_callback*>(pointer);
+=======
+                auto& func = *reinterpret_cast<const hook::timer_callback*>(pointer);
+>>>>>>> Stashed changes
                 return static_cast<int>(func(remaining_calls));
             }) : nullptr, callback, nullptr);
     }
@@ -1047,13 +1120,21 @@ namespace weechat {
             [] (const void *pointer, void *,
                 struct t_gui_buffer *buffer,
                 const char *input_data) {
+<<<<<<< Updated upstream
                 auto func = *reinterpret_cast<const gui_buffer::input_callback*>(pointer);
+=======
+                auto& func = *reinterpret_cast<const gui_buffer::input_callback*>(pointer);
+>>>>>>> Stashed changes
                 gui_buffer buffer_(buffer);
                 return static_cast<int>(func(buffer_, input_data));
             }, &input_cb, nullptr,
             [] (const void *pointer, void *,
                 struct t_gui_buffer *buffer) {
+<<<<<<< Updated upstream
                 auto func = *reinterpret_cast<const gui_buffer::close_callback*>(pointer);
+=======
+                auto& func = *reinterpret_cast<const gui_buffer::close_callback*>(pointer);
+>>>>>>> Stashed changes
                 gui_buffer buffer_(buffer);
                 return static_cast<int>(func(buffer_));
             }, &close_cb, nullptr);
@@ -1232,7 +1313,11 @@ namespace weechat {
                       struct t_gui_window *window,
                       struct t_gui_buffer *buffer,
                       struct t_hashtable *extra_args) {
+<<<<<<< Updated upstream
                 auto func = *reinterpret_cast<const gui_bar_item::build_callback*>(pointer);
+=======
+                auto& func = *reinterpret_cast<const gui_bar_item::build_callback*>(pointer);
+>>>>>>> Stashed changes
                 gui_bar_item item_(item);
                 gui_buffer buffer_(buffer);
                 auto res = func(item_, window, buffer_, extra_args);
diff --git a/strophe.ipp b/strophe.ipp
index e467516..fabfc6e 100644
--- a/strophe.ipp
+++ b/strophe.ipp
@@ -10,9 +10,17 @@ namespace xmpp {
     }
 
     template<typename UserData>
+<<<<<<< Updated upstream
     context::context(UserData& data)
         : context(xmpp_ctx_new(nullptr, const_cast<xmpp_log_t*>(static_cast<const xmpp_log_t*>(std::any_cast<logger<UserData>>(&this->m_logger))))) {
         this->m_logger = logger(data);
+=======
+    context::context(UserData& data) {
+        this->m_logger.emplace<logger<UserData>>(data);
+        auto logger_ptr = std::any_cast<logger<UserData>>(&this->m_logger);
+        xmpp_ctx_t *ctx_ptr = xmpp_ctx_new(nullptr, static_cast<xmpp_log_t*>(logger_ptr));
+        xmpp_ctx_ptr::operator=(xmpp_ctx_ptr(ctx_ptr, &xmpp_ctx_free));
+>>>>>>> Stashed changes
     }
 
     template<typename UserData>
diff --git a/weechat.cpp b/weechat.cpp
index b665f06..f63c41c 100644
--- a/weechat.cpp
+++ b/weechat.cpp
@@ -15,9 +15,21 @@ namespace weechat {
         check_callback check_value_cb, change_callback change_cb, delete_callback delete_cb)
         : config_option(weechat::config_new_option(
                             config_file, section, name.data(), type.data(),
+<<<<<<< Updated upstream
                             description.data(), string_values.data(), min, max,
                             default_value.data(), value.data(), null_value_allowed,
                             this->m_check_cb, this->m_change_cb, this->m_delete_cb)) {
+=======
+                            description.data(),
+                            !string_values.empty() ? string_values.data() : nullptr,
+                            min, max,
+                            !default_value.empty() ? default_value.data() : nullptr,
+                            !value.empty() ? value.data() : nullptr,
+                            null_value_allowed,
+                            check_value_cb ? &this->m_check_cb : nullptr,
+                            change_cb ? &this->m_change_cb : nullptr,
+                            delete_cb ? &this->m_delete_cb : nullptr)) {
+>>>>>>> Stashed changes
         this->m_check_cb = check_value_cb;
         this->m_change_cb = change_cb;
         this->m_delete_cb = delete_cb;
@@ -55,10 +67,18 @@ namespace weechat {
                                    delete_option_callback delete_option_cb)
         : config_section(weechat::config_new_section(config_file, name.data(),
                                                      user_can_add_options, user_can_delete_options,
+<<<<<<< Updated upstream
                                                      this->m_read_cb, this->m_write_cb,
                                                      this->m_write_default_cb,
                                                      this->m_create_option_cb,
                                                      this->m_delete_option_cb)) {
+=======
+                                                     read_cb ? &this->m_read_cb : nullptr,
+                                                     write_cb ? &this->m_write_cb : nullptr,
+                                                     write_default_cb ? &this->m_write_default_cb : nullptr,
+                                                     create_option_cb ? &this->m_create_option_cb : nullptr,
+                                                     delete_option_cb ? &this->m_delete_option_cb : nullptr)) {
+>>>>>>> Stashed changes
         this->m_read_cb = read_cb;
         this->m_write_cb = write_cb;
         this->m_write_default_cb = write_default_cb;
@@ -105,7 +125,11 @@ namespace weechat {
     }
 
     gui_buffer::~gui_buffer() {
+<<<<<<< Updated upstream
         weechat::buffer_close(*this);
+=======
+      //weechat::buffer_close(*this);
+>>>>>>> Stashed changes
     }
 
     gui_bar_item::gui_bar_item(struct t_gui_bar_item* item)
@@ -115,7 +139,11 @@ namespace weechat {
     }
 
     gui_bar_item::~gui_bar_item() {
+<<<<<<< Updated upstream
         weechat::bar_item_remove(*this);
+=======
+      //weechat::bar_item_remove(*this);
+>>>>>>> Stashed changes
     }
 
     hook::hook(struct t_hook* hook)
@@ -132,6 +160,10 @@ namespace weechat {
     }
 
     hook::~hook() {
+<<<<<<< Updated upstream
         weechat::unhook(*this);
+=======
+      //weechat::unhook(*this);
+>>>>>>> Stashed changes
     }
 }