De-privatize Facebook classes

Tue, 20 Sep 2022 22:43:37 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Tue, 20 Sep 2022 22:43:37 -0500
changeset 41728
e9b96ef5ea38
parent 41727
d88b05eadbd7
child 41729
35d53c7ca722

De-privatize Facebook classes

Also fix their `dispose` methods, which should be safe to call twice.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/1822/

libpurple/protocols/facebook/api.c file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/data.c file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/thrift.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/facebook/api.c	Tue Sep 20 03:31:39 2022 -0500
+++ b/libpurple/protocols/facebook/api.c	Tue Sep 20 22:43:37 2022 -0500
@@ -49,8 +49,14 @@
 	PROP_N
 };
 
-typedef struct
-{
+/**
+ * FbApi:
+ *
+ * Represents a Facebook Messenger connection.
+ */
+struct _FbApi {
+	GObject parent;
+
 	FbMqtt *mqtt;
 	SoupSession *cons;
 	PurpleConnection *gc;
@@ -69,17 +75,6 @@
 	guint unread;
 	FbId lastmid;
 	gchar *contacts_delta;
-} FbApiPrivate;
-
-/**
- * FbApi:
- *
- * Represents a Facebook Messenger connection.
- */
-struct _FbApi
-{
-	GObject parent;
-	FbApiPrivate *priv;
 };
 
 static void fb_api_error_literal(FbApi *api, FbApiError error,
@@ -100,36 +95,36 @@
 void
 fb_api_contacts_delta(FbApi *api, const gchar *delta_cursor);
 
-G_DEFINE_TYPE_WITH_PRIVATE(FbApi, fb_api, G_TYPE_OBJECT);
+G_DEFINE_TYPE(FbApi, fb_api, G_TYPE_OBJECT);
 
 static void
 fb_api_set_property(GObject *obj, guint prop, const GValue *val,
                     GParamSpec *pspec)
 {
-	FbApiPrivate *priv = FB_API(obj)->priv;
+	FbApi *api = FB_API(obj);
 
 	switch (prop) {
 	case PROP_CID:
-		g_free(priv->cid);
-		priv->cid = g_value_dup_string(val);
+		g_free(api->cid);
+		api->cid = g_value_dup_string(val);
 		break;
 	case PROP_DID:
-		g_free(priv->did);
-		priv->did = g_value_dup_string(val);
+		g_free(api->did);
+		api->did = g_value_dup_string(val);
 		break;
 	case PROP_MID:
-		priv->mid = g_value_get_uint64(val);
+		api->mid = g_value_get_uint64(val);
 		break;
 	case PROP_STOKEN:
-		g_free(priv->stoken);
-		priv->stoken = g_value_dup_string(val);
+		g_free(api->stoken);
+		api->stoken = g_value_dup_string(val);
 		break;
 	case PROP_TOKEN:
-		g_free(priv->token);
-		priv->token = g_value_dup_string(val);
+		g_free(api->token);
+		api->token = g_value_dup_string(val);
 		break;
 	case PROP_UID:
-		priv->uid = g_value_get_int64(val);
+		api->uid = g_value_get_int64(val);
 		break;
 
 	default:
@@ -141,26 +136,26 @@
 static void
 fb_api_get_property(GObject *obj, guint prop, GValue *val, GParamSpec *pspec)
 {
-	FbApiPrivate *priv = FB_API(obj)->priv;
+	FbApi *api = FB_API(obj);
 
 	switch (prop) {
 	case PROP_CID:
-		g_value_set_string(val, priv->cid);
+		g_value_set_string(val, api->cid);
 		break;
 	case PROP_DID:
-		g_value_set_string(val, priv->did);
+		g_value_set_string(val, api->did);
 		break;
 	case PROP_MID:
-		g_value_set_uint64(val, priv->mid);
+		g_value_set_uint64(val, api->mid);
 		break;
 	case PROP_STOKEN:
-		g_value_set_string(val, priv->stoken);
+		g_value_set_string(val, api->stoken);
 		break;
 	case PROP_TOKEN:
-		g_value_set_string(val, priv->token);
+		g_value_set_string(val, api->token);
 		break;
 	case PROP_UID:
-		g_value_set_int64(val, priv->uid);
+		g_value_set_int64(val, api->uid);
 		break;
 
 	default:
@@ -173,22 +168,25 @@
 static void
 fb_api_dispose(GObject *obj)
 {
-	FbApiPrivate *priv = FB_API(obj)->priv;
-
-	soup_session_abort(priv->cons);
-
-	if (G_UNLIKELY(priv->mqtt != NULL)) {
-		g_object_unref(priv->mqtt);
+	FbApi *api = FB_API(obj);
+
+	if(api->cons != NULL) {
+		soup_session_abort(api->cons);
 	}
 
-	g_object_unref(priv->cons);
-	g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
-
-	g_free(priv->cid);
-	g_free(priv->did);
-	g_free(priv->stoken);
-	g_free(priv->token);
-	g_free(priv->contacts_delta);
+	g_clear_object(&api->mqtt);
+
+	g_clear_object(&api->cons);
+	if(api->msgs != NULL) {
+		g_queue_free_full(api->msgs, (GDestroyNotify)fb_api_message_free);
+		api->msgs = NULL;
+	}
+
+	g_clear_pointer(&api->cid, g_free);
+	g_clear_pointer(&api->did, g_free);
+	g_clear_pointer(&api->stoken, g_free);
+	g_clear_pointer(&api->token, g_free);
+	g_clear_pointer(&api->contacts_delta, g_free);
 }
 
 static void
@@ -506,10 +504,7 @@
 static void
 fb_api_init(FbApi *api)
 {
-	FbApiPrivate *priv = fb_api_get_instance_private(api);
-	api->priv = priv;
-
-	priv->msgs = g_queue_new();
+	api->msgs = g_queue_new();
 }
 
 GQuark
@@ -529,7 +524,6 @@
 {
 	const gchar *str;
 	FbApiError errc = FB_API_ERROR_GENERAL;
-	FbApiPrivate *priv;
 	FbJsonValues *values;
 	gboolean success = TRUE;
 	gchar *msg;
@@ -547,7 +541,6 @@
 	};
 
 	g_return_val_if_fail(FB_IS_API(api), FALSE);
-	priv = api->priv;
 
 	if (G_UNLIKELY(size == 0)) {
 		fb_api_error_literal(api, FB_API_ERROR_GENERAL, _("Empty JSON data"));
@@ -579,11 +572,8 @@
 		errc = FB_API_ERROR_AUTH;
 		success = FALSE;
 
-		g_free(priv->stoken);
-		priv->stoken = NULL;
-
-		g_free(priv->token);
-		priv->token = NULL;
+		g_clear_pointer(&api->stoken, g_free);
+		g_clear_pointer(&api->token, g_free);
 	}
 
 	/* 509 is used for "invalid attachment id" */
@@ -600,8 +590,7 @@
 		errc = FB_API_ERROR_QUEUE;
 		success = FALSE;
 
-		g_free(priv->stoken);
-		priv->stoken = NULL;
+		g_clear_pointer(&api->stoken, g_free);
 	}
 
 	g_object_unref(values);
@@ -688,7 +677,6 @@
                 const gchar *method, FbHttpParams *params,
                 SoupSessionCallback callback)
 {
-	FbApiPrivate *priv = api->priv;
 	gchar *data;
 	gchar *key;
 	gchar *val;
@@ -698,7 +686,7 @@
 	SoupMessage *msg;
 
 	fb_http_params_set_str(params, "api_key", FB_API_KEY);
-	fb_http_params_set_str(params, "device_id", priv->did);
+	fb_http_params_set_str(params, "device_id", api->did);
 	fb_http_params_set_str(params, "fb_api_req_friendly_name", name);
 	fb_http_params_set_str(params, "format", "json");
 	fb_http_params_set_str(params, "method", method);
@@ -731,14 +719,14 @@
 	msg = soup_message_new_from_encoded_form("POST", url, soup_form_encode_hash(params));
 	fb_http_params_free(params);
 
-	if (priv->token != NULL) {
-		data = g_strdup_printf("OAuth %s", priv->token);
+	if (api->token != NULL) {
+		data = g_strdup_printf("OAuth %s", api->token);
 		soup_message_headers_replace(soup_message_get_request_headers(msg),
 		                             "Authorization", data);
 		g_free(data);
 	}
 
-	soup_session_queue_message(priv->cons, msg, callback, api);
+	soup_session_queue_message(api->cons, msg, callback, api);
 
 	fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", msg);
 	fb_util_debug(FB_UTIL_DEBUG_INFO, "  Request URL: %s", url);
@@ -815,12 +803,11 @@
 fb_api_cb_mqtt_error(FbMqtt *mqtt, GError *error, gpointer data)
 {
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
-
-	if (!priv->retrying) {
-		priv->retrying = TRUE;
+
+	if (!api->retrying) {
+		api->retrying = TRUE;
 		fb_util_debug_info("Attempting to reconnect the MQTT stream...");
-		fb_api_connect(api, priv->invisible);
+		fb_api_connect(api, api->invisible);
 	} else {
 		g_signal_emit_by_name(api, "error", error);
 	}
@@ -831,7 +818,6 @@
 {
 	const GByteArray *bytes;
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
 	FbThrift *thft;
 	GByteArray *cytes;
 	GError *err = NULL;
@@ -844,13 +830,13 @@
 
 	/* Write the client identifier */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 1, 0);
-	fb_thrift_write_str(thft, priv->cid);
+	fb_thrift_write_str(thft, api->cid);
 
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRUCT, 4, 1);
 
 	/* Write the user identifier */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_I64, 1, 0);
-	fb_thrift_write_i64(thft, priv->uid);
+	fb_thrift_write_i64(thft, api->uid);
 
 	/* Write the information string */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 2, 1);
@@ -874,11 +860,11 @@
 
 	/* Write the visibility state */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_BOOL, 7, 6);
-	fb_thrift_write_bool(thft, !priv->invisible);
+	fb_thrift_write_bool(thft, !api->invisible);
 
 	/* Write the device identifier */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 8, 7);
-	fb_thrift_write_str(thft, priv->did);
+	fb_thrift_write_str(thft, api->did);
 
 	/* Write the UNKNOWN ("fg"?) */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_BOOL, 9, 8);
@@ -894,7 +880,7 @@
 
 	/* Write the MQTT identifier */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_I64, 12, 11);
-	fb_thrift_write_i64(thft, priv->mid);
+	fb_thrift_write_i64(thft, api->mid);
 
 	/* Write the UNKNOWN */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_LIST, 14, 12);
@@ -903,7 +889,7 @@
 
 	/* Write the token */
 	fb_thrift_write_field(thft, FB_THRIFT_TYPE_STRING, 15, 14);
-	fb_thrift_write_str(thft, priv->token);
+	fb_thrift_write_str(thft, api->token);
 
 	/* Write the STOP for the struct */
 	fb_thrift_write_stop(thft);
@@ -927,7 +913,6 @@
 fb_api_connect_queue(FbApi *api)
 {
 	FbApiMessage *msg;
-	FbApiPrivate *priv = api->priv;
 	gchar *json;
 	JsonBuilder *bldr;
 
@@ -937,11 +922,10 @@
 	fb_json_bldr_add_int(bldr, "sync_api_version", 3);
 	fb_json_bldr_add_str(bldr, "encoding", "JSON");
 
-	if (priv->stoken == NULL) {
-		fb_json_bldr_add_int(bldr, "initial_titan_sequence_id",
-		                     priv->sid);
-		fb_json_bldr_add_str(bldr, "device_id", priv->did);
-		fb_json_bldr_add_int(bldr, "entity_fbid", priv->uid);
+	if (api->stoken == NULL) {
+		fb_json_bldr_add_int(bldr, "initial_titan_sequence_id", api->sid);
+		fb_json_bldr_add_str(bldr, "device_id", api->did);
+		fb_json_bldr_add_int(bldr, "entity_fbid", api->uid);
 
 		fb_json_bldr_obj_begin(bldr, "queue_params");
 		fb_json_bldr_add_str(bldr, "buzz_on_deltas_enabled", "false");
@@ -965,21 +949,21 @@
 		return;
 	}
 
-	fb_json_bldr_add_int(bldr, "last_seq_id", priv->sid);
-	fb_json_bldr_add_str(bldr, "sync_token", priv->stoken);
+	fb_json_bldr_add_int(bldr, "last_seq_id", api->sid);
+	fb_json_bldr_add_str(bldr, "sync_token", api->stoken);
 
 	json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
 	fb_api_publish(api, "/messenger_sync_get_diffs", "%s", json);
 	g_signal_emit_by_name(api, "connect");
 	g_free(json);
 
-	if (!g_queue_is_empty(priv->msgs)) {
-		msg = g_queue_peek_head(priv->msgs);
+	if (!g_queue_is_empty(api->msgs)) {
+		msg = g_queue_peek_head(api->msgs);
 		fb_api_message_send(api, msg);
 	}
 
-	if (priv->retrying) {
-		priv->retrying = FALSE;
+	if (api->retrying) {
+		api->retrying = FALSE;
 		fb_util_debug_info("Reconnected the MQTT stream");
 	}
 }
@@ -990,7 +974,6 @@
 {
 	const gchar *str;
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
 	FbJsonValues *values;
 	GError *err = NULL;
 	JsonNode *root;
@@ -1013,10 +996,10 @@
 	);
 
 	str = fb_json_values_next_str(values, "0");
-	priv->sid = g_ascii_strtoll(str, NULL, 10);
-	priv->unread = fb_json_values_next_int(values, 0);
-
-	if (priv->sid == 0) {
+	api->sid = g_ascii_strtoll(str, NULL, 10);
+	api->unread = fb_json_values_next_int(values, 0);
+
+	if (api->sid == 0) {
 		fb_api_error_literal(api, FB_API_ERROR_GENERAL,
 		                     _("Failed to get sync_sequence_id"));
 	} else {
@@ -1031,7 +1014,6 @@
 fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpointer data)
 {
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
 	gchar *json;
 	JsonBuilder *bldr;
 
@@ -1061,7 +1043,7 @@
 	/* Notifications seem to lead to some sort of sending rate limit */
 	fb_mqtt_unsubscribe(mqtt, "/orca_message_notifications", NULL);
 
-	if (priv->sid == 0) {
+	if (api->sid == 0) {
 		bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 		fb_json_bldr_add_str(bldr, "1", "0");
 		fb_api_http_query(api, FB_API_QUERY_SEQ_ID, bldr,
@@ -1230,7 +1212,6 @@
 fb_api_cb_publish_typing(FbApi *api, GByteArray *pload)
 {
 	const gchar *str;
-	FbApiPrivate *priv = api->priv;
 	FbApiTyping typg;
 	FbJsonValues *values;
 	GError *err = NULL;
@@ -1257,7 +1238,7 @@
 	if (g_ascii_strcasecmp(str, "typ") == 0) {
 		typg.uid = fb_json_values_next_int(values, 0);
 
-		if (typg.uid != priv->uid) {
+		if (typg.uid != api->uid) {
 			typg.state = fb_json_values_next_int(values, 0);
 			g_signal_emit_by_name(api, "typing", &typg);
 		}
@@ -1271,7 +1252,6 @@
 fb_api_cb_publish_ms_r(FbApi *api, GByteArray *pload)
 {
 	FbApiMessage *msg;
-	FbApiPrivate *priv = api->priv;
 	FbJsonValues *values;
 	GError *err = NULL;
 	JsonNode *root;
@@ -1292,11 +1272,11 @@
 
 	if (fb_json_values_next_bool(values, TRUE)) {
 		/* Pop and free the successful message */
-		msg = g_queue_pop_head(priv->msgs);
+		msg = g_queue_pop_head(api->msgs);
 		fb_api_message_free(msg);
 
-		if (!g_queue_is_empty(priv->msgs)) {
-			msg = g_queue_peek_head(priv->msgs);
+		if (!g_queue_is_empty(api->msgs)) {
+			msg = g_queue_peek_head(api->msgs);
 			fb_api_message_send(api, msg);
 		}
 	} else {
@@ -1449,7 +1429,6 @@
 fb_api_cb_publish_ms(FbApi *api, GByteArray *pload)
 {
 	const gchar *data;
-	FbApiPrivate *priv = api->priv;
 	FbJsonValues *values;
 	FbThrift *thft;
 	gchar *stoken;
@@ -1503,13 +1482,13 @@
 		return;
 	);
 
-	priv->sid = fb_json_values_next_int(values, 0);
+	api->sid = fb_json_values_next_int(values, 0);
 	stoken = fb_json_values_next_str_dup(values, NULL);
 	g_object_unref(values);
 
 	if (G_UNLIKELY(stoken != NULL)) {
-		g_free(priv->stoken);
-		priv->stoken = stoken;
+		g_free(api->stoken);
+		api->stoken = stoken;
 		g_signal_emit_by_name(api, "connect");
 		json_node_free(root);
 		return;
@@ -1569,7 +1548,6 @@
 	const gchar *body;
 	const gchar *str;
 	GError *err = NULL;
-	FbApiPrivate *priv = api->priv;
 	FbApiMessage *dmsg;
 	FbApiMessage msg;
 	FbId id;
@@ -1606,19 +1584,19 @@
 		}
 
 		/* Ignore sequential duplicates */
-		if (id == priv->lastmid) {
+		if (id == api->lastmid) {
 			fb_util_debug_info("Ignoring duplicate %" FB_ID_FORMAT, id);
 			goto beach;
 		}
 
-		priv->lastmid = id;
+		api->lastmid = id;
 		fb_api_message_reset(&msg, FALSE);
 		msg.uid = fb_json_values_next_int(values, 0);
 		oid = fb_json_values_next_int(values, 0);
 		msg.tid = fb_json_values_next_int(values, 0);
 		msg.tstamp = fb_json_values_next_int(values, 0);
 
-		if (msg.uid == priv->uid) {
+		if (msg.uid == api->uid) {
 			msg.flags |= FB_API_MESSAGE_FLAG_SELF;
 
 			if (msg.tid == 0) {
@@ -1919,31 +1897,29 @@
 fb_api_new(PurpleConnection *gc, GProxyResolver *resolver)
 {
 	FbApi *api;
-	FbApiPrivate *priv;
 
 	api = g_object_new(FB_TYPE_API, NULL);
-	priv = api->priv;
-
-	priv->gc = gc;
-	priv->cons = soup_session_new_with_options(
+
+	api->gc = gc;
+	api->cons = soup_session_new_with_options(
 	        "proxy-resolver", resolver,
 	        "user-agent", FB_API_AGENT,
 	        NULL);
-	priv->mqtt = fb_mqtt_new(gc);
-
-	g_signal_connect(priv->mqtt,
+	api->mqtt = fb_mqtt_new(gc);
+
+	g_signal_connect(api->mqtt,
 	                 "connect",
 	                 G_CALLBACK(fb_api_cb_mqtt_connect),
 	                 api);
-	g_signal_connect(priv->mqtt,
+	g_signal_connect(api->mqtt,
 	                 "error",
 	                 G_CALLBACK(fb_api_cb_mqtt_error),
 	                 api);
-	g_signal_connect(priv->mqtt,
+	g_signal_connect(api->mqtt,
 	                 "open",
 	                 G_CALLBACK(fb_api_cb_mqtt_open),
 	                 api);
-	g_signal_connect(priv->mqtt,
+	g_signal_connect(api->mqtt,
 	                 "publish",
 	                 G_CALLBACK(fb_api_cb_mqtt_publish),
 	                 api);
@@ -1954,38 +1930,32 @@
 void
 fb_api_rehash(FbApi *api)
 {
-	FbApiPrivate *priv;
-
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
-
-	if (priv->cid == NULL) {
-		priv->cid = fb_util_rand_alnum(32);
+
+	if (api->cid == NULL) {
+		api->cid = fb_util_rand_alnum(32);
+	}
+
+	if (api->did == NULL) {
+		api->did = g_uuid_string_random();
 	}
 
-	if (priv->did == NULL) {
-		priv->did = g_uuid_string_random();
+	if (api->mid == 0) {
+		api->mid = g_random_int();
 	}
 
-	if (priv->mid == 0) {
-		priv->mid = g_random_int();
-	}
-
-	if (strlen(priv->cid) > 20) {
-		priv->cid = g_realloc_n(priv->cid , 21, sizeof *priv->cid);
-		priv->cid[20] = 0;
+	if (strlen(api->cid) > 20) {
+		api->cid = g_realloc_n(api->cid , 21, sizeof *api->cid);
+		api->cid[20] = 0;
 	}
 }
 
 gboolean
 fb_api_is_invisible(FbApi *api)
 {
-	FbApiPrivate *priv;
-
 	g_return_val_if_fail(FB_IS_API(api), FALSE);
-	priv = api->priv;
-
-	return priv->invisible;
+
+	return api->invisible;
 }
 
 static void
@@ -2100,7 +2070,6 @@
                gpointer data)
 {
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
 	FbJsonValues *values;
 	GError *err = NULL;
 	JsonNode *root;
@@ -2120,9 +2089,9 @@
 		return;
 	);
 
-	g_free(priv->token);
-	priv->token = fb_json_values_next_str_dup(values, NULL);
-	priv->uid = fb_json_values_next_int(values, 0);
+	g_free(api->token);
+	api->token = fb_json_values_next_str_dup(values, NULL);
+	api->uid = fb_json_values_next_int(values, 0);
 
 	g_signal_emit_by_name(api, "auth");
 	g_object_unref(values);
@@ -2233,7 +2202,6 @@
 fb_api_cb_contacts_nodes(FbApi *api, JsonNode *root, GSList *users)
 {
 	const gchar *str;
-	FbApiPrivate *priv = api->priv;
 	FbApiUser *user;
 	FbId uid;
 	FbJsonValues *values;
@@ -2262,7 +2230,7 @@
 		str = fb_json_values_next_str(values, NULL);
 
 		if ((!purple_strequal(str, "ARE_FRIENDS") &&
-		    (uid != priv->uid)) || (uid == 0))
+		    (uid != api->uid)) || (uid == 0))
 		{
 			if (!is_array) {
 				break;
@@ -2323,7 +2291,6 @@
 	const gchar *cursor;
 	const gchar *delta_cursor;
 	FbApi *api = data;
-	FbApiPrivate *priv = api->priv;
 	FbJsonValues *values;
 	gboolean complete;
 	gboolean is_delta;
@@ -2391,8 +2358,8 @@
 
 	if (G_UNLIKELY(err == NULL)) {
 		if (is_delta || complete) {
-			g_free(priv->contacts_delta);
-			priv->contacts_delta = g_strdup(is_delta ? cursor : delta_cursor);
+			g_free(api->contacts_delta);
+			api->contacts_delta = g_strdup(is_delta ? cursor : delta_cursor);
 		}
 
 		if (users) {
@@ -2416,14 +2383,12 @@
 void
 fb_api_contacts(FbApi *api)
 {
-	FbApiPrivate *priv;
 	JsonBuilder *bldr;
 
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
-
-	if (priv->contacts_delta) {
-		fb_api_contacts_delta(api, priv->contacts_delta);
+
+	if (api->contacts_delta) {
+		fb_api_contacts_delta(api, api->contacts_delta);
 		return;
 	}
 
@@ -2474,38 +2439,31 @@
 void
 fb_api_connect(FbApi *api, gboolean invisible)
 {
-	FbApiPrivate *priv;
-
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
-
-	priv->invisible = invisible;
-	fb_mqtt_open(priv->mqtt, FB_MQTT_HOST, FB_MQTT_PORT);
+
+	api->invisible = invisible;
+	fb_mqtt_open(api->mqtt, FB_MQTT_HOST, FB_MQTT_PORT);
 }
 
 void
 fb_api_disconnect(FbApi *api)
 {
-	FbApiPrivate *priv;
-
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
-
-	fb_mqtt_disconnect(priv->mqtt);
+
+	fb_mqtt_disconnect(api->mqtt);
 }
 
 static void
 fb_api_message_send(FbApi *api, FbApiMessage *msg)
 {
 	const gchar *tpfx;
-	FbApiPrivate *priv = api->priv;
 	FbId id;
 	FbId mid;
 	gchar *json;
 	JsonBuilder *bldr;
 
 	mid = FB_API_MSGID(g_get_real_time() / 1000, g_random_int());
-	priv->lastmid = mid;
+	api->lastmid = mid;
 
 	if (msg->tid != 0) {
 		tpfx = "tfbid_";
@@ -2518,7 +2476,7 @@
 	bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 	fb_json_bldr_add_str(bldr, "body", msg->text);
 	fb_json_bldr_add_strf(bldr, "msgid", "%" FB_ID_FORMAT, mid);
-	fb_json_bldr_add_strf(bldr, "sender_fbid", "%" FB_ID_FORMAT, priv->uid);
+	fb_json_bldr_add_strf(bldr, "sender_fbid", "%" FB_ID_FORMAT, api->uid);
 	fb_json_bldr_add_strf(bldr, "to", "%s%" FB_ID_FORMAT, tpfx, id);
 
 	json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL);
@@ -2530,12 +2488,10 @@
 fb_api_message(FbApi *api, FbId id, gboolean thread, const gchar *text)
 {
 	FbApiMessage *msg;
-	FbApiPrivate *priv;
 	gboolean empty;
 
 	g_return_if_fail(FB_IS_API(api));
 	g_return_if_fail(text != NULL);
-	priv = api->priv;
 
 	msg = g_new0(FbApiMessage, 1);
 	msg->text = g_strdup(text);
@@ -2546,10 +2502,10 @@
 		msg->uid = id;
 	}
 
-	empty = g_queue_is_empty(priv->msgs);
-	g_queue_push_tail(priv->msgs, msg);
-
-	if (empty && fb_mqtt_connected(priv->mqtt, FALSE)) {
+	empty = g_queue_is_empty(api->msgs);
+	g_queue_push_tail(api->msgs, msg);
+
+	if (empty && fb_mqtt_connected(api->mqtt, FALSE)) {
 		fb_api_message_send(api, msg);
 	}
 }
@@ -2557,7 +2513,6 @@
 void
 fb_api_publish(FbApi *api, const gchar *topic, const gchar *format, ...)
 {
-	FbApiPrivate *priv;
 	GByteArray *bytes;
 	GByteArray *cytes;
 	gchar *msg;
@@ -2567,7 +2522,6 @@
 	g_return_if_fail(FB_IS_API(api));
 	g_return_if_fail(topic != NULL);
 	g_return_if_fail(format != NULL);
-	priv = api->priv;
 
 	va_start(ap, format);
 	msg = g_strdup_vprintf(format, ap);
@@ -2585,7 +2539,7 @@
 	                      "Writing message (topic: %s)",
 			      topic);
 
-	fb_mqtt_publish(priv->mqtt, topic, cytes);
+	fb_mqtt_publish(api->mqtt, topic, cytes);
 	g_byte_array_free(cytes, TRUE);
 	g_byte_array_free(bytes, TRUE);
 }
@@ -2594,16 +2548,14 @@
 fb_api_read(FbApi *api, FbId id, gboolean thread)
 {
 	const gchar *key;
-	FbApiPrivate *priv;
 	gchar *json;
 	JsonBuilder *bldr;
 
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
 
 	bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 	fb_json_bldr_add_bool(bldr, "state", TRUE);
-	fb_json_bldr_add_int(bldr, "syncSeqId", priv->sid);
+	fb_json_bldr_add_int(bldr, "syncSeqId", api->sid);
 	fb_json_bldr_add_str(bldr, "mark", "read");
 
 	key = thread ? "threadFbId" : "otherUserFbId";
@@ -2838,19 +2790,17 @@
 void
 fb_api_unread(FbApi *api)
 {
-	FbApiPrivate *priv;
 	JsonBuilder *bldr;
 
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
-
-	if (priv->unread < 1) {
+
+	if (api->unread < 1) {
 		return;
 	}
 
 	bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 	fb_json_bldr_add_str(bldr, "2", "true");
-	fb_json_bldr_add_int(bldr, "1", priv->unread);
+	fb_json_bldr_add_int(bldr, "1", api->unread);
 	fb_json_bldr_add_str(bldr, "12", "true");
 	fb_json_bldr_add_str(bldr, "13", "false");
 	fb_api_http_query(api, FB_API_QUERY_THREADS, bldr,
@@ -2918,7 +2868,6 @@
                     GError **error)
 {
 	const gchar *str;
-	FbApiPrivate *priv = api->priv;
 	FbApiUser *user;
 	FbId uid;
 	FbJsonValues *values;
@@ -2961,7 +2910,7 @@
 		uid = FB_ID_FROM_STR(str);
 		num_users++;
 
-		if (uid != priv->uid) {
+		if (uid != api->uid) {
 			user = g_new0(FbApiUser, 1);
 			user->uid = uid;
 			user->name = fb_json_values_next_str_dup(values, NULL);
@@ -3083,7 +3032,6 @@
 void
 fb_api_thread_create(FbApi *api, GSList *uids)
 {
-	FbApiPrivate *priv;
 	FbHttpParams *prms;
 	FbId *uid;
 	gchar *json;
@@ -3092,12 +3040,11 @@
 
 	g_return_if_fail(FB_IS_API(api));
 	g_warn_if_fail(g_slist_length(uids) > 1);
-	priv = api->priv;
 
 	bldr = fb_json_bldr_new(JSON_NODE_ARRAY);
 	fb_json_bldr_obj_begin(bldr, NULL);
 	fb_json_bldr_add_str(bldr, "type", "id");
-	fb_json_bldr_add_strf(bldr, "id", "%" FB_ID_FORMAT, priv->uid);
+	fb_json_bldr_add_strf(bldr, "id", "%" FB_ID_FORMAT, api->uid);
 	fb_json_bldr_obj_end(bldr);
 
 	for (l = uids; l != NULL; l = l->next) {
@@ -3141,22 +3088,20 @@
 void
 fb_api_thread_remove(FbApi *api, FbId tid, FbId uid)
 {
-	FbApiPrivate *priv;
 	FbHttpParams *prms;
 	gchar *json;
 	JsonBuilder *bldr;
 
 	g_return_if_fail(FB_IS_API(api));
-	priv = api->priv;
 
 	prms = fb_http_params_new();
 	fb_http_params_set_strf(prms, "id", "t_%" FB_ID_FORMAT, tid);
 
 	if (uid == 0) {
-		uid = priv->uid;
+		uid = api->uid;
 	}
 
-	if (uid != priv->uid) {
+	if (uid != api->uid) {
 		bldr = fb_json_bldr_new(JSON_NODE_ARRAY);
 		fb_json_bldr_add_strf(bldr, NULL, "%" FB_ID_FORMAT, uid);
 		json = fb_json_bldr_close(bldr, JSON_NODE_ARRAY, NULL);
--- a/libpurple/protocols/facebook/data.c	Tue Sep 20 03:31:39 2022 -0500
+++ b/libpurple/protocols/facebook/data.c	Tue Sep 20 22:43:37 2022 -0500
@@ -28,8 +28,14 @@
 #include "api.h"
 #include "data.h"
 
-typedef struct
-{
+/**
+ * FbData:
+ *
+ * Represents the connection data used by #FacebookProtocol.
+ */
+struct _FbData {
+	GObject parent;
+
 	FbApi *api;
 	SoupSession *cons;
 	PurpleConnection *gc;
@@ -41,18 +47,13 @@
 } FbDataPrivate;
 
 /**
- * FbData:
+ * FbDataImage:
  *
- * Represents the connection data used by #FacebookProtocol.
+ * Represents the data used for fetching images.
  */
-struct _FbData
-{
+struct _FbDataImage {
 	GObject parent;
-	FbDataPrivate *priv;
-};
 
-typedef struct
-{
 	FbData *fata;
 	gchar *url;
 	FbDataImageFunc func;
@@ -62,17 +63,6 @@
 	gboolean active;
 	const guint8 *image;
 	gsize size;
-} FbDataImagePrivate;
-
-/**
- * FbDataImage:
- *
- * Represents the data used for fetching images.
- */
-struct _FbDataImage
-{
-	GObject parent;
-	FbDataImagePrivate *priv;
 };
 
 static const gchar *fb_props_strs[] = {
@@ -82,33 +72,39 @@
 	"token"
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE(FbData, fb_data, G_TYPE_OBJECT);
-G_DEFINE_TYPE_WITH_PRIVATE(FbDataImage, fb_data_image, G_TYPE_OBJECT);
+G_DEFINE_TYPE(FbData, fb_data, G_TYPE_OBJECT);
+G_DEFINE_TYPE(FbDataImage, fb_data_image, G_TYPE_OBJECT);
 
 static void
 fb_data_dispose(GObject *obj)
 {
-	FbDataPrivate *priv = FB_DATA(obj)->priv;
-	GHashTableIter iter;
-	gpointer ptr;
+	FbData *fata = FB_DATA(obj);
 
-	soup_session_abort(priv->cons);
-	g_hash_table_iter_init(&iter, priv->evs);
-
-	while (g_hash_table_iter_next(&iter, NULL, &ptr)) {
-		g_source_remove(GPOINTER_TO_UINT(ptr));
+	if(fata->cons != NULL) {
+		soup_session_abort(fata->cons);
 	}
 
-	if (G_LIKELY(priv->api != NULL)) {
-		g_object_unref(priv->api);
+	if(fata->evs != NULL) {
+		GHashTableIter iter;
+		gpointer ptr = NULL;
+
+		g_hash_table_iter_init(&iter, fata->evs);
+		while (g_hash_table_iter_next(&iter, NULL, &ptr)) {
+			g_source_remove(GPOINTER_TO_UINT(ptr));
+		}
 	}
 
-	g_object_unref(priv->cons);
-	g_queue_free_full(priv->msgs, (GDestroyNotify) fb_api_message_free);
+	g_clear_object(&fata->api);
 
-	g_hash_table_destroy(priv->imgs);
-	g_hash_table_destroy(priv->unread);
-	g_hash_table_destroy(priv->evs);
+	g_clear_object(&fata->cons);
+	if(fata->msgs != NULL) {
+		g_queue_free_full(fata->msgs, (GDestroyNotify)fb_api_message_free);
+		fata->msgs = NULL;
+	}
+
+	g_clear_pointer(&fata->imgs, g_hash_table_destroy);
+	g_clear_pointer(&fata->unread, g_hash_table_destroy);
+	g_clear_pointer(&fata->evs, g_hash_table_destroy);
 }
 
 static void
@@ -122,32 +118,28 @@
 static void
 fb_data_init(FbData *fata)
 {
-	FbDataPrivate *priv = fb_data_get_instance_private(fata);
-	fata->priv = priv;
-
-	priv->msgs = g_queue_new();
+	fata->msgs = g_queue_new();
 
-	priv->imgs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+	fata->imgs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
 	                                   g_object_unref, NULL);
-	priv->unread = g_hash_table_new_full(fb_id_hash, fb_id_equal,
+	fata->unread = g_hash_table_new_full(fb_id_hash, fb_id_equal,
 	                                     g_free, NULL);
-	priv->evs = g_hash_table_new_full(g_str_hash, g_str_equal,
-					  g_free, NULL);
+	fata->evs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 }
 
 static void
 fb_data_image_dispose(GObject *obj)
 {
 	FbDataImage *img = FB_DATA_IMAGE(obj);
-	FbDataImagePrivate *priv = img->priv;
-	FbData *fata = priv->fata;
+	FbData *fata = img->fata;
 
-	if ((priv->dunc != NULL) && (priv->data != NULL)) {
-		priv->dunc(priv->data);
+	if (img->dunc != NULL && img->data != NULL) {
+		img->dunc(img->data);
+		img->dunc = NULL;
 	}
 
-	g_free(priv->url);
-	g_hash_table_steal(fata->priv->imgs, img);
+	g_clear_pointer(&img->url, g_free);
+	g_hash_table_steal(fata->imgs, img);
 }
 
 static void
@@ -161,23 +153,19 @@
 static void
 fb_data_image_init(FbDataImage *img)
 {
-	FbDataImagePrivate *priv = fb_data_image_get_instance_private(img);
-	img->priv = priv;
 }
 
 FbData *
 fb_data_new(PurpleConnection *gc, GProxyResolver *resolver)
 {
 	FbData *fata;
-	FbDataPrivate *priv;
 
 	fata = g_object_new(FB_TYPE_DATA, NULL);
-	priv = fata->priv;
 
-	priv->cons = soup_session_new_with_options("proxy-resolver", resolver,
+	fata->cons = soup_session_new_with_options("proxy-resolver", resolver,
 	                                           NULL);
-	priv->api = fb_api_new(gc, resolver);
-	priv->gc = gc;
+	fata->api = fb_api_new(gc, resolver);
+	fata->gc = gc;
 
 	return fata;
 }
@@ -186,7 +174,6 @@
 fb_data_load(FbData *fata)
 {
 	const gchar *str;
-	FbDataPrivate *priv;
 	FbId id;
 	gboolean ret = TRUE;
 	guint i;
@@ -195,8 +182,7 @@
 	PurpleAccount *acct;
 
 	g_return_val_if_fail(FB_IS_DATA(fata), FALSE);
-	priv = fata->priv;
-	acct = purple_connection_get_account(priv->gc);
+	acct = purple_connection_get_account(fata->gc);
 
 	for (i = 0; i < G_N_ELEMENTS(fb_props_strs); i++) {
 		str = purple_account_get_string(acct, fb_props_strs[i], NULL);
@@ -207,7 +193,7 @@
 
 		g_value_init(&val, G_TYPE_STRING);
 		g_value_set_string(&val, str);
-		g_object_set_property(G_OBJECT(priv->api), fb_props_strs[i],
+		g_object_set_property(G_OBJECT(fata->api), fb_props_strs[i],
 		                      &val);
 		g_value_unset(&val);
 	}
@@ -218,7 +204,7 @@
 		uint = g_ascii_strtoull(str, NULL, 10);
 		g_value_init(&val, G_TYPE_UINT64);
 		g_value_set_uint64(&val, uint);
-		g_object_set_property(G_OBJECT(priv->api), "mid", &val);
+		g_object_set_property(G_OBJECT(fata->api), "mid", &val);
 		g_value_unset(&val);
 	} else {
 		ret = FALSE;
@@ -230,13 +216,13 @@
 		id = FB_ID_FROM_STR(str);
 		g_value_init(&val, FB_TYPE_ID);
 		g_value_set_int64(&val, id);
-		g_object_set_property(G_OBJECT(priv->api), "uid", &val);
+		g_object_set_property(G_OBJECT(fata->api), "uid", &val);
 		g_value_unset(&val);
 	} else {
 		ret = FALSE;
 	}
 
-	fb_api_rehash(priv->api);
+	fb_api_rehash(fata->api);
 	return ret;
 }
 
@@ -244,7 +230,6 @@
 fb_data_save(FbData *fata)
 {
 	const gchar *str;
-	FbDataPrivate *priv;
 	gchar *dup;
 	guint i;
 	guint64 uint;
@@ -252,12 +237,11 @@
 	PurpleAccount *acct;
 
 	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
-	acct = purple_connection_get_account(priv->gc);
+	acct = purple_connection_get_account(fata->gc);
 
 	for (i = 0; i < G_N_ELEMENTS(fb_props_strs); i++) {
 		g_value_init(&val, G_TYPE_STRING);
-		g_object_get_property(G_OBJECT(priv->api), fb_props_strs[i],
+		g_object_get_property(G_OBJECT(fata->api), fb_props_strs[i],
 		                      &val);
 		str = g_value_get_string(&val);
 
@@ -269,7 +253,7 @@
 	}
 
 	g_value_init(&val, G_TYPE_UINT64);
-	g_object_get_property(G_OBJECT(priv->api), "mid", &val);
+	g_object_get_property(G_OBJECT(fata->api), "mid", &val);
 	uint = g_value_get_uint64(&val);
 	g_value_unset(&val);
 
@@ -278,7 +262,7 @@
 	g_free(dup);
 
 	g_value_init(&val, G_TYPE_INT64);
-	g_object_get_property(G_OBJECT(priv->api), "uid", &val);
+	g_object_get_property(G_OBJECT(fata->api), "uid", &val);
 	uint = g_value_get_int64(&val);
 	g_value_unset(&val);
 
@@ -290,147 +274,119 @@
 void
 fb_data_save_timeout(FbData *fata, const gchar *name, guint id)
 {
-	FbDataPrivate *priv;
-
 	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
 
 	fb_data_clear_timeout(fata, name, TRUE);
 
-	g_hash_table_replace(priv->evs, g_strdup(name), GUINT_TO_POINTER(id));
+	g_hash_table_replace(fata->evs, g_strdup(name), GUINT_TO_POINTER(id));
 }
 
 void
 fb_data_clear_timeout(FbData *fata, const gchar *name, gboolean remove)
 {
-	FbDataPrivate *priv;
 	gpointer ptr;
 	guint id;
 
 	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
 
-	ptr = g_hash_table_lookup(priv->evs, name);
+	ptr = g_hash_table_lookup(fata->evs, name);
 	id = GPOINTER_TO_UINT(ptr);
 
 	if ((id > 0) && remove) {
 		g_source_remove(id);
 	}
 
-	g_hash_table_remove(priv->evs, name);
+	g_hash_table_remove(fata->evs, name);
 }
 
 FbApi *
 fb_data_get_api(FbData *fata)
 {
-	FbDataPrivate *priv;
 
 	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
-	priv = fata->priv;
 
-	return priv->api;
+	return fata->api;
 }
 
 PurpleConnection *
 fb_data_get_connection(FbData *fata)
 {
-	FbDataPrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
 
-	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
-	priv = fata->priv;
-
-	return priv->gc;
+	return fata->gc;
 }
 
 PurpleRoomlist *
 fb_data_get_roomlist(FbData *fata)
 {
-	FbDataPrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
 
-	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
-	priv = fata->priv;
-
-	return priv->roomlist;
+	return fata->roomlist;
 }
 
 gboolean
 fb_data_get_unread(FbData *fata, FbId id)
 {
-	FbDataPrivate *priv;
 	gpointer *ptr;
 
 	g_return_val_if_fail(FB_IS_DATA(fata), FALSE);
 	g_return_val_if_fail(id != 0, FALSE);
-	priv = fata->priv;
 
-	ptr = g_hash_table_lookup(priv->unread, &id);
+	ptr = g_hash_table_lookup(fata->unread, &id);
 	return GPOINTER_TO_INT(ptr);
 }
 
 void
 fb_data_set_roomlist(FbData *fata, PurpleRoomlist *list)
 {
-	FbDataPrivate *priv;
+	g_return_if_fail(FB_IS_DATA(fata));
 
-	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
-
-	priv->roomlist = list;
+	fata->roomlist = list;
 }
 
 void
 fb_data_set_unread(FbData *fata, FbId id, gboolean unread)
 {
-	FbDataPrivate *priv;
 	gpointer key;
 
 	g_return_if_fail(FB_IS_DATA(fata));
 	g_return_if_fail(id != 0);
-	priv = fata->priv;
 
 	if (!unread) {
-		g_hash_table_remove(priv->unread, &id);
+		g_hash_table_remove(fata->unread, &id);
 		return;
 	}
 
 	key = g_memdup2(&id, sizeof id);
-	g_hash_table_replace(priv->unread, key, GINT_TO_POINTER(unread));
+	g_hash_table_replace(fata->unread, key, GINT_TO_POINTER(unread));
 }
 
 void
 fb_data_add_message(FbData *fata, FbApiMessage *msg)
 {
-	FbDataPrivate *priv;
+	g_return_if_fail(FB_IS_DATA(fata));
 
-	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
-
-	g_queue_push_tail(priv->msgs, msg);
+	g_queue_push_tail(fata->msgs, msg);
 }
 
 void
 fb_data_remove_message(FbData *fata, FbApiMessage *msg)
 {
-	FbDataPrivate *priv;
+	g_return_if_fail(FB_IS_DATA(fata));
 
-	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
-
-	g_queue_remove(priv->msgs, msg);
+	g_queue_remove(fata->msgs, msg);
 }
 
 GSList *
 fb_data_take_messages(FbData *fata, FbId uid)
 {
 	FbApiMessage *msg;
-	FbDataPrivate *priv;
 	GList *l;
 	GList *prev;
 	GSList *msgs = NULL;
 
 	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
-	priv = fata->priv;
-	l = priv->msgs->tail;
+	l = fata->msgs->tail;
 
 	while (l != NULL) {
 		msg = l->data;
@@ -438,7 +394,7 @@
 
 		if (msg->uid == uid) {
 			msgs = g_slist_prepend(msgs, msg);
-			g_queue_delete_link(priv->msgs, l);
+			g_queue_delete_link(fata->msgs, l);
 		}
 
 		l = prev;
@@ -452,101 +408,81 @@
                   gpointer data, GDestroyNotify dunc)
 {
 	FbDataImage *img;
-	FbDataImagePrivate *priv;
 
 	g_return_val_if_fail(FB_IS_DATA(fata), NULL);
 	g_return_val_if_fail(url != NULL, NULL);
 	g_return_val_if_fail(func != NULL, NULL);
 
 	img = g_object_new(FB_TYPE_DATA_IMAGE, NULL);
-	priv = img->priv;
 
-	priv->fata = fata;
-	priv->url = g_strdup(url);
-	priv->func = func;
-	priv->data = data;
-	priv->dunc = dunc;
+	img->fata = fata;
+	img->url = g_strdup(url);
+	img->func = func;
+	img->data = data;
+	img->dunc = dunc;
 
-	g_hash_table_insert(fata->priv->imgs, img, img);
+	g_hash_table_insert(fata->imgs, img, img);
 	return img;
 }
 
 gboolean
 fb_data_image_get_active(FbDataImage *img)
 {
-	FbDataImagePrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), FALSE);
 
-	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), FALSE);
-	priv = img->priv;
-
-	return priv->active;
+	return img->active;
 }
 
 gpointer
 fb_data_image_get_data(FbDataImage *img)
 {
-	FbDataImagePrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
 
-	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
-	priv = img->priv;
-
-	return priv->data;
+	return img->data;
 }
 
 FbData *
 fb_data_image_get_fata(FbDataImage *img)
 {
-	FbDataImagePrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
 
-	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
-	priv = img->priv;
-
-	return priv->fata;
+	return img->fata;
 }
 
 const guint8 *
 fb_data_image_get_image(FbDataImage *img, gsize *size)
 {
-	FbDataImagePrivate *priv;
-
 	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
-	priv = img->priv;
 
 	if (size != NULL) {
-		*size = priv->size;
+		*size = img->size;
 	}
 
-	return priv->image;
+	return img->image;
 }
 
 guint8 *
 fb_data_image_dup_image(FbDataImage *img, gsize *size)
 {
-	FbDataImagePrivate *priv;
-
 	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
-	priv = img->priv;
 
 	if (size != NULL) {
-		*size = priv->size;
+		*size = img->size;
 	}
 
-	if (priv->size < 1) {
+	if (img->size < 1) {
 		return NULL;
 	}
 
-	return g_memdup2(priv->image, priv->size);
+	return g_memdup2(img->image, img->size);
 }
 
 const gchar *
 fb_data_image_get_url(FbDataImage *img)
 {
-	FbDataImagePrivate *priv;
+	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
 
-	g_return_val_if_fail(FB_IS_DATA_IMAGE(img), NULL);
-	priv = img->priv;
-
-	return priv->url;
+	return img->url;
 }
 
 static void
@@ -554,17 +490,16 @@
                  gpointer data)
 {
 	FbDataImage *img = data;
-	FbDataImagePrivate *priv = img->priv;
 	GError *err = NULL;
 
 	fb_http_error_chk(res, &err);
 
-	priv->image = (guint8 *)res->response_body->data;
-	priv->size = res->response_body->length;
-	priv->func(img, err);
+	img->image = (guint8 *)res->response_body->data;
+	img->size = res->response_body->length;
+	img->func(img, err);
 
 	if (G_LIKELY(err == NULL)) {
-		fb_data_image_queue(priv->fata);
+		fb_data_image_queue(img->fata);
 	} else {
 		g_error_free(err);
 	}
@@ -577,13 +512,11 @@
 {
 	const gchar *url;
 	FbDataImage *img;
-	FbDataPrivate *priv;
 	GHashTableIter iter;
 	guint active = 0;
 
 	g_return_if_fail(FB_IS_DATA(fata));
-	priv = fata->priv;
-	g_hash_table_iter_init(&iter, priv->imgs);
+	g_hash_table_iter_init(&iter, fata->imgs);
 
 	while (g_hash_table_iter_next(&iter, (gpointer *) &img, NULL)) {
 		if (fb_data_image_get_active(img)) {
@@ -595,7 +528,7 @@
 		return;
 	}
 
-	g_hash_table_iter_init(&iter, priv->imgs);
+	g_hash_table_iter_init(&iter, fata->imgs);
 
 	while (g_hash_table_iter_next(&iter, (gpointer *) &img, NULL)) {
 		SoupMessage *msg;
@@ -604,12 +537,12 @@
 			continue;
 		}
 
-		img->priv->active = TRUE;
+		img->active = TRUE;
 		url = fb_data_image_get_url(img);
 
 		msg = soup_message_new("GET", url);
 		// purple_http_request_set_max_len(req, FB_DATA_ICON_SIZE_MAX);
-		soup_session_queue_message(priv->cons, msg, fb_data_image_cb, img);
+		soup_session_queue_message(fata->cons, msg, fb_data_image_cb, img);
 
 		if (++active >= FB_DATA_ICON_MAX) {
 			break;
--- a/libpurple/protocols/facebook/thrift.c	Tue Sep 20 03:31:39 2022 -0500
+++ b/libpurple/protocols/facebook/thrift.c	Tue Sep 20 22:43:37 2022 -0500
@@ -23,35 +23,32 @@
 
 #include "thrift.h"
 
-typedef struct
-{
-	GByteArray *bytes;
-	gboolean internal;
-	guint offset;
-	guint pos;
-	guint lastbool;
-} FbThriftPrivate;
-
 /**
  * FbThrift:
  *
  * Represents a reader/writer for compact Thrift data.
  */
-struct _FbThrift
-{
+struct _FbThrift {
 	GObject parent;
-	FbThriftPrivate *priv;
+
+	GByteArray *bytes;
+	gboolean internal;
+	guint offset;
+	guint pos;
+	guint lastbool;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE(FbThrift, fb_thrift, G_TYPE_OBJECT);
+G_DEFINE_TYPE(FbThrift, fb_thrift, G_TYPE_OBJECT);
 
 static void
 fb_thrift_dispose(GObject *obj)
 {
-	FbThriftPrivate *priv = FB_THRIFT(obj)->priv;
+	FbThrift* thft = FB_THRIFT(obj);
 
-	if (priv->internal) {
-		g_byte_array_free(priv->bytes, TRUE);
+	if (thft->internal) {
+		g_byte_array_free(thft->bytes, TRUE);
+		thft->bytes = NULL;
+		thft->internal = FALSE;
 	}
 }
 
@@ -66,27 +63,22 @@
 static void
 fb_thrift_init(FbThrift *thft)
 {
-	FbThriftPrivate *priv = fb_thrift_get_instance_private(thft);
-
-	thft->priv = priv;
 }
 
 FbThrift *
 fb_thrift_new(GByteArray *bytes, guint offset)
 {
 	FbThrift *thft;
-	FbThriftPrivate *priv;
 
 	thft = g_object_new(FB_TYPE_THRIFT, NULL);
-	priv = thft->priv;
 
 	if (bytes != NULL) {
-		priv->bytes = bytes;
-		priv->offset = offset;
-		priv->pos = offset;
+		thft->bytes = bytes;
+		thft->offset = offset;
+		thft->pos = offset;
 	} else {
-		priv->bytes = g_byte_array_new();
-		priv->internal = TRUE;
+		thft->bytes = g_byte_array_new();
+		thft->internal = TRUE;
 	}
 
 	return thft;
@@ -95,73 +87,60 @@
 const GByteArray *
 fb_thrift_get_bytes(FbThrift *thft)
 {
-	FbThriftPrivate *priv;
+	g_return_val_if_fail(FB_IS_THRIFT(thft), NULL);
 
-	g_return_val_if_fail(FB_IS_THRIFT(thft), NULL);
-	priv = thft->priv;
-	return priv->bytes;
+	return thft->bytes;
 }
 
 guint
 fb_thrift_get_pos(FbThrift *thft)
 {
-	FbThriftPrivate *priv;
+	g_return_val_if_fail(FB_IS_THRIFT(thft), 0);
 
-	g_return_val_if_fail(FB_IS_THRIFT(thft), 0);
-	priv = thft->priv;
-	return priv->pos;
+	return thft->pos;
 }
 
 void
 fb_thrift_set_pos(FbThrift *thft, guint pos)
 {
-	FbThriftPrivate *priv;
+	g_return_if_fail(FB_IS_THRIFT(thft));
 
-	g_return_if_fail(FB_IS_THRIFT(thft));
-	priv = thft->priv;
-	priv->pos = pos;
+	thft->pos = pos;
 }
 
 void
 fb_thrift_reset(FbThrift *thft)
 {
-	FbThriftPrivate *priv;
+	g_return_if_fail(FB_IS_THRIFT(thft));
 
-	g_return_if_fail(FB_IS_THRIFT(thft));
-	priv = thft->priv;
-	priv->pos = priv->offset;
+	thft->pos = thft->offset;
 }
 
 gboolean
 fb_thrift_read(FbThrift *thft, gpointer data, guint size)
 {
-	FbThriftPrivate *priv;
+	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
 
-	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
-	priv = thft->priv;
-
-	if ((priv->pos + size) > priv->bytes->len) {
+	if ((thft->pos + size) > thft->bytes->len) {
 		return FALSE;
 	}
 
 	if ((data != NULL) && (size > 0)) {
-		memcpy(data, priv->bytes->data + priv->pos, size);
+		memcpy(data, thft->bytes->data + thft->pos, size);
 	}
 
-	priv->pos += size;
+	thft->pos += size;
 	return TRUE;
 }
 
 gboolean
 fb_thrift_read_bool(FbThrift *thft, gboolean *value)
 {
-	FbThriftPrivate *priv;
 	guint8 byte;
 
 	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
-	priv = thft->priv;
 
-	if ((priv->lastbool & 0x03) != 0x01) {
+	if ((thft->lastbool & 0x03) != 0x01) {
 		if (!fb_thrift_read_byte(thft, &byte)) {
 			return FALSE;
 		}
@@ -170,15 +149,15 @@
 			*value = (byte & 0x0F) == 0x01;
 		}
 
-		priv->lastbool = 0;
+		thft->lastbool = 0;
 		return TRUE;
 	}
 
 	if (value != NULL) {
-		*value = ((priv->lastbool & 0x04) >> 2) != 0;
+		*value = ((thft->lastbool & 0x04) >> 2) != 0;
 	}
 
-	priv->lastbool = 0;
+	thft->lastbool = 0;
 	return TRUE;
 }
 
@@ -344,14 +323,12 @@
 fb_thrift_read_field(FbThrift *thft, FbThriftType *type, gint16 *id,
 					 gint16 lastid)
 {
-	FbThriftPrivate *priv;
 	gint16 i16;
 	guint8 byte;
 
 	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
 	g_return_val_if_fail(type != NULL, FALSE);
 	g_return_val_if_fail(id != NULL, FALSE);
-	priv = thft->priv;
 
 	if (!fb_thrift_read_byte(thft, &byte)) {
 		return FALSE;
@@ -374,10 +351,10 @@
 	}
 
 	if (*type == FB_THRIFT_TYPE_BOOL) {
-		priv->lastbool = 0x01;
+		thft->lastbool = 0x01;
 
 		if ((byte & 0x0F) == 0x01) {
-			priv->lastbool |= 0x01 << 2;
+			thft->lastbool |= 0x01 << 2;
 		}
 	}
 
@@ -396,17 +373,15 @@
 gboolean
 fb_thrift_read_isstop(FbThrift *thft)
 {
-	FbThriftPrivate *priv;
 	guint8 byte;
 
 	g_return_val_if_fail(FB_IS_THRIFT(thft), FALSE);
-	priv = thft->priv;
 
 	if (!fb_thrift_read_byte(thft, &byte)) {
 		return FALSE;
 	}
 
-	priv->pos--;
+	thft->pos--;
 	return byte == FB_THRIFT_TYPE_STOP;
 }
 
@@ -477,35 +452,30 @@
 void
 fb_thrift_write(FbThrift *thft, gconstpointer data, guint size)
 {
-	FbThriftPrivate *priv;
+	g_return_if_fail(FB_IS_THRIFT(thft));
 
-	g_return_if_fail(FB_IS_THRIFT(thft));
-	priv = thft->priv;
-
-	g_byte_array_append(priv->bytes, data, size);
-	priv->pos += size;
+	g_byte_array_append(thft->bytes, data, size);
+	thft->pos += size;
 }
 
 void
 fb_thrift_write_bool(FbThrift *thft, gboolean value)
 {
-	FbThriftPrivate *priv;
 	guint pos;
 
 	g_return_if_fail(FB_IS_THRIFT(thft));
-	priv = thft->priv;
 
-	if ((priv->lastbool & 0x03) != 0x02) {
+	if ((thft->lastbool & 0x03) != 0x02) {
 		fb_thrift_write_byte(thft, value ? 0x01 : 0x02);
 		return;
 	}
 
-	pos = priv->lastbool >> 3;
-	priv->lastbool = 0;
+	pos = thft->lastbool >> 3;
+	thft->lastbool = 0;
 
-	if ((pos >= priv->offset) && (pos < priv->bytes->len)) {
-		priv->bytes->data[pos] &= ~0x0F;
-		priv->bytes->data[pos] |= value ? 0x01 : 0x02;
+	if ((pos >= thft->offset) && (pos < thft->bytes->len)) {
+		thft->bytes->data[pos] &= ~0x0F;
+		thft->bytes->data[pos] |= value ? 0x01 : 0x02;
 	}
 }
 
@@ -594,14 +564,12 @@
 fb_thrift_write_field(FbThrift *thft, FbThriftType type, gint16 id,
 					  gint16 lastid)
 {
-	FbThriftPrivate *priv;
 	gint16 diff;
 
 	g_return_if_fail(FB_IS_THRIFT(thft));
-	priv = thft->priv;
 
 	if (type == FB_THRIFT_TYPE_BOOL) {
-		priv->lastbool = (priv->pos << 3) | 0x02;
+		thft->lastbool = (thft->pos << 3) | 0x02;
 	}
 
 	type = fb_thrift_t2ct(type);

mercurial