--- a/libpurple/account.c Sat Nov 16 13:37:56 2019 +0300
+++ b/libpurple/account.c Tue Nov 26 23:59:35 2019 +0300
@@ -1792,19 +1792,19 @@
purple_account_set_status(PurpleAccount *account, const char *status_id,
- attrs = purple_attr_list_from_vargs(args);
+ attrs = purple_attrs_from_vargs(args); purple_account_set_status_list(account, status_id, active, attrs);
- g_list_free_full(attrs, g_free);
+ g_hash_table_destroy(attrs); purple_account_set_status_list(PurpleAccount *account, const char *status_id,
- gboolean active, GList *attrs)
+ gboolean active, GHashTable *attrs) --- a/libpurple/account.h Sat Nov 16 13:37:56 2019 +0300
+++ b/libpurple/account.h Tue Nov 26 23:59:35 2019 +0300
@@ -440,8 +440,9 @@
* @status_id: The ID of the status.
* @active: Whether @a status_id is to be activated (%TRUE) or
- * @attrs: (element-type utf8): A list of <type>const char *</type> attribute names followed by
- * <type>const char *</type> attribute values for the status.
+ * @attrs: (element-type utf8 gpointer): A hash table of + * <type>const char *</type> attribute names followed by + * <type>gpointer</type> attribute values for the status. * (For example, one pair might be <literal>"message"</literal>
* followed by <literal>"hello, talk to me!"</literal>.)
@@ -453,7 +454,7 @@
* FALSE, this function does nothing.
void purple_account_set_status_list(PurpleAccount *account,
- const char *status_id, gboolean active, GList *attrs);
+ const char *status_id, gboolean active, GHashTable *attrs); * purple_account_set_public_alias:
--- a/libpurple/accounts.c Sat Nov 16 13:37:56 2019 +0300
+++ b/libpurple/accounts.c Tue Nov 26 23:59:35 2019 +0300
@@ -200,17 +200,16 @@
migrate_xmpp_encryption(account);
parse_status_attrs(PurpleXmlNode *node, PurpleStatus *status)
+ GHashTable *attrs = g_hash_table_new(g_str_hash, g_str_equal); for (child = purple_xmlnode_get_child(node, "attribute"); child != NULL;
child = purple_xmlnode_get_next_twin(child))
- PurpleAttr *attr = NULL;
const char *id = purple_xmlnode_get_attrib(child, "id");
const char *value = purple_xmlnode_get_attrib(child, "value");
@@ -224,26 +223,23 @@
switch (G_VALUE_TYPE(attr_value))
- attr = purple_attr_new(id, (char *)value);
+ g_hash_table_insert(attrs, id, (char *)value); - if (sscanf(value, "%d", &v) == 1)
- attr = purple_attr_new(id, GINT_TO_POINTER(v));
+ if (sscanf(value, "%d", &v) == 1) { + g_hash_table_insert(attrs, id, GINT_TO_POINTER(v));
- list = g_list_append(list, attr);
@@ -253,7 +249,7 @@
+ GHashTable *attrs = NULL; /* Get the active/inactive state */
data = purple_xmlnode_get_attrib(node, "active");
@@ -281,7 +277,7 @@
purple_account_set_status_list(account, type, active, attrs);
- g_list_free_full(attrs, g_free);
+ g_hash_table_destroy(attrs); --- a/libpurple/status.c Sat Nov 16 13:37:56 2019 +0300
+++ b/libpurple/status.c Tue Nov 26 23:59:35 2019 +0300
@@ -714,23 +714,27 @@
purple_status_set_active_with_attrs(PurpleStatus *status, gboolean active, va_list args)
- GList *attrs = purple_attr_list_from_vargs(args);
+ GHashTable *attrs = purple_attrs_from_vargs(args); purple_status_set_active_with_attrs_list(status, active, attrs);
- g_list_free_full(attrs, g_free);
+ g_hash_table_destroy(attrs); purple_status_set_active_with_attrs_list(PurpleStatus *status, gboolean active,
PurpleStatusPrivate *priv = NULL;
gboolean changed = FALSE;
GList *specified_attr_ids = NULL;
PurpleStatusType *status_type;
g_return_if_fail(PURPLE_IS_STATUS(status));
+ g_return_if_fail(attrs != NULL); priv = purple_status_get_instance_private(status);
@@ -750,44 +754,43 @@
- for (l = attrs; l != NULL; l = l->next)
- PurpleAttr *attr = l->data;
+ g_hash_table_iter_init(&iter, attrs); + while (g_hash_table_iter_next(&iter, (gpointer *)&id, (gpointer *)&data)) { - value = purple_status_get_attr_value(status, attr->id);
+ value = purple_status_get_attr_value(status, id); purple_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is "
- "not supported.\n", attr->id, priv->status_type->name);
+ "not supported.\n", id, priv->status_type->name); /* Skip over the data and move on to the next attribute */
- specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)attr->id);
+ specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)id); if (G_VALUE_TYPE(value) == G_TYPE_STRING)
- const gchar *string_data = attr->data;
+ const gchar *string_data = data; if (purple_strequal(string_data, g_value_get_string(value)))
- status_set_attr_string(status, attr->id, string_data);
+ status_set_attr_string(status, id, string_data); else if (G_VALUE_TYPE(value) == G_TYPE_INT)
- int int_data = GPOINTER_TO_INT(attr->data);
+ int int_data = GPOINTER_TO_INT(data); if (int_data == g_value_get_int(value))
- status_set_attr_int(status, attr->id, int_data);
+ status_set_attr_int(status, id, int_data); else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN)
- gboolean boolean_data = GPOINTER_TO_INT(attr->data);
+ gboolean boolean_data = GPOINTER_TO_INT(data); if (boolean_data == g_value_get_boolean(value))
- status_set_attr_boolean(status, attr->id, boolean_data);
+ status_set_attr_boolean(status, id, boolean_data); @@ -1351,32 +1354,19 @@
/**************************************************************************/
-/* PurpleAttr helpers */
/**************************************************************************/
-purple_attr_new(const char *id, gpointer data)
+purple_attrs_from_vargs(va_list args)
- attr = g_new0(PurpleAttr, 1);
+ GHashTable *attrs = g_hash_table_new(g_str_hash, g_str_equal);
-purple_attr_list_from_vargs(va_list args)
- while ((id = va_arg(args, const char *)) != NULL)
+ while ((id = va_arg(args, gchar *)) != NULL) gpointer data = va_arg(args, gpointer);
- PurpleAttr *attr = purple_attr_new(id, data);
- attrs = g_list_append(attrs, attr);
+ g_hash_table_insert(attrs, id, data); --- a/libpurple/status.h Sat Nov 16 13:37:56 2019 +0300
+++ b/libpurple/status.h Tue Nov 26 23:59:35 2019 +0300
@@ -96,21 +96,6 @@
PURPLE_STATUS_NUM_PRIMITIVES, /*< skip >*/
- * @id: The attribute id
- * @data: The attribute data
- * Similar to PurpleKeyValuePair except it doesn't allocate memory for @id and @data.
-typedef struct _PurpleAttr
#define PURPLE_TUNE_ARTIST "tune_artist"
@@ -510,17 +495,16 @@
* purple_status_set_active_with_attrs_list:
* @active: The active state.
- * @attrs: (element-type PurpleAttr): A list of attributes to set on the status. This list is
- * composed of key/value pairs, where each key is a valid
- * attribute name for this PurpleStatusType. The list is
- * not modified or freed by this function.
+ * @attrs: (element-type utf8 gpointer): A hash table of attributes to set on the status. + * This hash table's keys are valid attribute names for this PurpleStatusType. + * The hash table is not modified or freed by this function. * Sets whether or not a status is active.
* This should only be called by the account, conversation, and buddy APIs.
void purple_status_set_active_with_attrs_list(PurpleStatus *status, gboolean active,
* purple_status_get_status_type:
@@ -716,36 +700,23 @@
void purple_statuses_uninit(void);
/**************************************************************************/
-/* PurpleAttr helpers */
/**************************************************************************/
- * @id: The name part of PurpleAttr
- * @data: The value part of PurpleAttr
- * Creates a new PurpleAttr.
- * Returns: The created PurpleAttr
-PurpleAttr *purple_attr_new(const char *id, gpointer data);
- * purple_attr_list_from_vargs:
+ * purple_attrs_from_vargs: * @args: A list of attributes to parse. This list is
* composed of key/value pairs, where each key is a valid
* attribute name for this PurpleStatusType. The list should
- * Returns a list of attributes constructed from args.
+ * Returns a hash table of attributes constructed from args. - * Returns: (element-type PurpleAttr) (transfer full): The list of attributes.
+ * Returns: (element-type utf8 gpointer) (transfer container): The hash table of attributes. -GList *purple_attr_list_from_vargs(va_list args);
+GHashTable *purple_attrs_from_vargs(va_list args);