Skip to content

Commit 1cf102f

Browse files
committed
Refactor: libcrmcommon: New mark_attr_created()
Use with pcmk__xe_foreach_attr(). Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent a5b074b commit 1cf102f

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

lib/common/xml.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,26 @@ pcmk__xml_escape(const char *text, enum pcmk__xml_escape_type type)
12411241
return g_string_free(copy, FALSE);
12421242
}
12431243

1244+
/*!
1245+
* \internal
1246+
* \brief Set the \c pcmk__xf_created flag on an attribute
1247+
*
1248+
* \param[in,out] attr XML attribute
1249+
* \param[in] user_data Ignored
1250+
*
1251+
* \return \c true (to continue iterating)
1252+
*
1253+
* \note This is compatible with \c pcmk__xe_foreach_attr().
1254+
*/
1255+
static bool
1256+
mark_attr_created(xmlAttr *attr, void *user_data)
1257+
{
1258+
xml_node_private_t *nodepriv = attr->_private;
1259+
1260+
pcmk__set_xml_flags(nodepriv, pcmk__xf_created);
1261+
return true;
1262+
}
1263+
12441264
/*!
12451265
* \internal
12461266
* \brief Add an XML attribute to a node, marked as deleted
@@ -1455,12 +1475,7 @@ static void
14551475
xml_diff_attrs(xmlNode *old_xml, xmlNode *new_xml)
14561476
{
14571477
// Cleared later if attributes are not really new
1458-
for (xmlAttr *attr = pcmk__xe_first_attr(new_xml); attr != NULL;
1459-
attr = attr->next) {
1460-
xml_node_private_t *nodepriv = attr->_private;
1461-
1462-
pcmk__set_xml_flags(nodepriv, pcmk__xf_created);
1463-
}
1478+
pcmk__xe_foreach_attr(new_xml, mark_attr_created, NULL);
14641479

14651480
pcmk__xe_foreach_attr(old_xml, mark_attr_diff, new_xml);
14661481
pcmk__xe_foreach_attr(new_xml, check_new_attr_acls, NULL);

0 commit comments

Comments
 (0)