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