pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
xml_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 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 #ifndef PCMK__CRM_COMMON_XML_COMPAT__H
11 #define PCMK__CRM_COMMON_XML_COMPAT__H
12 
13 #include <glib.h> // gboolean
14 #include <libxml/tree.h> // xmlNode
15 
16 #include <crm/common/nvpair.h> // crm_xml_add()
17 #include <crm/common/xml_names.h> // PCMK_XE_CLONE
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
32 #define XML_PARANOIA_CHECKS 0
34 
36 xmlDoc *getDocPtr(xmlNode *node);
37 
39 int add_node_nocopy(xmlNode * parent, const char *name, xmlNode * child);
40 
42 xmlNode *find_entity(xmlNode *parent, const char *node_name, const char *id);
43 
45 char *xml_get_path(const xmlNode *xml);
46 
48 void xml_log_changes(uint8_t level, const char *function, const xmlNode *xml);
49 
51 void xml_log_patchset(uint8_t level, const char *function, const xmlNode *xml);
52 
54 gboolean apply_xml_diff(xmlNode *old_xml, xmlNode *diff, xmlNode **new_xml);
55 
57 void crm_destroy_xml(gpointer data);
58 
60 gboolean xml_has_children(const xmlNode *root);
61 
63 static inline const char *
64 crm_xml_add_boolean(xmlNode *node, const char *name, gboolean value)
65 {
66  return crm_xml_add(node, name, (value? "true" : "false"));
67 }
68 
69 // NOTE: sbd (as of at least 1.5.2) uses this
71 static inline const char *
72 crm_element_name(const xmlNode *xml)
73 {
74  return (xml == NULL)? NULL : (const char *) xml->name;
75 }
76 
78 char *crm_xml_escape(const char *text);
79 
80 // NOTE: sbd (as of at least 1.5.2) uses this
82 xmlNode *copy_xml(xmlNode *src_node);
83 
85 xmlNode *add_node_copy(xmlNode *new_parent, xmlNode *xml_node);
86 
88 void purge_diff_markers(xmlNode *a_node);
89 
91 xmlNode *diff_xml_object(xmlNode *left, xmlNode *right, gboolean suppress);
92 
94 xmlNode *subtract_xml_object(xmlNode *parent, xmlNode *left, xmlNode *right,
95  gboolean full, gboolean *changed,
96  const char *marker);
97 
99 gboolean can_prune_leaf(xmlNode *xml_node);
100 
102 xmlNode *create_xml_node(xmlNode *parent, const char *name);
103 
105 xmlNode *pcmk_create_xml_text_node(xmlNode *parent, const char *name,
106  const char *content);
107 
109 xmlNode *pcmk_create_html_node(xmlNode *parent, const char *element_name,
110  const char *id, const char *class_name,
111  const char *text);
112 
114 xmlNode *first_named_child(const xmlNode *parent, const char *name);
115 
117 xmlNode *find_xml_node(const xmlNode *root, const char *search_path,
118  gboolean must_find);
119 
121 xmlNode *crm_next_same_xml(const xmlNode *sibling);
122 
124 void xml_remove_prop(xmlNode *obj, const char *name);
125 
127 gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update,
128  gboolean delete_only);
129 
131 gboolean update_xml_child(xmlNode *child, xmlNode *to_update);
132 
134 int find_xml_children(xmlNode **children, xmlNode *root, const char *tag,
135  const char *field, const char *value,
136  gboolean search_matches);
137 
139 xmlNode *get_xpath_object_relative(const char *xpath, xmlNode *xml_obj,
140  int error_level);
141 
143 void fix_plus_plus_recursive(xmlNode *target);
144 
146 gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml);
147 
149 xmlNode *get_message_xml(const xmlNode *msg, const char *field);
150 
152 const char *xml_latest_schema(void);
153 
155 const char *get_schema_name(int version);
156 
158 int get_schema_version(const char *name);
159 
161 int update_validation(xmlNode **xml_blob, int *best, int max,
162  gboolean transform, gboolean to_logs);
163 
165 gboolean validate_xml(xmlNode *xml_blob, const char *validation,
166  gboolean to_logs);
167 
169 gboolean validate_xml_verbose(const xmlNode *xml_blob);
170 
171 // NOTE: sbd (as of at least 1.5.2) uses this
173 gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs);
174 
176 static inline const char *
177 crm_map_element_name(const xmlNode *xml)
178 {
179  if (xml == NULL) {
180  return NULL;
181  } else if (strcmp((const char *) xml->name, "master") == 0) {
182  // Can't use PCMK__XE_PROMOTABLE_LEGACY because it's internal
183  return PCMK_XE_CLONE;
184  } else {
185  return (const char *) xml->name;
186  }
187 }
188 
190 void copy_in_properties(xmlNode *target, const xmlNode *src);
191 
193 void expand_plus_plus(xmlNode * target, const char *name, const char *value);
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif // PCMK__CRM_COMMON_XML_COMPAT__H
void xml_log_changes(uint8_t level, const char *function, const xmlNode *xml)
Definition: xml_display.c:524
xmlNode * get_message_xml(const xmlNode *msg, const char *field)
Definition: messages.c:299
char data[0]
Definition: cpg.c:58
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
Definition: xml.c:2345
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Definition: xml.c:2555
const char * name
Definition: cib.c:26
void purge_diff_markers(xmlNode *a_node)
Definition: patchset.c:1571
gboolean xml_has_children(const xmlNode *root)
Definition: xml.c:2369
gboolean validate_xml_verbose(const xmlNode *xml_blob)
Definition: schemas.c:1701
int get_schema_version(const char *name)
Definition: schemas.c:1620
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:301
void crm_destroy_xml(gpointer data)
Definition: xml.c:2324
gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)
Definition: xml.c:2567
void fix_plus_plus_recursive(xmlNode *target)
Definition: xml.c:2677
char * crm_xml_escape(const char *text)
Definition: xml.c:2402
gboolean can_prune_leaf(xmlNode *xml_node)
Definition: patchset.c:1590
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2476
#define PCMK_XE_CLONE
Definition: xml_names.h:80
xmlNode * first_named_child(const xmlNode *parent, const char *name)
Definition: xml.c:2528
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
Definition: schemas.c:1661
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
Definition: xml.c:2508
xmlNode * subtract_xml_object(xmlNode *parent, xmlNode *left, xmlNode *right, gboolean full, gboolean *changed, const char *marker)
Definition: patchset.c:1583
xmlDoc * getDocPtr(xmlNode *node)
Definition: xml.c:2330
xmlNode * diff_xml_object(xmlNode *left, xmlNode *right, gboolean suppress)
Definition: patchset.c:1577
int find_xml_children(xmlNode **children, xmlNode *root, const char *tag, const char *field, const char *value, gboolean search_matches)
Definition: xml.c:2641
gboolean apply_xml_diff(xmlNode *old_xml, xmlNode *diff, xmlNode **new_xml)
Definition: patchset.c:1481
const char * get_schema_name(int version)
Definition: schemas.c:1612
void copy_in_properties(xmlNode *target, const xmlNode *src)
Definition: xml.c:2696
xmlNode * get_xpath_object_relative(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:374
Functionality for manipulating name/value pairs.
const char * target
Definition: pcmk_fence.c:29
Defined string constants for XML element and attribute names.
int add_node_nocopy(xmlNode *parent, const char *name, xmlNode *child)
Definition: xml.c:2361
gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
Definition: schemas.c:1729
gboolean update_xml_child(xmlNode *child, xmlNode *to_update)
Definition: xml.c:2634
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
Definition: xml.c:2317
void xml_log_patchset(uint8_t level, const char *function, const xmlNode *xml)
int update_validation(xmlNode **xml_blob, int *best, int max, gboolean transform, gboolean to_logs)
Definition: schemas.c:1642
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
Definition: messages.c:290
char * xml_get_path(const xmlNode *xml)
Get an XPath string that matches an XML element as closely as possible.
Definition: xpath.c:360
xmlNode * find_xml_node(const xmlNode *root, const char *search_path, gboolean must_find)
Definition: xml.c:2534
void xml_remove_prop(xmlNode *obj, const char *name)
Definition: xml.c:2561
const char * parent
Definition: cib.c:27
void expand_plus_plus(xmlNode *target, const char *name, const char *value)
Definition: xml.c:2719
xmlNode * pcmk_create_html_node(xmlNode *parent, const char *element_name, const char *id, const char *class_name, const char *text)
Definition: xml.c:2518
uint32_t version
Definition: remote.c:213
const char * xml_latest_schema(void)
Definition: schemas.c:1606
xmlNode * copy_xml(xmlNode *src_node)
Definition: xml.c:2461