1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

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
This commit is contained in:
Michael Vetter 2018-08-14 15:49:25 +02:00
parent bcaf55e5b8
commit f4fb61b0c8
2 changed files with 7 additions and 12 deletions

View File

@ -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)
{

View File

@ -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);