diff options
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/bridge/bridge.cpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/utils/timed_events.hpp | 5 | ||||
-rw-r--r-- | src/utils/timed_events_manager.cpp | 14 | ||||
-rw-r--r-- | tests/end_to_end/__main__.py | 25 |
7 files changed, 51 insertions, 5 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 63ee909..586665a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -166,7 +166,7 @@ test:freebsd: .template:codecov_e2e: &codecov_e2e <<: *codecov script: - - bash <(curl -s https://codecov.io/bash) -X gcov -X coveragepy -f ./coverage_e2e.info -F $(echo $CI_JOB_NAME | sed s/:/_/g) + - bash <(curl -s https://codecov.io/bash) -X gcov -X coveragepy -f ./coverage_e2e.info -F $(echo $CI_JOB_NAME | sed s/:/_/g | sed s/codecov_//) codecov:fedora: <<: *codecov_e2e diff --git a/CMakeLists.txt b/CMakeLists.txt index 9458f00..41260aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,6 +194,7 @@ if(LITESQL_FOUND) add_library(database OBJECT src/database/database.cpp ${LITESQL_GENERATED_SOURCES}) + include_directories(database ${LITESQL_INCLUDE_DIRS}) set(USE_DATABASE TRUE) else() add_library(database OBJECT "") diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index f263c3f..69e8c35 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1048,7 +1048,7 @@ void Bridge::send_iq_version_request(const std::string& nick, const std::string& { const auto resources = this->resources_in_server[hostname]; if (resources.begin() != resources.end()) - this->xmpp.send_iq_version_request(utils::tolower(nick) + "%" + utils::empty_if_fixed_server(hostname), + this->xmpp.send_iq_version_request(utils::tolower(nick) + utils::empty_if_fixed_server("%" + hostname), this->user_jid + "/" + *resources.begin()); } @@ -1061,7 +1061,7 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& // Forward to the first resource (arbitrary, based on the “order” of the std::set) only const auto resources = this->resources_in_server[hostname]; if (resources.begin() != resources.end()) - this->xmpp.send_ping_request(utils::tolower(nick) + "%" + utils::empty_if_fixed_server(hostname), + this->xmpp.send_ping_request(utils::tolower(nick) + utils::empty_if_fixed_server("%" + hostname), this->user_jid + "/" + *resources.begin(), utils::revstr(id)); } diff --git a/src/main.cpp b/src/main.cpp index 2db89cc..1a9b065 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,19 +179,20 @@ int main(int ac, char** av) { if (xmpp_component->ever_auth) { + static const std::string reconnect_name{"XMPP reconnection"}; if (xmpp_component->first_connection_try == true) { // immediately re-try to connect xmpp_component->reset(); xmpp_component->start(); } - else + else if (!TimedEventsManager::instance().find_event(reconnect_name)) { // Re-connecting failed, we now try only each few seconds auto reconnect_later = [xmpp_component]() { xmpp_component->reset(); xmpp_component->start(); }; - TimedEvent event(std::chrono::steady_clock::now() + 2s, reconnect_later, "XMPP reconnection"); + TimedEvent event(std::chrono::steady_clock::now() + 2s, reconnect_later, reconnect_name); TimedEventsManager::instance().add_event(std::move(event)); } } diff --git a/src/utils/timed_events.hpp b/src/utils/timed_events.hpp index 393b38d..fa0fc50 100644 --- a/src/utils/timed_events.hpp +++ b/src/utils/timed_events.hpp @@ -125,6 +125,11 @@ public: * Return the number of managed events. */ std::size_t size() const; + /** + * Return a pointer to the first event with the given name. If none + * is found, returns nullptr. + */ + const TimedEvent* find_event(const std::string& name) const; private: std::vector<TimedEvent> events; diff --git a/src/utils/timed_events_manager.cpp b/src/utils/timed_events_manager.cpp index 67d61fe..75e6338 100644 --- a/src/utils/timed_events_manager.cpp +++ b/src/utils/timed_events_manager.cpp @@ -1,5 +1,7 @@ #include <utils/timed_events.hpp> +#include <algorithm> + TimedEventsManager& TimedEventsManager::instance() { static TimedEventsManager inst; @@ -67,7 +69,19 @@ std::size_t TimedEventsManager::cancel(const std::string& name) return res; } + + std::size_t TimedEventsManager::size() const { return this->events.size(); } + +const TimedEvent* TimedEventsManager::find_event(const std::string& name) const +{ + const auto it = std::find_if(this->events.begin(), this->events.end(), [&name](const TimedEvent& o) { + return o.get_name() == name; + }); + if (it == this->events.end()) + return nullptr; + return &*it; +} diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index aca6ffd..4ca7ff8 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -1263,6 +1263,31 @@ if __name__ == '__main__': "/iq[@from='#foo%{irc_server_one}/{nick_one}'][@type='result'][@to='{jid_one}/{resource_two}'][@id='third_ping']"), ]), + Scenario("self_ping_fixed_server", [ + handshake_sequence(), + partial(send_stanza, + "<presence from='{jid_one}/{resource_one}' to='#foo@{biboumi_host}/{nick_one}' />"), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + "/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo@{biboumi_host}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo@{biboumi_host}'][@type='groupchat']/subject[not(text())]"), + + # Send a ping to ourself + partial(send_stanza, + "<iq type='get' from='{jid_one}/{resource_one}' id='first_ping' to='#foo@{biboumi_host}/{nick_one}'><ping xmlns='urn:xmpp:ping' /></iq>"), + # We receive our own ping request, + partial(expect_stanza, + "/iq[@from='{lower_nick_one}@{biboumi_host}'][@type='get'][@to='{jid_one}/{resource_one}'][@id='gnip_tsrif']"), + # Respond to the request + partial(send_stanza, + "<iq type='result' to='{lower_nick_one}@{biboumi_host}' id='gnip_tsrif' from='{jid_one}/{resource_one}'/>"), + partial(expect_stanza, + "/iq[@from='#foo@{biboumi_host}/{nick_one}'][@type='result'][@to='{jid_one}/{resource_one}'][@id='first_ping']"), + ], conf="fixed_server"), Scenario("simple_kick", [ handshake_sequence(), |