libpurple/connection.c

changeset 41300
fa932768f319
parent 41156
268e57363246
child 41429
1f1a3fbb2759
--- a/libpurple/connection.c	Thu Mar 17 21:41:10 2022 -0500
+++ b/libpurple/connection.c	Thu Mar 17 23:22:29 2022 -0500
@@ -47,6 +47,8 @@
 struct _PurpleConnection {
 	GObject gparent;
 
+	gchar *id;
+
 	PurpleProtocol *protocol;     /* The protocol.                     */
 	PurpleConnectionFlags flags;  /* Connection flags.                 */
 
@@ -83,6 +85,7 @@
 
 enum {
 	PROP_0,
+	PROP_ID,
 	PROP_PROTOCOL,
 	PROP_FLAGS,
 	PROP_STATE,
@@ -275,6 +278,13 @@
 	return gc->account;
 }
 
+const gchar *
+purple_connection_get_id(PurpleConnection *connection) {
+	g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), NULL);
+
+	return connection->id;
+}
+
 PurpleProtocol *
 purple_connection_get_protocol(PurpleConnection *gc) {
 	g_return_val_if_fail(PURPLE_IS_CONNECTION(gc), NULL);
@@ -641,6 +651,18 @@
 	return type;
 }
 
+
+/**************************************************************************
+ * Helpers
+ **************************************************************************/
+static void
+purple_connection_set_id(PurpleConnection *connection, const gchar *id) {
+	g_free(connection->id);
+	connection->id = g_strdup(id);
+
+	g_object_notify_by_pspec(G_OBJECT(connection), properties[PROP_ID]);
+}
+
 /**************************************************************************
  * GObject code
  **************************************************************************/
@@ -652,6 +674,9 @@
 	PurpleConnection *gc = PURPLE_CONNECTION(obj);
 
 	switch (param_id) {
+		case PROP_ID:
+			purple_connection_set_id(gc, g_value_get_string(value));
+			break;
 		case PROP_PROTOCOL:
 			gc->protocol = g_value_get_object(value);
 			break;
@@ -684,6 +709,9 @@
 	PurpleConnection *gc = PURPLE_CONNECTION(obj);
 
 	switch (param_id) {
+		case PROP_ID:
+			g_value_set_string(value, purple_connection_get_id(gc));
+			break;
 		case PROP_PROTOCOL:
 			g_value_set_object(value, purple_connection_get_protocol(gc));
 			break;
@@ -721,6 +749,14 @@
 
 	G_OBJECT_CLASS(purple_connection_parent_class)->constructed(object);
 
+	if(gc->id == NULL) {
+		gchar *uuid = g_uuid_string_random();
+
+		purple_connection_set_id(gc, uuid);
+
+		g_free(uuid);
+	}
+
 	g_object_get(gc, "account", &account, NULL);
 	purple_account_set_connection(account, gc);
 	g_object_unref(account);
@@ -796,6 +832,7 @@
 
 	purple_str_wipe(gc->password);
 	g_free(gc->display_name);
+	g_free(gc->id);
 
 	G_OBJECT_CLASS(purple_connection_parent_class)->finalize(object);
 }
@@ -809,6 +846,12 @@
 	obj_class->finalize = purple_connection_finalize;
 	obj_class->constructed = purple_connection_constructed;
 
+	properties[PROP_ID] = g_param_spec_string(
+		"id", "id",
+		"The identifier of the account",
+		NULL,
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
 	properties[PROP_PROTOCOL] = g_param_spec_object(
 		"protocol", "Protocol",
 		"The protocol that the connection is using.",

mercurial