From a63faf6fa95017dbbfeaf0ff43fdb526c4ae7068 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 30 May 2014 13:39:00 +0200 Subject: Use libuuid to generate unique IDs for iq and adhoc sessions --- src/test.cpp | 11 ++++++++--- src/xmpp/xmpp_component.cpp | 10 +++++++--- src/xmpp/xmpp_component.hpp | 2 -- 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/test.cpp b/src/test.cpp index 8fe739c..ac14377 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -121,9 +121,14 @@ int main() /** * Id generation */ - assert(XmppComponent::next_id() == "0"); - assert(XmppComponent::next_id() == "1"); - assert(XmppComponent::next_id() == "2"); + std::cout << color << "Testing id generation…" << reset << std::endl; + const std::string first_uuid = XmppComponent::next_id(); + const std::string second_uuid = XmppComponent::next_id(); + std::cout << first_uuid << std::endl; + std::cout << second_uuid << std::endl; + assert(first_uuid.size() == 36); + assert(second_uuid.size() == 36); + assert(first_uuid != second_uuid); /** * Utils diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 4c62aa7..9547e3a 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -13,14 +13,14 @@ #include +#include + #ifdef SYSTEMDDAEMON_FOUND # include #endif using namespace std::string_literals; -unsigned long XmppComponent::current_id = 0; - static std::set kickable_errors{ "gone", "internal-server-error", @@ -934,5 +934,9 @@ void XmppComponent::send_iq_version_request(const std::string& from, std::string XmppComponent::next_id() { - return std::to_string(XmppComponent::current_id++); + char uuid_str[37]; + uuid_t uuid; + uuid_generate(uuid); + uuid_unparse(uuid, uuid_str); + return uuid_str; } diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp index b234d76..e3e24e0 100644 --- a/src/xmpp/xmpp_component.hpp +++ b/src/xmpp/xmpp_component.hpp @@ -235,8 +235,6 @@ private: */ std::unordered_map> bridges; - static unsigned long current_id; - AdhocCommandsHandler adhoc_commands_handler; XmppComponent(const XmppComponent&) = delete; XmppComponent(XmppComponent&&) = delete; -- cgit v1.2.3