about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2018-08-14 15:49:25 +0200
committerMichael Vetter <jubalh@iodoru.org>2018-08-14 15:51:18 +0200
commitf4fb61b0c83b0eea20f7b60fa83bc116fd103a84 (patch)
tree1e9dd1e0edcecf377e67d5ca5a18a69aa2a108a4 /src
parentbcaf55e5b8525ea91346657520ff47f45cbbe064 (diff)
downloadprofani-tty-f4fb61b0c83b0eea20f7b60fa83bc116fd103a84.tar.gz
Use uuid in create_unique_id instead of counter
Message IDs should be unique so they can be used by XEPs like delivery receipts, chat markers, message correction.

So far it used a counter so restarting profanity will cause the counter
to be 0 again.

Let's rather use an UUID since we have such a function in the
xmpp/xmpp.h already.

Closes https://github.com/boothj5/profanity/issues/998
Diffstat (limited to 'src')
-rw-r--r--src/common.c18
-rw-r--r--src/common.h1
2 files changed, 7 insertions, 12 deletions
diff --git a/src/common.c b/src/common.c
index a3893c06..0e9585d6 100644
--- a/src/common.c
+++ b/src/common.c
@@ -56,6 +56,7 @@
 #include "log.h"
 #include "common.h"
 #include "tools/p_sha1.h"
+#include "xmpp/xmpp.h"
 
 struct curl_data_t
 {
@@ -63,8 +64,6 @@ struct curl_data_t
     size_t size;
 };
 
-static unsigned long unique_id = 0;
-
 static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
 
 gboolean
@@ -337,25 +336,22 @@ create_unique_id(char *prefix)
 {
     char *result = NULL;
     GString *result_str = g_string_new("");
+    char *uuid = connection_create_uuid();
 
-    unique_id++;
     if (prefix) {
-        g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id);
+        g_string_printf(result_str, "prof_%s_%s", prefix, uuid);
     } else {
-        g_string_printf(result_str, "prof_%lu", unique_id);
+        g_string_printf(result_str, "prof_%s", uuid);
     }
+
+    connection_free_uuid(uuid);
+
     result = result_str->str;
     g_string_free(result_str, FALSE);
 
     return result;
 }
 
-void
-reset_unique_id(void)
-{
-    unique_id = 0;
-}
-
 char*
 p_sha1_hash(char *str)
 {
diff --git a/src/common.h b/src/common.h
index a53fdf9c..a2135288 100644
--- a/src/common.h
+++ b/src/common.h
@@ -94,7 +94,6 @@ gboolean release_is_new(char *found_version);
 
 char* p_sha1_hash(char *str);
 char* create_unique_id(char *prefix);
-void reset_unique_id(void);
 
 char* get_file_or_linked(char *loc, char *basedir);
 char* strip_arg_quotes(const char *const input);