pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
xml_comment.c
Go to the documentation of this file.
1/*
2 * Copyright 2024-2025 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#include <crm_internal.h>
11
12#include <stdbool.h> // bool, false
13#include <stdio.h> // NULL
14
15#include <libxml/tree.h> // xmlDoc, xmlNode, etc.
16#include <libxml/xmlstring.h> // xmlChar
17
18#include "crmcommon_private.h"
19
29xmlNode *
30pcmk__xc_create(xmlDoc *doc, const char *content)
31{
32 xmlNode *node = NULL;
33
34 // Pacemaker typically assumes every xmlNode has a doc
35 pcmk__assert(doc != NULL);
36
37 node = xmlNewDocComment(doc, (const xmlChar *) content);
38 pcmk__mem_assert(node);
40 return node;
41}
42
53bool
54pcmk__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
72static xmlNode *
73match_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
103void
104pcmk__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}
const char * parent
Definition cib.c:27
G_GNUC_INTERNAL void pcmk__xml_new_private_data(xmlNode *xml)
Definition xml.c:387
#define CRM_CHECK(expr, failure_action)
Definition logging.h:213
const char * target
Definition pcmk_fence.c:31
#define pcmk__assert(expr)
#define pcmk__mem_assert(ptr)
@ pcmk__str_casei
void pcmk__xc_update(xmlNode *parent, xmlNode *target, xmlNode *update)
xmlNode * pcmk__xc_create(xmlDoc *doc, const char *content)
Definition xml_comment.c:30
bool pcmk__xc_matches(const xmlNode *comment1, const xmlNode *comment2)
Definition xml_comment.c:54
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
Definition xml.c:832