--- a/libpurple/account.c Sat Nov 16 13:36:56 2019 +0300
+++ b/libpurple/account.c Sat Nov 16 13:37:56 2019 +0300
@@ -1793,19 +1793,12 @@
- while ((id = va_arg(args, const char *)) != NULL)
- attrs = g_list_append(attrs, (char *)id);
- data = va_arg(args, void *);
- attrs = g_list_append(attrs, data);
+ attrs = purple_attr_list_from_vargs(args); purple_account_set_status_list(account, status_id, active, attrs);
+ g_list_free_full(attrs, g_free); --- a/libpurple/accounts.c Sat Nov 16 13:36:56 2019 +0300
+++ b/libpurple/accounts.c Sat Nov 16 13:37:56 2019 +0300
@@ -210,6 +210,7 @@
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");
@@ -220,26 +221,26 @@
- list = g_list_append(list, (char *)id);
switch (G_VALUE_TYPE(attr_value))
- list = g_list_append(list, (char *)value);
+ attr = purple_attr_new(id, (char *)value); if (sscanf(value, "%d", &v) == 1)
- list = g_list_append(list, GINT_TO_POINTER(v));
- list = g_list_remove(list, id);
+ attr = purple_attr_new(id, GINT_TO_POINTER(v)); + list = g_list_append(list, attr); @@ -280,7 +281,7 @@
purple_account_set_status_list(account, type, active, attrs);
+ g_list_free_full(attrs, g_free); --- a/libpurple/status.c Sat Nov 16 13:36:56 2019 +0300
+++ b/libpurple/status.c Sat Nov 16 13:37:56 2019 +0300
@@ -714,18 +714,10 @@
purple_status_set_active_with_attrs(PurpleStatus *status, gboolean active, va_list args)
+ GList *attrs = purple_attr_list_from_vargs(args); - while ((id = va_arg(args, const char *)) != NULL)
- attrs = g_list_append(attrs, (char *)id);
- data = va_arg(args, void *);
- attrs = g_list_append(attrs, data);
purple_status_set_active_with_attrs_list(status, active, attrs);
+ g_list_free_full(attrs, g_free); @@ -758,58 +750,46 @@
+ for (l = attrs; l != NULL; l = l->next)
+ PurpleAttr *attr = l->data;
- value = purple_status_get_attr_value(status, id);
+ value = purple_status_get_attr_value(status, attr->id); purple_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is "
- "not supported.\n", id, priv->status_type->name);
+ "not supported.\n", attr->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)id);
+ specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)attr->id); if (G_VALUE_TYPE(value) == G_TYPE_STRING)
- const gchar *string_data = l->data;
+ const gchar *string_data = attr->data; if (purple_strequal(string_data, g_value_get_string(value)))
- status_set_attr_string(status, id, string_data);
+ status_set_attr_string(status, attr->id, string_data); else if (G_VALUE_TYPE(value) == G_TYPE_INT)
- int int_data = GPOINTER_TO_INT(l->data);
+ int int_data = GPOINTER_TO_INT(attr->data); if (int_data == g_value_get_int(value))
- status_set_attr_int(status, id, int_data);
+ status_set_attr_int(status, attr->id, int_data); else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN)
- gboolean boolean_data = GPOINTER_TO_INT(l->data);
+ gboolean boolean_data = GPOINTER_TO_INT(attr->data); if (boolean_data == g_value_get_boolean(value))
- status_set_attr_boolean(status, id, boolean_data);
+ status_set_attr_boolean(status, attr->id, boolean_data);
- /* We don't know what the data is--skip over it */
/* Reset any unspecified attributes to their default value */
@@ -1369,3 +1349,35 @@
purple_prefs_disconnect_by_handle(purple_prefs_get_handle());
+/**************************************************************************/ +/* PurpleAttr helpers */ +/**************************************************************************/ +purple_attr_new(const char *id, gpointer data) + attr = g_new0(PurpleAttr, 1); +purple_attr_list_from_vargs(va_list args) + while ((id = va_arg(args, const char *)) != NULL) + gpointer data = va_arg(args, gpointer); + PurpleAttr *attr = purple_attr_new(id, data); + attrs = g_list_append(attrs, attr); --- a/libpurple/status.h Sat Nov 16 13:36:56 2019 +0300
+++ b/libpurple/status.h Sat Nov 16 13:37:56 2019 +0300
@@ -96,6 +96,21 @@
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"
@@ -495,7 +510,7 @@
* purple_status_set_active_with_attrs_list:
* @active: The active state.
- * @attrs: (element-type void): A list of attributes to set on the status. This list is
+ * @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.
@@ -700,6 +715,38 @@
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: + * @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: (element-type PurpleAttr) (transfer full): The list of attributes. +GList *purple_attr_list_from_vargs(va_list args); #endif /* PURPLE_STATUS_H */