pidgin/pidgin

Parents 992049f86586
Children 9d2735c0e848
Use a checksum of the protocol id and account username for accounts without ids

This still isn't bullet proof, but it's better than just a UUID4. Any change to
a username, or switch protocols will potentially orphan lots of records, but
this is a step in the right direction.

In the future I'm thinking account names might be better, but the jury is still
out on that one.

Testing Done:
Created a new account and verified that it got a sha256 digest as its id in `accounts.xml`.

Reviewed at https://reviews.imfreedom.org/r/2052/
--- a/libpurple/account.c Tue Nov 08 22:12:47 2022 -0600
+++ b/libpurple/account.c Wed Nov 09 23:04:13 2022 -0600
@@ -749,13 +749,16 @@
G_OBJECT_CLASS(purple_account_parent_class)->constructed(object);
- /* If we didn't get an id, just generate a random one. */
+ /* If we didn't get an id, checksum the protocol id and the username. */
if(account->id == NULL) {
- gchar *uuid = g_uuid_string_random();
-
- purple_account_set_id(account, uuid);
-
- g_free(uuid);
+ GChecksum *checksum = g_checksum_new(G_CHECKSUM_SHA256);
+
+ g_checksum_update(checksum, (const guchar *)account->protocol_id, -1);
+ g_checksum_update(checksum, (const guchar *)account->username, -1);
+
+ purple_account_set_id(account, g_checksum_get_string(checksum));
+
+ g_checksum_free(checksum);
}
g_object_get(object,