Use libuuid to generate unique IDs for iq and adhoc sessions

This commit is contained in:
Florent Le Coz
2014-05-30 13:39:00 +02:00
parent 8eb9e535a3
commit a63faf6fa9
5 changed files with 60 additions and 9 deletions
+8 -3
View File
@@ -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
+7 -3
View File
@@ -13,14 +13,14 @@
#include <config.h>
#include <uuid.h>
#ifdef SYSTEMDDAEMON_FOUND
# include <systemd/sd-daemon.h>
#endif
using namespace std::string_literals;
unsigned long XmppComponent::current_id = 0;
static std::set<std::string> 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;
}
-2
View File
@@ -235,8 +235,6 @@ private:
*/
std::unordered_map<std::string, std::unique_ptr<Bridge>> bridges;
static unsigned long current_id;
AdhocCommandsHandler adhoc_commands_handler;
XmppComponent(const XmppComponent&) = delete;
XmppComponent(XmppComponent&&) = delete;