Skip to content

Commit 9272bde

Browse files
committed
Refactor: libcrmcommon: foreach_const_attr() in unpack_ticket_state()
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 1a3f6d1 commit 9272bde

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

lib/pengine/unpack.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,29 @@ unpack_tags(xmlNode *xml_tags, pcmk_scheduler_t *scheduler)
10041004
return TRUE;
10051005
}
10061006

1007+
/*!
1008+
* \internal
1009+
* \brief Add a non-ID attribute to a hash table of name-value pairs
1010+
*
1011+
* This is like \c pcmk__xa_insert_dup() but does nothing if the attribute's
1012+
* name is \c PCMK_XA_ID.
1013+
*
1014+
* \param[in] attr XML attribute
1015+
* \param[in,out] user_data Name-value pair table (<tt>GHashTable *</tt>)
1016+
*
1017+
* \return \c true (to continue iterating)
1018+
*
1019+
* \note This is compatible with \c pcmk__xe_foreach_const_attr().
1020+
*/
1021+
static bool
1022+
insert_dup_attr_if_not_id(const xmlAttr *attr, void *user_data)
1023+
{
1024+
if (!pcmk__str_eq((const char *) attr->name, PCMK_XA_ID, pcmk__str_none)) {
1025+
pcmk__xa_insert_dup(attr, user_data);
1026+
}
1027+
return true;
1028+
}
1029+
10071030
/*!
10081031
* \internal
10091032
* \brief Unpack a ticket state entry
@@ -1022,7 +1045,6 @@ unpack_ticket_state(xmlNode *xml_ticket, void *userdata)
10221045
const char *granted = NULL;
10231046
const char *last_granted = NULL;
10241047
const char *standby = NULL;
1025-
xmlAttrPtr xIter = NULL;
10261048

10271049
pcmk__ticket_t *ticket = NULL;
10281050

@@ -1042,15 +1064,8 @@ unpack_ticket_state(xmlNode *xml_ticket, void *userdata)
10421064
}
10431065
}
10441066

1045-
for (xIter = xml_ticket->properties; xIter; xIter = xIter->next) {
1046-
const char *prop_name = (const char *)xIter->name;
1047-
const char *prop_value = pcmk__xml_attr_value(xIter);
1048-
1049-
if (pcmk__str_eq(prop_name, PCMK_XA_ID, pcmk__str_none)) {
1050-
continue;
1051-
}
1052-
pcmk__insert_dup(ticket->state, prop_name, prop_value);
1053-
}
1067+
pcmk__xe_foreach_const_attr(xml_ticket, insert_dup_attr_if_not_id,
1068+
ticket->state);
10541069

10551070
granted = g_hash_table_lookup(ticket->state, PCMK__XA_GRANTED);
10561071
if (pcmk__is_true(granted)) {

0 commit comments

Comments
 (0)