This source file includes following definitions.
- pcmk__xc_create
- pcmk__xc_match
- pcmk__xc_update
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13
14 #include <libxml/tree.h>
15
16 #include "crmcommon_private.h"
17
18
19
20
21
22
23
24
25
26
27 xmlNode *
28 pcmk__xc_create(xmlDoc *doc, const char *content)
29 {
30 xmlNode *node = NULL;
31
32
33 pcmk__assert(doc != NULL);
34
35 node = xmlNewDocComment(doc, (pcmkXmlStr) content);
36 pcmk__mem_assert(node);
37 pcmk__xml_new_private_data(node);
38 return node;
39 }
40
41
42
43
44
45
46
47
48
49 xmlNode *
50 pcmk__xc_match(const xmlNode *root, const xmlNode *search_comment, bool exact)
51 {
52 xmlNode *a_child = NULL;
53 int search_offset = pcmk__xml_position(search_comment, pcmk__xf_skip);
54
55 CRM_CHECK(search_comment->type == XML_COMMENT_NODE, return NULL);
56
57 for (a_child = pcmk__xml_first_child(root); a_child != NULL;
58 a_child = pcmk__xml_next(a_child)) {
59 if (exact) {
60 int offset = pcmk__xml_position(a_child, pcmk__xf_skip);
61 xml_node_private_t *nodepriv = a_child->_private;
62
63 if (offset < search_offset) {
64 continue;
65
66 } else if (offset > search_offset) {
67 return NULL;
68 }
69
70 if (pcmk_is_set(nodepriv->flags, pcmk__xf_skip)) {
71 continue;
72 }
73 }
74
75 if (a_child->type == XML_COMMENT_NODE
76 && pcmk__str_eq((const char *)a_child->content, (const char *)search_comment->content, pcmk__str_casei)) {
77 return a_child;
78
79 } else if (exact) {
80 return NULL;
81 }
82 }
83
84 return NULL;
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98 void
99 pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update)
100 {
101 CRM_CHECK(update != NULL, return);
102 CRM_CHECK(update->type == XML_COMMENT_NODE, return);
103
104 if (target == NULL) {
105 target = pcmk__xc_match(parent, update, false);
106 }
107
108 if (target == NULL) {
109 pcmk__xml_copy(parent, update);
110
111 } else if (!pcmk__str_eq((const char *)target->content, (const char *)update->content, pcmk__str_casei)) {
112 xmlFree(target->content);
113 target->content = xmlStrdup(update->content);
114 }
115 }