diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:46:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:46:09 +0000 |
commit | 043aa641ad4373e96fd748deb1e7fab3cb579a07 (patch) | |
tree | f8fde8a97ab5db152043f6c01043672114c0a4df /lib/common/xml_attr.c | |
parent | Releasing progress-linux version 2.1.6-5~progress7.99u1. (diff) | |
download | pacemaker-043aa641ad4373e96fd748deb1e7fab3cb579a07.tar.xz pacemaker-043aa641ad4373e96fd748deb1e7fab3cb579a07.zip |
Merging upstream version 2.1.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/common/xml_attr.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/common/xml_attr.c b/lib/common/xml_attr.c new file mode 100644 index 0000000..427d267 --- /dev/null +++ b/lib/common/xml_attr.c @@ -0,0 +1,84 @@ +/* + * Copyright 2004-2023 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. + */ + +#include <crm_internal.h> + +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <time.h> +#include <string.h> +#include <stdlib.h> +#include <stdarg.h> +#include <bzlib.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xmlIO.h> /* xmlAllocOutputBuffer */ + +#include <crm/crm.h> +#include <crm/msg_xml.h> +#include <crm/common/xml.h> +#include <crm/common/xml_internal.h> // PCMK__XML_LOG_BASE, etc. +#include "crmcommon_private.h" + +void +pcmk__mark_xml_attr_dirty(xmlAttr *a) +{ + xmlNode *parent = a->parent; + xml_node_private_t *nodepriv = a->_private; + + pcmk__set_xml_flags(nodepriv, pcmk__xf_dirty|pcmk__xf_modified); + pcmk__clear_xml_flags(nodepriv, pcmk__xf_deleted); + pcmk__mark_xml_node_dirty(parent); +} + +// This also clears attribute's flags if not marked as deleted +bool +pcmk__marked_as_deleted(xmlAttrPtr a, void *user_data) +{ + xml_node_private_t *nodepriv = a->_private; + + if (pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) { + return true; + } + nodepriv->flags = pcmk__xf_none; + return false; +} + +/*! + * \internal + * \brief Append an XML attribute to a buffer + * + * \param[in] attr Attribute to append + * \param[in,out] buffer Where to append the content (must not be \p NULL) + */ +void +pcmk__dump_xml_attr(const xmlAttr *attr, GString *buffer) +{ + char *p_value = NULL; + const char *p_name = NULL; + xml_node_private_t *nodepriv = NULL; + + if (attr == NULL || attr->children == NULL) { + return; + } + + nodepriv = attr->_private; + if (nodepriv && pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) { + return; + } + + p_name = (const char *) attr->name; + p_value = crm_xml_escape((const char *)attr->children->content); + pcmk__g_strcat(buffer, " ", p_name, "=\"", pcmk__s(p_value, "<null>"), "\"", + NULL); + + free(p_value); +}
\ No newline at end of file |