pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
xml.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__H
11 #define PCMK__CRM_COMMON_XML__H
12 
13 
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17 
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <fcntl.h>
21 
22 #include <libxml/tree.h>
23 #include <libxml/xpath.h>
24 
25 #include <crm/crm.h>
26 #include <crm/common/nvpair.h>
27 #include <crm/common/schemas.h>
28 #include <crm/common/xml_io.h>
29 #include <crm/common/xml_names.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
41 typedef const xmlChar *pcmkXmlStr;
42 
43 
44 /*
45  * Searching & Modifying
46  */
47 
48 // NOTE: sbd (as of at least 1.5.2) uses this
49 xmlNode *get_xpath_object(const char *xpath, xmlNode * xml_obj, int error_level);
50 
51 char *calculate_on_disk_digest(xmlNode * local_cib);
52 char *calculate_operation_digest(xmlNode * local_cib, const char *version);
53 char *calculate_xml_versioned_digest(xmlNode * input, gboolean sort, gboolean do_filter,
54  const char *version);
55 
56 // NOTE: sbd (as of at least 1.5.2) uses this
62 void crm_xml_init(void);
63 
64 void crm_xml_cleanup(void);
65 
66 void pcmk_free_xml_subtree(xmlNode *xml);
67 
68 // NOTE: sbd (as of at least 1.5.2) uses this
69 void free_xml(xmlNode * child);
70 
71 xmlNode *sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive);
72 xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path);
73 void crm_foreach_xpath_result(xmlNode *xml, const char *xpath,
74  void (*helper)(xmlNode*, void*), void *user_data);
75 xmlNode *expand_idref(xmlNode * input, xmlNode * top);
76 
77 void freeXpathObject(xmlXPathObjectPtr xpathObj);
78 xmlNode *getXpathResult(xmlXPathObjectPtr xpathObj, int index);
79 void dedupXpathResults(xmlXPathObjectPtr xpathObj);
80 
81 static inline int numXpathResults(xmlXPathObjectPtr xpathObj)
82 {
83  if(xpathObj == NULL || xpathObj->nodesetval == NULL) {
84  return 0;
85  }
86  return xpathObj->nodesetval->nodeNr;
87 }
88 
89 bool xml_tracking_changes(xmlNode * xml);
90 bool xml_document_dirty(xmlNode *xml);
91 void xml_track_changes(xmlNode * xml, const char *user, xmlNode *acl_source, bool enforce_acls);
92 void xml_calculate_changes(xmlNode *old_xml, xmlNode *new_xml);
93 void xml_calculate_significant_changes(xmlNode *old_xml, xmlNode *new_xml);
94 void xml_accept_changes(xmlNode * xml);
95 bool xml_patch_versions(const xmlNode *patchset, int add[3], int del[3]);
96 
97 xmlNode *xml_create_patchset(
98  int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version);
99 int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version);
100 
101 void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest);
102 
103 void crm_xml_sanitize_id(char *id);
104 void crm_xml_set_id(xmlNode *xml, const char *format, ...) G_GNUC_PRINTF(2, 3);
105 
106 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
107 #include <crm/common/xml_compat.h>
108 #endif
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif
A dumping ground.
XML schema API.
void crm_xml_cleanup(void)
Definition: xml.c:2143
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
Definition: xml.c:303
void crm_xml_init(void)
Initialize the CRM XML subsystem.
Definition: xml.c:2121
void xml_accept_changes(xmlNode *xml)
Definition: xml.c:402
Wrappers for and extensions to XML input/output functions.
void dedupXpathResults(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:101
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:189
Deprecated Pacemaker XML API.
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
Definition: xml.c:976
bool xml_tracking_changes(xmlNode *xml)
Definition: xml.c:318
char * calculate_operation_digest(xmlNode *local_cib, const char *version)
Calculate and return digest of XML operation.
Definition: digest.c:148
void pcmk_free_xml_subtree(xmlNode *xml)
Definition: xml.c:795
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
Definition: patchset.c:1330
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
Definition: xml.c:2152
bool xml_document_dirty(xmlNode *xml)
Definition: xml.c:325
void free_xml(xmlNode *child)
Definition: xml.c:867
char * calculate_on_disk_digest(xmlNode *local_cib)
Calculate and return digest of XML tree, suitable for storing on disk.
Definition: digest.c:129
xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
Definition: xml.c:2072
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
Definition: patchset.c:386
const xmlChar * pcmkXmlStr
Definition: xml.h:41
Functionality for manipulating name/value pairs.
const char * target
Definition: pcmk_fence.c:29
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
Definition: xpath.c:139
Defined string constants for XML element and attribute names.
const char * path
Definition: cib.c:28
xmlNode * input
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
Definition: xpath.c:58
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
Definition: digest.c:165
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
Definition: xpath.c:170
bool xml_patch_versions(const xmlNode *patchset, int add[3], int del[3])
Definition: patchset.c:788
const char * parent
Definition: cib.c:27
void xml_calculate_significant_changes(xmlNode *old_xml, xmlNode *new_xml)
Definition: xml.c:1541
void freeXpathObject(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:39
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version)
Definition: patchset.c:328
void xml_calculate_changes(xmlNode *old_xml, xmlNode *new_xml)
Definition: xml.c:1549
uint32_t version
Definition: remote.c:213