mirror of
https://github.com/profanity-im/profanity.git
synced 2025-07-26 12:14:28 -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:
parent
bcaf55e5b8
commit
f4fb61b0c8
18
src/common.c
18
src/common.c
@ -56,6 +56,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "tools/p_sha1.h"
|
#include "tools/p_sha1.h"
|
||||||
|
#include "xmpp/xmpp.h"
|
||||||
|
|
||||||
struct curl_data_t
|
struct curl_data_t
|
||||||
{
|
{
|
||||||
@ -63,8 +64,6 @@ struct curl_data_t
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned long unique_id = 0;
|
|
||||||
|
|
||||||
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
|
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -337,25 +336,22 @@ create_unique_id(char *prefix)
|
|||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
GString *result_str = g_string_new("");
|
GString *result_str = g_string_new("");
|
||||||
|
char *uuid = connection_create_uuid();
|
||||||
|
|
||||||
unique_id++;
|
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id);
|
g_string_printf(result_str, "prof_%s_%s", prefix, uuid);
|
||||||
} else {
|
} 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;
|
result = result_str->str;
|
||||||
g_string_free(result_str, FALSE);
|
g_string_free(result_str, FALSE);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
reset_unique_id(void)
|
|
||||||
{
|
|
||||||
unique_id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
p_sha1_hash(char *str)
|
p_sha1_hash(char *str)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,6 @@ gboolean release_is_new(char *found_version);
|
|||||||
|
|
||||||
char* p_sha1_hash(char *str);
|
char* p_sha1_hash(char *str);
|
||||||
char* create_unique_id(char *prefix);
|
char* create_unique_id(char *prefix);
|
||||||
void reset_unique_id(void);
|
|
||||||
|
|
||||||
char* get_file_or_linked(char *loc, char *basedir);
|
char* get_file_or_linked(char *loc, char *basedir);
|
||||||
char* strip_arg_quotes(const char *const input);
|
char* strip_arg_quotes(const char *const input);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user