pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
xml_attr.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2025 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdio.h>
13#include <sys/types.h>
14#include <unistd.h>
15#include <time.h>
16#include <string.h>
17#include <stdlib.h>
18#include <stdarg.h>
19#include <bzlib.h>
20
21#include <libxml/parser.h>
22#include <libxml/tree.h>
23#include <libxml/xmlIO.h> /* xmlAllocOutputBuffer */
24
25#include <crm/crm.h>
26#include <crm/common/xml.h>
27#include <crm/common/xml_internal.h> // PCMK__XML_LOG_BASE, etc.
28#include "crmcommon_private.h"
29
44int
45pcmk__xa_remove(xmlAttr *attr, bool force)
46{
47 xmlNode *element = NULL;
48
49 if ((attr == NULL) || (attr->parent == NULL)) {
50 return pcmk_rc_ok;
51 }
52
53 element = attr->parent;
54
55 if (!force && !pcmk__check_acl(element, NULL, pcmk__xf_acl_write)) {
56 // ACLs apply to element, not to particular attributes
57 crm_trace("ACLs prevent removal of attributes from %s element",
58 (const char *) element->name);
59 return EPERM;
60 }
61
62 if (!force && (element != NULL)
64
65 // Leave in place (marked for removal) until after diff is calculated
67 pcmk__set_xml_flags((xml_node_private_t *) attr->_private,
69 } else {
70 pcmk__xml_free_private_data((xmlNode *) attr);
71 xmlRemoveProp(attr);
72 }
73 return pcmk_rc_ok;
74}
75
76void
78{
79 xmlNode *parent = a->parent;
80 xml_node_private_t *nodepriv = a->_private;
81
85}
86
87// This also clears attribute's flags if not marked as deleted
88bool
89pcmk__marked_as_deleted(xmlAttrPtr a, void *user_data)
90{
91 xml_node_private_t *nodepriv = a->_private;
92
93 if (pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) {
94 return true;
95 }
96 nodepriv->flags = pcmk__xf_none;
97 return false;
98}
99
107void
108pcmk__dump_xml_attr(const xmlAttr *attr, GString *buffer)
109{
110 const char *name = NULL;
111 const char *value = NULL;
112 gchar *value_esc = NULL;
113 xml_node_private_t *nodepriv = NULL;
114
115 if (attr == NULL || attr->children == NULL) {
116 return;
117 }
118
119 nodepriv = attr->_private;
120 if (nodepriv && pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) {
121 return;
122 }
123
124 name = (const char *) attr->name;
125 value = (const char *) attr->children->content;
126 if (value == NULL) {
127 /* Don't print anything for unset attribute. Any null-indicator value,
128 * including the empty string, could also be a real value that needs to
129 * be treated differently from "unset".
130 */
131 return;
132 }
133
135 value_esc = pcmk__xml_escape(value, pcmk__xml_escape_attr);
136 value = value_esc;
137 }
138
139 pcmk__g_strcat(buffer, " ", name, "=\"", value, "\"", NULL);
140 g_free(value_esc);
141}
bool pcmk__check_acl(xmlNode *xml, const char *attr_name, enum pcmk__xml_flags mode)
Definition acl.c:748
const char * parent
Definition cib.c:27
const char * name
Definition cib.c:26
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition util.h:80
A dumping ground.
#define pcmk__set_xml_flags(xml_priv, flags_to_set)
G_GNUC_INTERNAL void pcmk__xml_free_private_data(xmlNode *xml)
Definition xml.c:399
#define pcmk__clear_xml_flags(xml_priv, flags_to_clear)
G_GNUC_INTERNAL void pcmk__xml_set_parent_flags(xmlNode *xml, uint64_t flags)
Definition xml.c:109
G_GNUC_INTERNAL void G_GNUC_INTERNAL void pcmk__mark_xml_node_dirty(xmlNode *xml)
Definition xml.c:159
#define crm_trace(fmt, args...)
Definition logging.h:370
@ pcmk_rc_ok
Definition results.h:159
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
Definition strings.c:1299
uint32_t flags
Group of enum pcmk__xml_flags
Wrappers for and extensions to libxml2.
void pcmk__mark_xml_attr_dirty(xmlAttr *a)
Definition xml_attr.c:77
int pcmk__xa_remove(xmlAttr *attr, bool force)
Definition xml_attr.c:45
void pcmk__dump_xml_attr(const xmlAttr *attr, GString *buffer)
Definition xml_attr.c:108
bool pcmk__marked_as_deleted(xmlAttrPtr a, void *user_data)
Definition xml_attr.c:89
bool pcmk__xml_doc_all_flags_set(const xmlDoc *xml, uint32_t flags)
Definition xml.c:147
bool pcmk__xml_needs_escape(const char *text, enum pcmk__xml_escape_type type)
Definition xml.c:909
@ pcmk__xml_escape_attr
@ pcmk__xf_deleted
Node was deleted (set for attribute only)
@ pcmk__xf_dirty
@ pcmk__xf_modified
Node was modified.
@ pcmk__xf_acl_write
ACL write permission (implies read permission in most or all contexts)
@ pcmk__xf_tracking
Tracking is enabled (set for document only)
@ pcmk__xf_none
This flag has no effect.
char * pcmk__xml_escape(const char *text, enum pcmk__xml_escape_type type)
Definition xml.c:991