pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
xml_element_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-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_ELEMENT_INTERNAL__H
11 #define PCMK__CRM_COMMON_XML_ELEMENT_INTERNAL__H
12 
13 /*
14  * Internal-only wrappers for and extensions to libxml2 for processing XML
15  * elements
16  */
17 
18 #include <stdbool.h> // bool
19 #include <stdint.h> // uint32_t
20 #include <stdio.h> // NULL
21 #include <string.h> // strcmp()
22 
23 #include <libxml/tree.h> // xmlNode, etc.
24 
25 #include <crm/common/iso8601.h> // crm_time_t
26 #include <crm/common/xml_element.h> // crm_element_value()
27 #include <crm/common/xml_names.h> // PCMK_XA_ID
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 const char *pcmk__xe_add_last_written(xmlNode *xe);
34 
35 xmlNode *pcmk__xe_first_child(const xmlNode *parent, const char *node_name,
36  const char *attr_n, const char *attr_v);
37 
38 void pcmk__xe_remove_attr(xmlNode *element, const char *name);
39 bool pcmk__xe_remove_attr_cb(xmlNode *xml, void *user_data);
40 void pcmk__xe_remove_matching_attrs(xmlNode *element,
41  bool (*match)(xmlAttrPtr, void *),
42  void *user_data);
43 int pcmk__xe_delete_match(xmlNode *xml, xmlNode *search);
44 int pcmk__xe_replace_match(xmlNode *xml, xmlNode *replace);
45 int pcmk__xe_update_match(xmlNode *xml, xmlNode *update, uint32_t flags);
46 
55 static inline const char *
56 pcmk__xe_id(const xmlNode *xml)
57 {
58  return crm_element_value(xml, PCMK_XA_ID);
59 }
60 
70 static inline bool
71 pcmk__xe_is(const xmlNode *xml, const char *name)
72 {
73  return (xml != NULL) && (xml->name != NULL) && (name != NULL)
74  && (strcmp((const char *) xml->name, name) == 0);
75 }
76 
77 xmlNode *pcmk__xe_create(xmlNode *parent, const char *name);
78 xmlNode *pcmk__xe_next(const xmlNode *node, const char *element_name);
79 
80 void pcmk__xe_set_content(xmlNode *node, const char *format, ...)
81  G_GNUC_PRINTF(2, 3);
82 
83 int pcmk__xe_get_score(const xmlNode *xml, const char *name, int *score,
84  int default_score);
85 
86 int pcmk__xe_copy_attrs(xmlNode *target, const xmlNode *src, uint32_t flags);
87 void pcmk__xe_sort_attrs(xmlNode *xml);
88 
89 void pcmk__xe_set_id(xmlNode *xml, const char *format, ...)
90  G_GNUC_PRINTF(2, 3);
91 
100 void
101 pcmk__xe_set_propv(xmlNodePtr node, va_list pairs);
102 
113 void
114 pcmk__xe_set_props(xmlNodePtr node, ...)
115 G_GNUC_NULL_TERMINATED;
116 
125 static inline xmlAttr *
126 pcmk__xe_first_attr(const xmlNode *xe)
127 {
128  return (xe == NULL)? NULL : xe->properties;
129 }
130 
151 int
152 pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name,
153  int (*handler)(xmlNode *xml, void *userdata),
154  void *userdata);
155 
156 int pcmk__xe_get_datetime(const xmlNode *xml, const char *attr, crm_time_t **t);
157 int pcmk__xe_get_flags(const xmlNode *xml, const char *name, uint32_t *dest,
158  uint32_t default_value);
159 
160 void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value);
161 int pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value);
162 bool pcmk__xe_attr_is_true(const xmlNode *node, const char *name);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif // PCMK__CRM_COMMON_XML_ELEMENT_INTERNAL__H
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Definition: xml_element.c:42
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
Definition: xml_element.c:1480
const char * name
Definition: cib.c:26
struct crm_time_s crm_time_t
Definition: iso8601.h:32
bool pcmk__xe_remove_attr_cb(xmlNode *xml, void *user_data)
Definition: xml_element.c:361
void pcmk__xe_sort_attrs(xmlNode *xml)
Definition: xml_element.c:312
int pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name, int(*handler)(xmlNode *xml, void *userdata), void *userdata)
Definition: xml_element.c:979
int pcmk__xe_update_match(xmlNode *xml, xmlNode *update, uint32_t flags)
Definition: xml_element.c:926
void pcmk__xe_remove_attr(xmlNode *element, const char *name)
Definition: xml_element.c:339
bool pcmk__xe_attr_is_true(const xmlNode *node, const char *name)
Definition: xml_element.c:1538
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
Definition: xml_element.c:407
int pcmk__xe_delete_match(xmlNode *xml, xmlNode *search)
Definition: xml_element.c:717
int pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value)
Definition: xml_element.c:1501
int pcmk__xe_get_datetime(const xmlNode *xml, const char *attr, crm_time_t **t)
Definition: xml_element.c:1436
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: xml_element.c:1168
void void pcmk__xe_set_propv(xmlNodePtr node, va_list pairs)
Definition: xml_element.c:952
int pcmk__xe_get_flags(const xmlNode *xml, const char *name, uint32_t *dest, uint32_t default_value)
Definition: xml_element.c:1243
ISO_8601 Date handling.
void pcmk__xe_set_content(xmlNode *node, const char *format,...) G_GNUC_PRINTF(2
const char * pcmk__xe_add_last_written(xmlNode *xe)
Definition: xml_element.c:526
#define PCMK_XA_ID
Definition: xml_names.h:301
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
Definition: xml_element.c:106
const char * target
Definition: pcmk_fence.c:31
void int pcmk__xe_get_score(const xmlNode *xml, const char *name, int *score, int default_score)
Definition: xml_element.c:132
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
Definition: xml_element.c:970
Defined string constants for XML element and attribute names.
int pcmk__xe_copy_attrs(xmlNode *target, const xmlNode *src, uint32_t flags)
Definition: xml_element.c:252
void pcmk__xe_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
int pcmk__xe_replace_match(xmlNode *xml, xmlNode *replace)
Definition: xml_element.c:832
const char * parent
Definition: cib.c:27
Wrappers for and extensions to libxml2 for XML elements.
void pcmk__xe_remove_matching_attrs(xmlNode *element, bool(*match)(xmlAttrPtr, void *), void *user_data)
Definition: xml_element.c:379
uint64_t flags
Definition: remote.c:211