This source file includes following definitions.
- pcmk__xa_remove
- pcmk__mark_xml_attr_dirty
- pcmk__marked_as_deleted
- pcmk__dump_xml_attr
1
2
3
4
5
6
7
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>
24
25 #include <crm/crm.h>
26 #include <crm/common/xml.h>
27 #include <crm/common/xml_internal.h>
28 #include "crmcommon_private.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 int
45 pcmk__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
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)
63 && pcmk__xml_doc_all_flags_set(element->doc, pcmk__xf_tracking)) {
64
65
66 pcmk__xml_set_parent_flags(element, pcmk__xf_dirty);
67 pcmk__set_xml_flags((xml_node_private_t *) attr->_private,
68 pcmk__xf_deleted);
69 } else {
70 pcmk__xml_free_private_data((xmlNode *) attr);
71 xmlRemoveProp(attr);
72 }
73 return pcmk_rc_ok;
74 }
75
76 void
77 pcmk__mark_xml_attr_dirty(xmlAttr *a)
78 {
79 xmlNode *parent = a->parent;
80 xml_node_private_t *nodepriv = a->_private;
81
82 pcmk__set_xml_flags(nodepriv, pcmk__xf_dirty|pcmk__xf_modified);
83 pcmk__clear_xml_flags(nodepriv, pcmk__xf_deleted);
84 pcmk__mark_xml_node_dirty(parent);
85 }
86
87
88 bool
89 pcmk__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
100
101
102
103
104
105
106
107 void
108 pcmk__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
128
129
130
131 return;
132 }
133
134 if (pcmk__xml_needs_escape(value, pcmk__xml_escape_attr)) {
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 }