Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
925d17f
Refactor: libcrmcommon: pcmk__xe_copy_attrs pcmk__xe_foreach_const_attr
nrwahl2 Dec 27, 2025
68598bc
Refactor: libcrmcommon: Use foreach functions in pcmk__xe_sort_attrs()
nrwahl2 Dec 27, 2025
21f9c7e
Refactor: libcrmcommon: pcmk__xe_foreach_attr for matching attr removal
nrwahl2 Dec 27, 2025
e83a0c3
Refactor: libcrmcommon: delete matching xe pcmk__xe_foreach_const_attr
nrwahl2 Dec 27, 2025
125c2b6
Refactor: libpe_status: get_meta_attributes pcmk__xe_foreach_const_attr
nrwahl2 Dec 27, 2025
31b392b
Refactor: libcrmcommon: pcmk__xe_foreach_const_attr() in xml2list()
nrwahl2 Dec 27, 2025
2bcf90c
Refactor: libcrmcommon: Drop check in add_xml_changes_to_patchset()
nrwahl2 Dec 27, 2025
19a5928
Refactor: libcrmcommon: Drop xpath check in add_xml_changes_to_patchset
nrwahl2 Dec 27, 2025
c2d7856
Refactor: libcrmcommon: Clarify pointers in add_xml_changes_to_patchset
nrwahl2 Dec 27, 2025
a1f472f
Refactor: libcrmcommon: Use foreach for adding attr changes to patchset
nrwahl2 Dec 27, 2025
f28ae6d
Refactor: libcrmcommon: Drop cIter in add_xml_changes_to_patchset()
nrwahl2 Dec 27, 2025
866c728
Refactor: libcrmcommon: Functionize adding modify change to patchset
nrwahl2 Dec 27, 2025
198f778
Refactor: libcrmcommon: Functionize adding create change to patchset
nrwahl2 Dec 27, 2025
65123b8
Refactor: libcrmcommon: Functionize adding move change to patchset
nrwahl2 Dec 27, 2025
80d7d7b
Refactor: libcrmcommon: Add modify change only if xml is dirty
nrwahl2 Dec 27, 2025
bff088a
Refactor: libcrmcommon: Functionize adding delete change to patchset
nrwahl2 Dec 27, 2025
21060bd
Refactor: libcrmcommon: Minor xml_create_patchset_v2() improvements
nrwahl2 Dec 27, 2025
6450f51
Refactor: libcrmcommon: Functionize setting version fields in patchset
nrwahl2 Dec 27, 2025
01956f7
Refactor: libcrmcommon: pcmk__xe_copy_attrs() in apply_v2_patchset()
nrwahl2 Dec 27, 2025
d2a49b9
Refactor: libcrmcommon: implicitly_allowed() pcmk__xe_foreach_const_attr
nrwahl2 Dec 27, 2025
daf53b0
Refactor: libcrmcommon: Clarify pcmk__xml_attr_value()
nrwahl2 Dec 27, 2025
260f8dc
Refactor: libcrmcommon: Simplify/clarify pcmk__dump_xml_attr()
nrwahl2 Dec 27, 2025
7259f36
Refactor: libcrmcommon: pcmk__xe_foreach_const_attr in dump_xml_element
nrwahl2 Dec 27, 2025
8faf718
Low: libcrmcommon: Drop "<null>" fallback in show_xml_element()
nrwahl2 Dec 28, 2025
182f64e
Refactor: libcrmcommon: Display attributes with NULL private data
nrwahl2 Jun 13, 2026
342984f
Refactor: libcrmcommon: Call pcmk__dump_xml_attr() in show_xml_element()
nrwahl2 Dec 28, 2025
86cf138
Refactor: libcrmcommon: Drop a couple checks from show_xml_element()
nrwahl2 Dec 28, 2025
f851a84
Refactor: libcrmcommon: pcmk__xe_foreach_const_attr in show_xml_element
nrwahl2 Dec 28, 2025
7e669e6
Refactor: libcrmcommon: Functionize checking whether attribute is hidden
nrwahl2 Dec 28, 2025
c6a526a
Refactor: libcrmcommon: Rename show_xml_changes_recursive argument
nrwahl2 Dec 28, 2025
a5bd47c
Refactor: libcrmcommon: foreach_const_attr in show_xml_changes_recursive
nrwahl2 Dec 28, 2025
0f1c8ad
Refactor: libcrmcommon: foreach const attr in pcmk__xe_sort_attrs test
nrwahl2 Dec 28, 2025
1a3f6d1
Refactor: libpe_status: foreach_const_attr in pcmk__unpack_action_meta
nrwahl2 Dec 29, 2025
9272bde
Refactor: libcrmcommon: foreach_const_attr() in unpack_ticket_state()
nrwahl2 Dec 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/crm/common/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <crm/common/servers_internal.h>
#include <crm/common/tls_internal.h>
#include <crm/common/utils_internal.h>
// xml_attr_internal.h intentionally left out
// xml_comment_internal.h intentionally left out
// xml_element_internal.h intentionally left out
// xml_idref_internal.h intentionally left out
Expand Down
37 changes: 37 additions & 0 deletions include/crm/common/xml_attr_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2025-2026 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

Comment thread
nrwahl2 marked this conversation as resolved.
#ifndef PCMK__INCLUDED_CRM_COMMON_INTERNAL_H
#error "Include <crm/common/internal.h> instead of <xml_attr_internal.h> " \
"directly"
#endif

#ifndef PCMK__CRM_COMMON_XML_ATTR_INTERNAL__H
#define PCMK__CRM_COMMON_XML_ATTR_INTERNAL__H

/*
* Internal-only wrappers for and extensions to libxml2 for processing XML
* attributes
*/

#include <stdbool.h> // bool

#include <libxml/tree.h> // xmlAttr

#ifdef __cplusplus
extern "C" {
#endif

bool pcmk__xa_insert_dup(const xmlAttr *attr, void *user_data);

#ifdef __cplusplus
}
#endif

#endif // PCMK__XML_ATTR_INTERNAL__H
2 changes: 1 addition & 1 deletion include/crm/common/xml_element_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ xmlNode *pcmk__xe_first_child(const xmlNode *parent, const char *node_name,
void pcmk__xe_remove_attr(xmlNode *element, const char *name);
bool pcmk__xe_remove_attr_cb(xmlNode *xml, void *user_data);
void pcmk__xe_remove_matching_attrs(xmlNode *element, bool force,
bool (*match)(xmlAttrPtr, void *),
bool (*match)(xmlAttr *, void *),
void *user_data);
int pcmk__xe_delete_match(xmlNode *xml, xmlNode *search);
int pcmk__xe_replace_match(xmlNode *xml, xmlNode *replace);
Expand Down
17 changes: 15 additions & 2 deletions include/crm/common/xml_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <crm/common/xml_names.h> // PCMK_XA_ID, PCMK_XE_CLONE

// This file is a wrapper for other {xml_*,xpath}_internal.h headers
#include <crm/common/xml_attr_internal.h>
#include <crm/common/xml_comment_internal.h>
#include <crm/common/xml_element_internal.h>
#include <crm/common/xml_idref_internal.h>
Expand Down Expand Up @@ -432,11 +433,23 @@ void pcmk__xml_mark_changes(xmlNode *old_xml, xmlNode *new_xml);
bool pcmk__xml_tree_foreach(xmlNode *xml, bool (*fn)(xmlNode *, void *),
void *user_data);

/*!
* \internal
* \brief Get an XML attribute's value
*
* \param[in] attr XML attribute
*
* \return Value of \p attr, or \c NULL if \p attr is \c NULL or its value is
* unset
*/
static inline const char *
pcmk__xml_attr_value(const xmlAttr *attr)
{
return ((attr == NULL) || (attr->children == NULL))? NULL
: (const char *) attr->children->content;
if ((attr == NULL) || (attr->children == NULL)) {
return NULL;
}

return (const char *) attr->children->content;
}

void pcmk__xml_patchset_add_digest(xmlNode *patchset, const xmlNode *target);
Expand Down
30 changes: 22 additions & 8 deletions lib/common/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,24 @@ is_mode_allowed(uint32_t flags, enum pcmk__xml_flags mode)
}
}

/*!
* \internal
* \brief Check whether an XML attribute's name is \c PCMK_XA_ID
*
* \param[in] attr Attribute to check
* \param[in] user_data Ignored
*
* \return \c true if the attribute's name is \c PCMK_XA_ID, or \c false
* otherwise
*
* \note This is compatible with \c pcmk__xe_foreach_const_attr().
*/
static bool
attr_is_id(const xmlAttr *attr, void *user_data)
{
return pcmk__str_eq((const char *) attr->name, PCMK_XA_ID, pcmk__str_none);
}

/*!
* \internal
* \brief Check whether an XML attribute's name is not \c PCMK_XA_ID
Expand All @@ -803,7 +821,7 @@ is_mode_allowed(uint32_t flags, enum pcmk__xml_flags mode)
static bool
attr_is_not_id(xmlAttr *attr, void *user_data)
{
return !pcmk__str_eq((const char *) attr->name, PCMK_XA_ID, pcmk__str_none);
return !attr_is_id(attr, user_data);
}

/*!
Expand Down Expand Up @@ -952,14 +970,10 @@ xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml,
* \return \c true if XML element is implicitly allowed, or \c false otherwise
*/
static bool
implicitly_allowed(xmlNode *xml)
implicitly_allowed(const xmlNode *xml)
{
for (xmlAttr *attr = pcmk__xe_first_attr(xml); attr != NULL;
attr = attr->next) {

if (attr_is_not_id(attr, NULL)) {
return false;
}
if (!pcmk__xe_foreach_const_attr(xml, attr_is_id, NULL)) {
return false;
}

/* Creation is not implicitly allowed for a descendant of PCMK_XE_ACLS, but
Expand Down
2 changes: 1 addition & 1 deletion lib/common/crmcommon_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ G_GNUC_INTERNAL
bool pcmk__marked_as_deleted(xmlAttrPtr a, void *user_data);

G_GNUC_INTERNAL
void pcmk__dump_xml_attr(const xmlAttr *attr, GString *buffer);
bool pcmk__dump_xml_attr(const xmlAttr *attr, void *user_data);

G_GNUC_INTERNAL
int pcmk__xe_set_score(xmlNode *target, const char *name, const char *value);
Expand Down
12 changes: 1 addition & 11 deletions lib/common/nvpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ GHashTable *
xml2list(const xmlNode *parent)
{
xmlNode *child = NULL;
xmlAttrPtr pIter = NULL;
xmlNode *nvpair_list = NULL;
GHashTable *nvpair_hash = pcmk__strkey_table(free, free);

Expand All @@ -354,16 +353,7 @@ xml2list(const xmlNode *parent)

pcmk__log_xml_trace(nvpair_list, "Unpacking");

for (pIter = pcmk__xe_first_attr(nvpair_list); pIter != NULL;
pIter = pIter->next) {

const char *p_name = (const char *)pIter->name;
const char *p_value = pcmk__xml_attr_value(pIter);

pcmk__trace("Added %s=%s", p_name, p_value);

pcmk__insert_dup(nvpair_hash, p_name, p_value);
}
pcmk__xe_foreach_const_attr(nvpair_list, pcmk__xa_insert_dup, nvpair_hash);

for (child = pcmk__xe_first_child(nvpair_list, PCMK__XE_PARAM, NULL, NULL);
child != NULL; child = pcmk__xe_next(child, PCMK__XE_PARAM)) {
Expand Down
Loading