20 #include <sys/param.h> 22 #include <sys/types.h> 38 #include <libxml/xmlreader.h> 45 # include <libxml/parser.h> 46 # include <libxml/tree.h> 47 # include <libxml/relaxng.h> 51 # include <libxslt/xslt.h> 52 # include <libxslt/transform.h> 55 #define XML_BUFFER_SIZE 4096 56 #define XML_PARSER_DEBUG 0 59 xml_log(
int priority,
const char *fmt, ...)
62 __get_prefix(const
char *prefix, xmlNode *xml,
char *buffer,
int offset);
65 xml_log(
int priority, const
char *fmt, ...)
70 qb_log_from_external_source_va(__FUNCTION__, __FILE__, fmt, priority, __LINE__, 0, ap);
76 xmlRelaxNGValidCtxtPtr valid;
77 xmlRelaxNGParserCtxtPtr parser;
78 } relaxng_ctx_cache_t;
116 typedef struct xml_private_s
125 typedef struct xml_acl_s {
132 static filter_t filter[] = {
141 static struct schema_s *known_schemas = NULL;
142 static int xml_schema_max = 0;
144 static xmlNode *subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right, gboolean * changed);
145 static xmlNode *find_xml_comment(xmlNode * root, xmlNode * search_comment);
146 static int add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update);
147 static bool __xml_acl_check(xmlNode *xml,
const char *name,
enum xml_private_flags mode);
151 xml_latest_schema_index(
void)
153 return xml_schema_max - 4;
157 xml_minimum_schema_index(
void)
164 best = xml_latest_schema_index();
165 target = floor(known_schemas[best].
version);
167 for(lpc = best; lpc > 0; lpc--) {
168 if(known_schemas[lpc].version < target) {
174 best = xml_latest_schema_index();
185 #define CHUNK_SIZE 1024 186 static inline bool TRACKING_CHANGES(xmlNode *xml)
188 if(xml == NULL || xml->doc == NULL || xml->doc->_private == NULL) {
196 #define buffer_print(buffer, max, offset, fmt, args...) do { \ 199 rc = snprintf((buffer) + (offset), (max) - (offset), fmt, ##args); \ 201 if(buffer && rc < 0) { \ 202 crm_perror(LOG_ERR, "snprintf failed at offset %d", offset); \ 203 (buffer)[(offset)] = 0; \ 204 } else if(rc >= ((max) - (offset))) { \ 206 (max) = QB_MAX(CHUNK_SIZE, (max) * 2); \ 207 tmp = realloc_safe((buffer), (max) + 1); \ 217 insert_prefix(
int options,
char **buffer,
int *offset,
int *max,
int depth)
220 size_t spaces = 2 * depth;
222 if ((*buffer) == NULL || spaces >= ((*max) - (*offset))) {
224 (*buffer) = realloc_safe((*buffer), (*max) + 1);
226 memset((*buffer) + (*offset),
' ', spaces);
232 get_schema_root(
void)
234 static const char *base = NULL;
237 base = getenv(
"PCMK_schema_directory");
239 if (base == NULL || strlen(base) == 0) {
246 get_schema_path(
const char *name,
const char *file)
248 const char *base = get_schema_root();
256 static int schema_filter(
const struct dirent * a)
261 if(strstr(a->d_name,
"pacemaker-") != a->d_name) {
264 }
else if(strstr(a->d_name,
".rng") == NULL) {
267 }
else if(sscanf(a->d_name,
"pacemaker-%f.rng", &version) == 0) {
270 }
else if(strcmp(a->d_name,
"pacemaker-1.1.rng") == 0) {
281 static int schema_sort(
const struct dirent ** a,
const struct dirent **b)
284 float a_version = 0.0;
285 float b_version = 0.0;
287 sscanf(a[0]->d_name,
"pacemaker-%f.rng", &a_version);
288 sscanf(b[0]->d_name,
"pacemaker-%f.rng", &b_version);
290 if(a_version > b_version) {
292 }
else if(a_version < b_version) {
300 static void __xml_schema_add(
301 int type,
float version,
const char *name,
const char *location,
const char *transform,
int after_transform)
303 int last = xml_schema_max;
306 known_schemas = realloc_safe(known_schemas, xml_schema_max*
sizeof(
struct schema_s));
308 memset(known_schemas+last, 0,
sizeof(
struct schema_s));
309 known_schemas[last].type =
type;
310 known_schemas[last].after_transform = after_transform;
313 known_schemas[last].version =
version;
315 known_schemas[last].location =
crm_strdup_printf(
"%s.rng", known_schemas[last].name);
321 sscanf(name,
"%[^-]-%f", dummy, &
version);
322 known_schemas[last].version =
version;
323 known_schemas[last].name = strdup(name);
324 known_schemas[last].location = strdup(location);
328 known_schemas[last].transform = strdup(transform);
330 if(after_transform == 0) {
331 after_transform = xml_schema_max;
333 known_schemas[last].after_transform = after_transform;
335 if(known_schemas[last].after_transform < 0) {
336 crm_debug(
"Added supported schema %d: %s (%s)",
337 last, known_schemas[last].name, known_schemas[last].location);
339 }
else if(known_schemas[last].transform) {
340 crm_debug(
"Added supported schema %d: %s (%s upgrades to %d with %s)",
341 last, known_schemas[last].name, known_schemas[last].location,
342 known_schemas[last].after_transform,
343 known_schemas[last].transform);
346 crm_debug(
"Added supported schema %d: %s (%s upgrades to %d)",
347 last, known_schemas[last].name, known_schemas[last].location,
348 known_schemas[last].after_transform);
353 static int __xml_build_schema_list(
void)
356 const char *base = get_schema_root();
357 struct dirent **namelist = NULL;
359 max = scandir(base, &namelist, schema_filter, schema_sort);
360 __xml_schema_add(1, 0.0,
"pacemaker-0.6",
"crm.dtd",
"upgrade06.xsl", 3);
361 __xml_schema_add(1, 0.0,
"transitional-0.6",
"crm-transitional.dtd",
"upgrade06.xsl", 3);
362 __xml_schema_add(2, 0.0,
"pacemaker-0.7",
"pacemaker-1.0.rng", NULL, 0);
368 for (lpc = 0; lpc < max; lpc++) {
371 char *transform = NULL;
373 sscanf(namelist[lpc]->d_name,
"pacemaker-%f.rng", &version);
374 if((lpc + 1) < max) {
375 float next_version = 0.0;
377 sscanf(namelist[lpc+1]->d_name,
"pacemaker-%f.rng", &next_version);
379 if(floor(version) < floor(next_version)) {
384 xslt = get_schema_path(NULL, transform);
385 if(stat(xslt, &s) != 0) {
386 crm_err(
"Transform %s not found", xslt);
388 __xml_schema_add(2, version, NULL, NULL, NULL, -1);
398 __xml_schema_add(2, version, NULL, NULL, transform, next);
405 __xml_schema_add(2, 0.0,
"pacemaker-1.1",
"pacemaker-next.rng", NULL, 0);
406 __xml_schema_add(2, 0.0,
"pacemaker-next",
"pacemaker-next.rng", NULL, -1);
407 __xml_schema_add(0, 0.0,
"none",
"N/A", NULL, -1);
413 set_parent_flag(xmlNode *xml,
long flag)
416 for(; xml; xml = xml->parent) {
429 set_doc_flag(xmlNode *xml,
long flag)
432 if(xml && xml->doc && xml->doc->_private){
442 __xml_node_dirty(xmlNode *xml)
449 __xml_node_clean(xmlNode *xml)
451 xmlNode *cIter = NULL;
458 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
459 __xml_node_clean(cIter);
464 crm_node_created(xmlNode *xml)
466 xmlNode *cIter = NULL;
469 if(p && TRACKING_CHANGES(xml)) {
472 __xml_node_dirty(xml);
475 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
476 crm_node_created(cIter);
482 crm_attr_dirty(xmlAttr *a)
484 xmlNode *parent = a->parent;
493 __xml_node_dirty(parent);
496 int get_tag_name(
const char *input,
size_t offset,
size_t max);
497 int get_attr_name(
const char *input,
size_t offset,
size_t max);
502 xmlNode * xml_node, xmlNode * parent);
504 int add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff);
506 static inline const char *
507 crm_attr_value(xmlAttr * attr)
509 if (attr == NULL || attr->children == NULL) {
512 return (
const char *)attr->children->content;
515 static inline xmlAttr *
516 crm_first_attr(xmlNode * xml)
521 return xml->properties;
524 #define XML_PRIVATE_MAGIC (long) 0x81726354 527 __xml_acl_free(
void *
data)
547 g_list_free_full(p->acls, __xml_acl_free);
551 if(p->deleted_paths) {
552 g_list_free_full(p->deleted_paths, free);
553 p->deleted_paths = NULL;
562 __xml_private_clean(p);
567 pcmkDeregisterNode(xmlNodePtr node)
569 __xml_private_free(node->_private);
573 pcmkRegisterNode(xmlNodePtr node)
578 case XML_ELEMENT_NODE:
579 case XML_DOCUMENT_NODE:
580 case XML_ATTRIBUTE_NODE:
581 case XML_COMMENT_NODE:
590 case XML_CDATA_SECTION_NODE:
594 crm_trace(
"Ignoring %p %d", node, node->type);
599 if(p && TRACKING_CHANGES(node)) {
604 __xml_node_dirty(node);
627 if(target == NULL || target->doc == NULL || target->doc->_private == NULL){
633 }
else if (tag == NULL && ref == NULL && xpath == NULL) {
638 p = target->doc->_private;
645 acl->xpath = strdup(xpath);
646 crm_trace(
"Using xpath: %s", acl->xpath);
653 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"//%s", tag);
663 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@id='%s'", ref);
667 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
" and ");
671 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@%s", attr);
679 acl->xpath = strdup(buffer);
680 crm_trace(
"Built xpath: %s", acl->xpath);
683 p->acls = g_list_append(p->acls, acl);
689 __xml_acl_parse_entry(xmlNode * acl_top, xmlNode * acl_entry, xmlNode *target)
691 xmlNode *child = NULL;
693 for (child = __xml_first_child(acl_entry); child; child = __xml_next(child)) {
694 const char *tag = crm_element_name(child);
701 crm_trace(
"Processing %s %p", tag, child);
710 xmlNode *role = NULL;
712 for (role = __xml_first_child(acl_top); role; role = __xml_next(role)) {
716 if (role_id && strcmp(ref_role, role_id) == 0) {
717 crm_debug(
"Unpacking referenced role: %s", role_id);
718 __xml_acl_parse_entry(acl_top, role, target);
735 crm_warn(
"Unknown ACL entry: %s/%s", tag, kind);
781 __xml_acl_apply(xmlNode *xml)
785 xmlXPathObjectPtr xpathObj = NULL;
788 p = xml->doc->_private;
789 crm_trace(
"Not applying ACLs for %s", p->user);
793 p = xml->doc->_private;
794 for(aIter = p->acls; aIter != NULL; aIter = aIter->next) {
795 int max = 0, lpc = 0;
799 max = numXpathResults(xpathObj);
801 for(lpc = 0; lpc < max; lpc++) {
806 crm_trace(
"Applying %x to %s for %s", acl->mode, path, acl->xpath);
808 #ifdef SUSE_ACL_COMPAT 809 if(is_not_set(p->flags, acl->mode)) {
813 crm_config_warn(
"Configuration element %s is matched by multiple ACL rules, only the first applies ('%s' wins over '%s')",
821 p->flags |= acl->mode;
824 crm_trace(
"Now enforcing ACL: %s (%d matches)", acl->xpath, max);
831 p = xml->doc->_private;
832 crm_info(
"Enforcing default ACL for %s to %s", p->user, crm_element_name(xml));
838 __xml_acl_unpack(xmlNode *source, xmlNode *target,
const char *user)
843 if(target == NULL || target->doc == NULL || target->doc->_private == NULL) {
847 p = target->doc->_private;
849 crm_trace(
"no acls needed for '%s'", user);
851 }
else if(p->acls == NULL) {
855 p->user = strdup(user);
858 xmlNode *child = NULL;
860 for (child = __xml_first_child(acls); child; child = __xml_next(child)) {
861 const char *tag = crm_element_name(child);
866 if(
id && strcmp(
id, user) == 0) {
868 __xml_acl_parse_entry(acls, child, target);
883 }
else if(is_set(allowed, requested)) {
902 __xml_purge_attributes(xmlNode *xml)
904 xmlNode *child = NULL;
905 xmlAttr *xIter = NULL;
906 bool readable_children = FALSE;
910 crm_trace(
"%s is readable", crm_element_name(xml),
ID(xml));
914 xIter = crm_first_attr(xml);
915 while(xIter != NULL) {
916 xmlAttr *tmp = xIter;
917 const char *prop_name = (
const char *)xIter->name;
924 xmlUnsetProp(xml, tmp->name);
927 child = __xml_first_child(xml);
928 while ( child != NULL ) {
929 xmlNode *tmp = child;
931 child = __xml_next(child);
932 readable_children |= __xml_purge_attributes(tmp);
935 if(readable_children == FALSE) {
938 return readable_children;
945 xmlNode *target = NULL;
951 crm_trace(
"no acls needed for '%s'", user);
955 crm_trace(
"filtering copy of %p for '%s'", xml, user);
961 __xml_acl_unpack(acl_source, target, user);
963 __xml_acl_apply(target);
965 doc = target->doc->_private;
966 for(aIter = doc->acls; aIter != NULL && target; aIter = aIter->next) {
973 }
else if(acl->xpath) {
975 xmlXPathObjectPtr xpathObj =
xpath_search(target, acl->xpath);
977 max = numXpathResults(xpathObj);
978 for(lpc = 0; lpc < max; lpc++) {
981 crm_trace(
"Purging attributes from %s", acl->xpath);
982 if(__xml_purge_attributes(match) == FALSE && match == target) {
983 crm_trace(
"No access to the entire document for %s", user);
988 crm_trace(
"Enforced ACL %s (%d matches)", acl->xpath, max);
993 p = target->_private;
994 if(is_set(p->flags,
xpf_acl_deny) && __xml_purge_attributes(target) == FALSE) {
995 crm_trace(
"No access to the entire document for %s", user);
1000 g_list_free_full(doc->acls, __xml_acl_free);
1004 crm_trace(
"Ordinary user '%s' cannot access the CIB without any defined ACLs", doc->user);
1017 __xml_acl_post_process(xmlNode * xml)
1019 xmlNode *cIter = __xml_first_child(xml);
1023 xmlAttr *xIter = NULL;
1030 for (xIter = crm_first_attr(xml); xIter != NULL; xIter = xIter->next) {
1031 const char *prop_name = (
const char *)xIter->name;
1038 crm_trace(
"Creation of %s=%s is allowed", crm_element_name(xml),
ID(xml));
1042 crm_trace(
"Cannot add new node %s at %s", crm_element_name(xml), path);
1044 if(xml != xmlDocGetRootElement(xml->doc)) {
1055 while (cIter != NULL) {
1056 xmlNode *child = cIter;
1057 cIter = __xml_next(cIter);
1058 __xml_acl_post_process(child);
1065 if(xml && xml->doc && xml->doc->_private){
1080 __xml_acl_apply(xml);
1081 __xml_acl_post_process(xml);
1089 if(xml && xml->doc && xml->doc->_private){
1101 crm_trace(
"Tracking changes%s to %p", enforce_acls?
" with ACLs":
"", xml);
1104 if(acl_source == NULL) {
1108 __xml_acl_unpack(acl_source, xml, user);
1109 __xml_acl_apply(xml);
1126 if(xml != NULL && xml->doc && xml->doc->_private) {
1182 static int __xml_offset(xmlNode *xml)
1185 xmlNode *cIter = NULL;
1187 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
1190 if(is_not_set(p->flags,
xpf_skip)) {
1198 static int __xml_offset_no_deletions(xmlNode *xml)
1201 xmlNode *cIter = NULL;
1203 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
1215 __xml_build_changes(xmlNode * xml, xmlNode *patchset)
1217 xmlNode *cIter = NULL;
1218 xmlAttr *pIter = NULL;
1219 xmlNode *change = NULL;
1226 if(__get_prefix(NULL, xml->parent, buffer, offset) > 0) {
1227 int position = __xml_offset_no_deletions(xml);
1240 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1241 xmlNode *attr = NULL;
1243 p = pIter->_private;
1248 if(change == NULL) {
1252 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1277 xmlNode *result = NULL;
1282 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1285 p = pIter->_private;
1287 crm_xml_add(result, (
const char *)pIter->name, value);
1292 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1293 __xml_build_changes(cIter, patchset);
1297 if(patchset && is_set(p->flags,
xpf_moved)) {
1301 crm_trace(
"%s.%s moved to position %d", xml->name,
ID(xml), __xml_offset(xml));
1302 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1313 __xml_accept_changes(xmlNode * xml)
1315 xmlNode *cIter = NULL;
1316 xmlAttr *pIter = NULL;
1320 pIter = crm_first_attr(xml);
1322 while (pIter != NULL) {
1323 const xmlChar *name = pIter->name;
1325 p = pIter->_private;
1326 pIter = pIter->next;
1336 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1337 __xml_accept_changes(cIter);
1342 is_config_change(xmlNode *xml)
1349 p = config->_private;
1355 if(xml->doc && xml->doc->_private) {
1356 p = xml->doc->_private;
1357 for(gIter = p->deleted_paths; gIter; gIter = gIter->next) {
1358 char *path = gIter->data;
1370 xml_repair_v1_diff(xmlNode * last, xmlNode * next, xmlNode * local_diff, gboolean changed)
1373 xmlNode *cib = NULL;
1374 xmlNode *diff_child = NULL;
1376 const char *tag = NULL;
1378 const char *vfields[] = {
1384 if (local_diff == NULL) {
1389 tag =
"diff-removed";
1391 if (diff_child == NULL) {
1401 for(lpc = 0; last && lpc <
DIMOF(vfields); lpc++){
1405 if(changed || lpc == 2) {
1412 if (diff_child == NULL) {
1422 for(lpc = 0; next && lpc <
DIMOF(vfields); lpc++){
1429 xmlAttrPtr xIter = NULL;
1431 for (xIter = next->properties; xIter; xIter = xIter->next) {
1432 const char *p_name = (
const char *)xIter->name;
1435 xmlSetProp(cib, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
1443 xml_create_patchset_v1(xmlNode *source, xmlNode *target,
bool config,
bool suppress)
1449 xml_repair_v1_diff(source, target, patchset, config);
1456 xml_create_patchset_v2(xmlNode *source, xmlNode *target)
1464 xmlNode *patchset = NULL;
1465 const char *vfields[] = {
1477 doc = target->doc->_private;
1485 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1495 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1504 for(gIter = doc->deleted_paths; gIter; gIter = gIter->next) {
1511 __xml_build_changes(target, patchset);
1515 static gboolean patch_legacy_mode(
void)
1517 static gboolean init = TRUE;
1518 static gboolean legacy = FALSE;
1534 bool config = FALSE;
1535 xmlNode *patch = NULL;
1544 config = is_config_change(target);
1545 if(config_changed) {
1546 *config_changed = config;
1549 if(manage_version && config) {
1556 }
else if(manage_version) {
1563 if(patch_legacy_mode()) {
1572 crm_trace(
"Using patch format %d for version: %s", format, version);
1577 patch = xml_create_patchset_v1(source, target, config, FALSE);
1580 patch = xml_create_patchset_v2(source, target);
1583 crm_err(
"Unknown patch format: %d", format);
1595 char *digest = NULL;
1597 if (patch == NULL || source == NULL || target == NULL) {
1606 if (format > 1 && with_digest == FALSE) {
1620 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
1621 const char *prefix, xmlNode *
data,
int depth,
int options);
1627 xmlNode *child = NULL;
1628 xmlNode *added = NULL;
1629 xmlNode *removed = NULL;
1630 gboolean is_first = TRUE;
1632 int add[] = { 0, 0, 0 };
1633 int del[] = { 0, 0, 0 };
1635 const char *fmt = NULL;
1636 const char *digest = NULL;
1639 static struct qb_log_callsite *patchset_cs = NULL;
1641 if (patchset_cs == NULL) {
1642 patchset_cs = qb_log_callsite_get(
function, __FILE__,
"xml-patchset", log_level, __LINE__, 0);
1645 if (patchset == NULL) {
1649 }
else if (log_level == 0) {
1659 if (add[2] != del[2] || add[1] != del[1] || add[0] != del[0]) {
1661 "Diff: --- %d.%d.%d %s", del[0], del[1], del[2], fmt);
1663 "Diff: +++ %d.%d.%d %s", add[0], add[1], add[2], digest);
1665 }
else if (patchset != NULL && (add[0] || add[1] || add[2])) {
1667 "%s: Local-only Change: %d.%d.%d",
function ?
function :
"",
1668 add[0], add[1], add[2]);
1673 xmlNode *change = NULL;
1675 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
1680 }
else if(strcmp(op,
"create") == 0) {
1681 int lpc = 0, max = 0;
1684 max = strlen(prefix);
1685 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1688 for(lpc = 2; lpc < max; lpc++) {
1692 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1696 }
else if(strcmp(op,
"move") == 0) {
1699 }
else if(strcmp(op,
"modify") == 0) {
1707 buffer_unset[0] = 0;
1708 for (child = __xml_first_child(clist); child != NULL; child = __xml_next(child)) {
1713 }
else if(strcmp(op,
"set") == 0) {
1719 o_set += snprintf(buffer_set + o_set,
XML_BUFFER_SIZE - o_set,
"@%s=%s", name, value);
1721 }
else if(strcmp(op,
"unset") == 0) {
1723 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
", ");
1725 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
"@%s", name);
1729 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"+ %s: %s", xpath, buffer_set);
1732 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s: %s", xpath, buffer_unset);
1735 }
else if(strcmp(op,
"delete") == 0) {
1742 if (log_level < LOG_DEBUG ||
function == NULL) {
1747 for (child = __xml_first_child(removed); child != NULL; child = __xml_next(child)) {
1759 for (child = __xml_first_child(added); child != NULL; child = __xml_next(child)) {
1779 doc = xml->doc->_private;
1784 for(gIter = doc->deleted_paths; gIter; gIter = gIter->next) {
1785 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s", (
char*)gIter->data);
1795 xmlNode *top = NULL;
1802 crm_trace(
"Accepting changes to %p", xml);
1803 doc = xml->doc->_private;
1804 top = xmlDocGetRootElement(xml->doc);
1806 __xml_private_clean(xml->doc->_private);
1814 __xml_accept_changes(top);
1819 __subtract_xml_object(xmlNode * target, xmlNode * patch)
1821 xmlNode *patch_child = NULL;
1822 xmlNode *cIter = NULL;
1823 xmlAttrPtr xIter = NULL;
1826 const char *name = NULL;
1827 const char *value = NULL;
1829 if (target == NULL || patch == NULL) {
1833 if (target->type == XML_COMMENT_NODE) {
1836 subtract_xml_comment(target->parent, target, patch, &dummy);
1839 name = crm_element_name(target);
1847 if (value != NULL && strcmp(value,
"removed:top") == 0) {
1848 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
1854 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1855 const char *p_name = (
const char *)xIter->name;
1864 cIter = __xml_first_child(target);
1866 xmlNode *target_child = cIter;
1868 cIter = __xml_next(cIter);
1870 if (target_child->type == XML_COMMENT_NODE) {
1871 patch_child = find_xml_comment(patch, target_child);
1874 patch_child =
find_entity(patch, crm_element_name(target_child),
ID(target_child));
1877 __subtract_xml_object(target_child, patch_child);
1883 __add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * patch)
1885 xmlNode *patch_child = NULL;
1886 xmlNode *target_child = NULL;
1887 xmlAttrPtr xIter = NULL;
1889 const char *
id = NULL;
1890 const char *name = NULL;
1891 const char *value = NULL;
1893 if (patch == NULL) {
1895 }
else if (parent == NULL && target == NULL) {
1903 && strcmp(value,
"added:top") == 0) {
1905 name = crm_element_name(patch);
1906 crm_trace(
"We are the root of the addition: %s.id=%s", name,
id);
1910 }
else if(target == NULL) {
1912 name = crm_element_name(patch);
1913 crm_err(
"Could not locate: %s.id=%s", name,
id);
1917 if (target->type == XML_COMMENT_NODE) {
1918 add_xml_comment(parent, target, patch);
1921 name = crm_element_name(target);
1926 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1927 const char *p_name = (
const char *)xIter->name;
1935 for (patch_child = __xml_first_child(patch); patch_child != NULL;
1936 patch_child = __xml_next(patch_child)) {
1938 if (patch_child->type == XML_COMMENT_NODE) {
1939 target_child = find_xml_comment(target, patch_child);
1942 target_child =
find_entity(target, crm_element_name(patch_child),
ID(patch_child));
1945 __add_xml_object(target, target_child, patch_child);
1961 find_patch_xml_node(xmlNode *patchset,
int format,
bool added,
1962 xmlNode **patch_node)
1969 label = added?
"diff-added" :
"diff-removed";
1972 if (cib_node != NULL) {
1973 *patch_node = cib_node;
1977 label = added?
"target" :
"source";
1982 crm_warn(
"Unknown patch format: %d", format);
1993 xmlNode *tmp = NULL;
1995 const char *vfields[] = {
2005 if (!find_patch_xml_node(patchset, format, FALSE, &tmp)) {
2009 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2011 crm_trace(
"Got %d for del[%s]", del[lpc], vfields[lpc]);
2016 if (!find_patch_xml_node(patchset, format, TRUE, &tmp)) {
2020 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2022 crm_trace(
"Got %d for add[%s]", add[lpc], vfields[lpc]);
2030 xml_patch_version_check(xmlNode *xml, xmlNode *patchset,
int format)
2033 bool changed = FALSE;
2035 int this[] = { 0, 0, 0 };
2036 int add[] = { 0, 0, 0 };
2037 int del[] = { 0, 0, 0 };
2039 const char *vfields[] = {
2045 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2047 crm_trace(
"Got %d for this[%s]",
this[lpc], vfields[lpc]);
2048 if (
this[lpc] < 0) {
2056 add[2] =
this[2] + 1;
2057 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2058 del[lpc] =
this[lpc];
2063 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2064 if(
this[lpc] < del[lpc]) {
2065 crm_debug(
"Current %s is too low (%d < %d)", vfields[lpc],
this[lpc], del[lpc]);
2068 }
else if(
this[lpc] > del[lpc]) {
2069 crm_info(
"Current %s is too high (%d > %d)", vfields[lpc],
this[lpc], del[lpc]);
2074 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
2075 if(add[lpc] > del[lpc]) {
2080 if(changed == FALSE) {
2081 crm_notice(
"Versions did not change in patch %d.%d.%d", add[0], add[1], add[2]);
2085 crm_debug(
"Can apply patch %d.%d.%d to %d.%d.%d",
2086 add[0], add[1], add[2],
this[0],
this[1],
this[2]);
2091 xml_apply_patchset_v1(xmlNode *xml, xmlNode *patchset,
bool check_version)
2094 int root_nodes_seen = 0;
2097 xmlNode *child_diff = NULL;
2098 xmlNode *added =
find_xml_node(patchset,
"diff-added", FALSE);
2099 xmlNode *removed =
find_xml_node(patchset,
"diff-removed", FALSE);
2103 for (child_diff = __xml_first_child(removed); child_diff != NULL;
2104 child_diff = __xml_next(child_diff)) {
2105 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
2106 if (root_nodes_seen == 0) {
2107 __subtract_xml_object(xml, child_diff);
2112 if (root_nodes_seen > 1) {
2113 crm_err(
"(-) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
2117 root_nodes_seen = 0;
2120 xmlNode *child_diff = NULL;
2122 for (child_diff = __xml_first_child(added); child_diff != NULL;
2123 child_diff = __xml_next(child_diff)) {
2124 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
2125 if (root_nodes_seen == 0) {
2126 __add_xml_object(NULL, xml, child_diff);
2132 if (root_nodes_seen > 1) {
2133 crm_err(
"(+) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
2145 __first_xml_child_match(xmlNode *parent,
const char *name,
const char *
id)
2147 xmlNode *cIter = NULL;
2149 for (cIter = __xml_first_child(parent); cIter != NULL; cIter = __xml_next(cIter)) {
2150 if(strcmp((
const char *)cIter->name, name) != 0) {
2153 const char *cid =
ID(cIter);
2154 if(cid == NULL || strcmp(cid,
id) != 0) {
2164 __xml_find_path(xmlNode *top,
const char *key)
2166 xmlNode *target = (xmlNode*)top->doc;
2170 char *current = strdup(key);
2175 rc = sscanf (current,
"/%[^/]%s", section, remainder);
2185 }
else if(tag && section) {
2186 int f = sscanf (section,
"%[^[][@id='%[^']", tag,
id);
2190 target = __first_xml_child_match(target, tag, NULL);
2193 target = __first_xml_child_match(target, tag,
id);
2201 if(rc == 1 || target == NULL) {
2206 char *tmp = current;
2207 current = remainder;
2214 char *path = (
char *)xmlGetNodePath(target);
2216 crm_trace(
"Found %s for %s", path, key);
2231 xml_apply_patchset_v2(xmlNode *xml, xmlNode *patchset,
bool check_version)
2234 xmlNode *change = NULL;
2235 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
2236 xmlNode *match = NULL;
2240 crm_trace(
"Processing %s %s", change->name, op);
2248 match = __xml_find_path(xml, xpath);
2250 crm_trace(
"Performing %s on %s with %p", op, xpath, match);
2252 if(match == NULL && strcmp(op,
"delete") == 0) {
2253 crm_debug(
"No %s match for %s in %p", op, xpath, xml->doc);
2256 }
else if(match == NULL) {
2257 crm_err(
"No %s match for %s in %p", op, xpath, xml->doc);
2261 }
else if(strcmp(op,
"create") == 0) {
2263 xmlNode *child = NULL;
2264 xmlNode *match_child = NULL;
2266 match_child = match->children;
2269 while(match_child && position != __xml_offset(match_child)) {
2270 match_child = match_child->next;
2273 child = xmlDocCopyNode(change->children, match->doc, 1);
2275 crm_trace(
"Adding %s at position %d", child->name, position);
2276 xmlAddPrevSibling(match_child, child);
2278 }
else if(match->last) {
2279 crm_trace(
"Adding %s at position %d (end)", child->name, position);
2280 xmlAddNextSibling(match->last, child);
2283 crm_trace(
"Adding %s at position %d (first)", child->name, position);
2285 xmlAddChild(match, child);
2287 crm_node_created(child);
2289 }
else if(strcmp(op,
"move") == 0) {
2293 if(position != __xml_offset(match)) {
2294 xmlNode *match_child = NULL;
2297 if(p > __xml_offset(match)) {
2302 match_child = match->parent->children;
2304 while(match_child && p != __xml_offset(match_child)) {
2305 match_child = match_child->next;
2308 crm_trace(
"Moving %s to position %d (was %d, prev %p, %s %p)",
2309 match->name, position, __xml_offset(match), match->prev,
2310 match_child?
"next":
"last", match_child?match_child:match->parent->last);
2313 xmlAddPrevSibling(match_child, match);
2317 xmlAddNextSibling(match->parent->last, match);
2321 crm_trace(
"%s is already in position %d", match->name, position);
2324 if(position != __xml_offset(match)) {
2325 crm_err(
"Moved %s.%d to position %d instead of %d (%p)",
2326 match->name,
ID(match), __xml_offset(match), position, match->prev);
2330 }
else if(strcmp(op,
"delete") == 0) {
2333 }
else if(strcmp(op,
"modify") == 0) {
2334 xmlAttr *pIter = crm_first_attr(match);
2341 while(pIter != NULL) {
2342 const char *name = (
const char *)pIter->name;
2344 pIter = pIter->next;
2348 for (pIter = crm_first_attr(attrs); pIter != NULL; pIter = pIter->next) {
2349 const char *name = (
const char *)pIter->name;
2356 crm_err(
"Unknown operation: %s", op);
2367 xmlNode *old = NULL;
2370 if(patchset == NULL) {
2378 rc = xml_patch_version_check(xml, patchset, format);
2392 rc = xml_apply_patchset_v1(xml, patchset, check_version);
2395 rc = xml_apply_patchset_v2(xml, patchset, check_version);
2398 crm_err(
"Unknown patch format: %d", format);
2404 static struct qb_log_callsite *digest_cs = NULL;
2406 char *new_digest = NULL;
2409 if (digest_cs == NULL) {
2411 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
2417 crm_info(
"v%d digest mis-match: expected %s, calculated %s", format, digest, new_digest);
2420 if (digest_cs && digest_cs->targets) {
2426 crm_trace(
"%p %0.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
2430 crm_trace(
"v%d digest matched: expected %s, calculated %s", format, digest, new_digest);
2442 xmlNode *a_child = NULL;
2443 const char *name =
"NULL";
2446 name = crm_element_name(root);
2449 if (search_path == NULL) {
2450 crm_warn(
"Will never find <NULL>");
2454 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
2455 if (strcmp((
const char *)a_child->name, search_path) == 0) {
2462 crm_warn(
"Could not find %s in %s.", search_path, name);
2463 }
else if (root != NULL) {
2464 crm_trace(
"Could not find %s in %s.", search_path, name);
2466 crm_trace(
"Could not find %s in <NULL>.", search_path);
2475 xmlNode *a_child = NULL;
2477 for (a_child = __xml_first_child(parent); a_child != NULL; a_child = __xml_next(a_child)) {
2479 if (node_name == NULL || strcmp((
const char *)a_child->name, node_name) == 0) {
2480 const char *cid =
ID(a_child);
2481 if (
id == NULL || (cid != NULL && strcmp(
id, cid) == 0)) {
2487 crm_trace(
"node <%s id=%s> not found in %s.", node_name,
id, crm_element_name(parent));
2495 crm_warn(
"No node to copy properties from");
2497 }
else if (target == NULL) {
2498 crm_err(
"No node to copy properties into");
2501 xmlAttrPtr pIter = NULL;
2503 for (pIter = crm_first_attr(src); pIter != NULL; pIter = pIter->next) {
2504 const char *p_name = (
const char *)pIter->name;
2505 const char *p_value = crm_attr_value(pIter);
2518 xmlNode *child = NULL;
2519 xmlAttrPtr pIter = NULL;
2521 for (pIter = crm_first_attr(target); pIter != NULL; pIter = pIter->next) {
2522 const char *p_name = (
const char *)pIter->name;
2523 const char *p_value = crm_attr_value(pIter);
2527 for (child = __xml_first_child(target); child != NULL; child = __xml_next(child)) {
2540 const char *old_value = NULL;
2542 if (value == NULL || name == NULL) {
2548 if (old_value == NULL) {
2550 goto set_unexpanded;
2552 }
else if (strstr(value, name) != value) {
2553 goto set_unexpanded;
2556 name_len = strlen(name);
2557 value_len = strlen(value);
2558 if (value_len < (name_len + 2)
2559 || value[name_len] !=
'+' || (value[name_len + 1] !=
'+' && value[name_len + 1] !=
'=')) {
2560 goto set_unexpanded;
2566 if (old_value != value) {
2570 if (value[name_len + 1] !=
'+') {
2571 const char *offset_s = value + (name_len + 2);
2575 int_value += offset;
2585 if (old_value == value) {
2602 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2603 xmlDocSetRootElement(doc, node);
2604 xmlSetTreeDoc(node, doc);
2612 xmlNode *child = NULL;
2615 CRM_CHECK(src_node != NULL,
return NULL);
2617 child = xmlDocCopyNode(src_node, doc, 1);
2618 xmlAddChild(parent, child);
2619 crm_node_created(child);
2642 xmlNode *parent = xml;
2646 if(docp->acls == NULL) {
2647 crm_trace(
"Ordinary user %s cannot access the CIB without any defined ACLs", docp->user);
2652 offset = __get_prefix(NULL, xml, buffer, offset);
2654 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"[@%s]", name);
2664 xmlAttr *attr = xmlHasProp(xml, (
const xmlChar *)name);
2671 while(parent && parent->_private) {
2673 if(__xml_acl_mode_test(p->flags, mode)) {
2677 crm_trace(
"%x access denied to %s: parent", mode, buffer);
2681 parent = parent->parent;
2684 crm_trace(
"%x access denied to %s: default", mode, buffer);
2698 xmlAttr *attr = NULL;
2703 if (value == NULL) {
2706 #if XML_PARANOIA_CHECKS 2708 const char *old_value = NULL;
2713 CRM_CHECK(old_value != value,
crm_err(
"Cannot reset %s with crm_xml_add(%s)", name, value);
2718 if(TRACKING_CHANGES(node)) {
2721 if(old == NULL || value == NULL || strcmp(old, value) != 0) {
2726 if(dirty && __xml_acl_check(node, name,
xpf_acl_create) == FALSE) {
2727 crm_trace(
"Cannot add %s=%s to %s", name, value, node->name);
2731 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2733 crm_attr_dirty(attr);
2736 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2737 return (
char *)attr->children->content;
2744 xmlAttr *attr = NULL;
2745 const char *old_value = NULL;
2748 CRM_CHECK(name != NULL && name[0] != 0,
return NULL);
2753 CRM_CHECK(old_value != value,
return value);
2757 crm_trace(
"Cannot replace %s=%s to %s", name, value, node->name);
2760 }
else if (old_value != NULL && value == NULL) {
2764 }
else if (value == NULL) {
2768 if(TRACKING_CHANGES(node)) {
2769 if(old_value == NULL || value == NULL || strcmp(old_value, value) != 0) {
2774 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2776 crm_attr_dirty(attr);
2778 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2779 return (
char *)attr->children->content;
2786 const char *added =
crm_xml_add(node, name, number);
2796 xmlNode *node = NULL;
2798 if (name == NULL || name[0] == 0) {
2799 CRM_CHECK(name != NULL && name[0] == 0,
return NULL);
2803 if (parent == NULL) {
2804 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2805 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2806 xmlDocSetRootElement(doc, node);
2810 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2811 xmlAddChild(parent, node);
2813 crm_node_created(node);
2818 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset)
2820 const char *
id =
ID(xml);
2822 if(offset == 0 && prefix == NULL && xml->parent) {
2823 offset = __get_prefix(NULL, xml->parent, buffer, offset);
2827 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s[@id='%s']", (
const char *)xml->name,
id);
2828 }
else if(xml->name) {
2829 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s", (
const char *)xml->name);
2841 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
2842 return strdup(buffer);
2850 if (child != NULL) {
2851 xmlNode *top = NULL;
2852 xmlDoc *doc = child->doc;
2856 top = xmlDocGetRootElement(doc);
2859 if (doc != NULL && top == child) {
2863 }
else if(__xml_acl_check(child, NULL,
xpf_acl_write) == FALSE) {
2867 __get_prefix(NULL, child, buffer, offset);
2868 crm_trace(
"Cannot remove %s %x", buffer, p->flags);
2872 if(doc && TRACKING_CHANGES(child) && is_not_set(p->flags,
xpf_created)) {
2876 if(__get_prefix(NULL, child, buffer, offset) > 0) {
2877 crm_trace(
"Deleting %s %p from %p", buffer, child, doc);
2879 p->deleted_paths = g_list_append(p->deleted_paths, strdup(buffer));
2887 xmlUnlinkNode(child);
2896 xmlDoc *doc = xmlNewDoc((
const xmlChar *)
"1.0");
2897 xmlNode *copy = xmlDocCopyNode(src, doc, 1);
2899 xmlDocSetRootElement(doc, copy);
2900 xmlSetTreeDoc(copy, doc);
2905 crm_xml_err(
void *ctx,
const char *msg, ...)
2906 G_GNUC_PRINTF(2, 3);
2909 crm_xml_err(
void *ctx,
const char *msg, ...)
2914 static int buffer_len = 0;
2915 static char *buffer = NULL;
2916 static struct qb_log_callsite *xml_error_cs = NULL;
2918 va_start(args, msg);
2919 len = vasprintf(&buf, msg, args);
2921 if(xml_error_cs == NULL) {
2922 xml_error_cs = qb_log_callsite_get(
2926 if (strchr(buf,
'\n')) {
2929 crm_err(
"XML Error: %s%s", buffer, buf);
2932 crm_err(
"XML Error: %s", buf);
2934 if (xml_error_cs && xml_error_cs->targets) {
2935 crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__,
"xml library error", TRUE, TRUE);
2940 }
else if (buffer == NULL) {
2946 buffer = realloc_safe(buffer, 1 + buffer_len + len);
2947 memcpy(buffer + buffer_len, buf, len);
2949 buffer[buffer_len] = 0;
2959 xmlNode *xml = NULL;
2960 xmlDocPtr output = NULL;
2961 xmlParserCtxtPtr ctxt = NULL;
2962 xmlErrorPtr last_error = NULL;
2964 if (input == NULL) {
2965 crm_err(
"Can't parse NULL input");
2970 ctxt = xmlNewParserCtxt();
2975 xmlCtxtResetLastError(ctxt);
2976 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2979 xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL,
2980 XML_PARSE_NOBLANKS | XML_PARSE_RECOVER);
2982 xml = xmlDocGetRootElement(output);
2984 last_error = xmlCtxtGetLastError(ctxt);
2985 if (last_error && last_error->code != XML_ERR_OK) {
2991 crm_warn(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2992 last_error->domain, last_error->level, last_error->code, last_error->message);
2994 if (last_error->code == XML_ERR_DOCUMENT_EMPTY) {
2997 }
else if (last_error->code != XML_ERR_DOCUMENT_END) {
2998 crm_err(
"Couldn't%s parse %d chars: %s", xml ?
" fully" :
"", (
int)strlen(input),
3005 int len = strlen(input);
3009 crm_warn(
"Parse error[+%.3d]: %.80s", lpc, input+lpc);
3017 xmlFreeParserCtxt(ctxt);
3024 size_t data_length = 0;
3025 size_t read_chars = 0;
3027 char *xml_buffer = NULL;
3028 xmlNode *xml_obj = NULL;
3038 xml_buffer = realloc_safe(xml_buffer, next);
3039 read_chars = fread(xml_buffer + data_length, 1,
XML_BUFFER_SIZE, stdin);
3040 data_length += read_chars;
3041 }
while (read_chars > 0);
3043 if (data_length == 0) {
3044 crm_warn(
"No XML supplied on stdin");
3049 xml_buffer[data_length] =
'\0';
3059 decompress_file(
const char *filename)
3061 char *buffer = NULL;
3065 size_t length = 0, read_len = 0;
3067 BZFILE *bz_file = NULL;
3068 FILE *input = fopen(filename,
"r");
3070 if (input == NULL) {
3071 crm_perror(LOG_ERR,
"Could not open %s for reading", filename);
3075 bz_file = BZ2_bzReadOpen(&rc, input, 0, 0, NULL, 0);
3078 BZ2_bzReadClose(&rc, bz_file);
3083 while (rc == BZ_OK) {
3085 read_len = BZ2_bzRead(&rc, bz_file, buffer + length,
XML_BUFFER_SIZE);
3087 crm_trace(
"Read %ld bytes from file: %d", (
long)read_len, rc);
3089 if (rc == BZ_OK || rc == BZ_STREAM_END) {
3094 buffer[length] =
'\0';
3096 if (rc != BZ_STREAM_END) {
3097 crm_err(
"Couldn't read compressed xml from file");
3102 BZ2_bzReadClose(&rc, bz_file);
3106 crm_err(
"Cannot read compressed files:" " bzlib was not available at compile time");
3114 xmlNode *iter = xml->children;
3117 xmlNode *next = iter->next;
3119 switch (iter->type) {
3122 xmlUnlinkNode(iter);
3126 case XML_ELEMENT_NODE:
3143 xmlNode *xml = NULL;
3144 xmlDocPtr output = NULL;
3145 const char *match = NULL;
3146 xmlParserCtxtPtr ctxt = NULL;
3147 xmlErrorPtr last_error = NULL;
3148 static int xml_options = XML_PARSE_NOBLANKS | XML_PARSE_RECOVER;
3151 ctxt = xmlNewParserCtxt();
3156 xmlCtxtResetLastError(ctxt);
3157 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
3161 match = strstr(filename,
".bz2");
3164 if (filename == NULL) {
3166 output = xmlCtxtReadFd(ctxt, STDIN_FILENO,
"unknown.xml", NULL, xml_options);
3168 }
else if (match == NULL || match[4] != 0) {
3169 output = xmlCtxtReadFile(ctxt, filename, NULL, xml_options);
3172 char *input = decompress_file(filename);
3174 output = xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL, xml_options);
3178 if (output && (xml = xmlDocGetRootElement(output))) {
3182 last_error = xmlCtxtGetLastError(ctxt);
3183 if (last_error && last_error->code != XML_ERR_OK) {
3189 crm_err(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
3190 last_error->domain, last_error->level, last_error->code, last_error->message);
3192 if (last_error && last_error->code != XML_ERR_OK) {
3193 crm_err(
"Couldn't%s parse %s", xml ?
" fully" :
"", filename);
3200 xmlFreeParserCtxt(ctxt);
3215 time_t now = time(NULL);
3216 char *now_str = ctime(&now);
3223 write_xml_stream(xmlNode * xml_node,
const char *filename, FILE * stream, gboolean compress)
3226 char *buffer = NULL;
3227 unsigned int out = 0;
3231 crm_trace(
"Writing XML out to %s", filename);
3232 if (xml_node == NULL) {
3233 crm_err(
"Cannot write NULL to %s", filename);
3248 unsigned int in = 0;
3249 BZFILE *bz_file = NULL;
3251 bz_file = BZ2_bzWriteOpen(&rc, stream, 5, 0, 30);
3253 crm_err(
"bzWriteOpen failed: %d", rc);
3255 BZ2_bzWrite(&rc, bz_file, buffer, strlen(buffer));
3257 crm_err(
"bzWrite() failed: %d", rc);
3262 BZ2_bzWriteClose(&rc, bz_file, 0, &in, &out);
3264 crm_err(
"bzWriteClose() failed: %d", rc);
3267 crm_trace(
"%s: In: %d, out: %d", filename, in, out);
3271 crm_err(
"Cannot write compressed files:" " bzlib was not available at compile time");
3276 res = fprintf(stream,
"%s", buffer);
3278 crm_perror(LOG_ERR,
"Cannot write output to %s", filename);
3285 if (fflush(stream) != 0) {
3286 crm_perror(LOG_ERR,
"fflush for %s failed:", filename);
3290 if (fsync(fileno(stream)) < 0) {
3291 crm_perror(LOG_ERR,
"fsync for %s failed:", filename);
3297 crm_trace(
"Saved %d bytes to the Cib as XML", res);
3304 write_xml_fd(xmlNode * xml_node,
const char *filename,
int fd, gboolean compress)
3306 FILE *stream = NULL;
3309 stream = fdopen(fd,
"w");
3310 return write_xml_stream(xml_node, filename, stream, compress);
3316 FILE *stream = NULL;
3318 stream = fopen(filename,
"w");
3320 return write_xml_stream(xml_node, filename, stream, compress);
3328 return __xml_first_child(tmp);
3341 crm_xml_escape_shuffle(
char *text,
int start,
int *length,
const char *replace)
3344 int offset = strlen(replace) - 1;
3347 text = realloc_safe(text, *length);
3349 for (lpc = (*length) - 1; lpc > (start + offset); lpc--) {
3350 text[lpc] = text[lpc - offset];
3353 memcpy(text + start, replace, offset + 1);
3362 int length = 1 + strlen(text);
3363 char *copy = strdup(text);
3380 for (index = 0; index < length; index++) {
3381 switch (copy[index]) {
3385 copy = crm_xml_escape_shuffle(copy, index, &length,
"<");
3389 copy = crm_xml_escape_shuffle(copy, index, &length,
">");
3393 copy = crm_xml_escape_shuffle(copy, index, &length,
""");
3397 copy = crm_xml_escape_shuffle(copy, index, &length,
"'");
3401 copy = crm_xml_escape_shuffle(copy, index, &length,
"&");
3406 copy = crm_xml_escape_shuffle(copy, index, &length,
" ");
3411 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\n");
3415 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\r");
3425 if(copy[index] <
' ' || copy[index] >
'~') {
3429 copy = crm_xml_escape_shuffle(copy, index, &length, replace);
3443 dump_xml_attr(xmlAttrPtr attr,
int options,
char **buffer,
int *offset,
int *max)
3445 char *p_value = NULL;
3446 const char *p_name = NULL;
3450 if (attr == NULL || attr->children == NULL) {
3459 p_name = (
const char *)attr->name;
3461 buffer_print(*buffer, *max, *offset,
" %s=\"%s\"", p_name, p_value);
3466 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
3467 const char *prefix, xmlNode *
data,
int depth,
int options)
3471 const char *name = NULL;
3472 const char *hidden = NULL;
3474 xmlNode *child = NULL;
3475 xmlAttrPtr pIter = NULL;
3481 name = crm_element_name(
data);
3484 char *buffer = NULL;
3486 insert_prefix(options, &buffer, &offset, &max, depth);
3487 if(
data->type == XML_COMMENT_NODE) {
3497 for (pIter = crm_first_attr(
data); pIter != NULL; pIter = pIter->next) {
3499 const char *p_name = (
const char *)pIter->name;
3500 const char *p_value = crm_attr_value(pIter);
3501 char *p_copy = NULL;
3510 }
else if (hidden != NULL && p_name[0] != 0 && strstr(hidden, p_name) != NULL) {
3511 p_copy = strdup(
"*****");
3517 buffer_print(buffer, max, offset,
" %s=\"%s\"", p_name, p_copy);
3531 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3535 if(
data->type == XML_COMMENT_NODE) {
3545 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3551 char *buffer = NULL;
3553 insert_prefix(options, &buffer, &offset, &max, depth);
3556 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3562 __xml_log_change_element(
int log_level,
const char *file,
const char *
function,
int line,
3563 const char *prefix, xmlNode *
data,
int depth,
int options)
3566 char *prefix_m = NULL;
3567 xmlNode *child = NULL;
3568 xmlAttrPtr pIter = NULL;
3576 prefix_m = strdup(prefix);
3581 __xml_log_element(log_level, file,
function, line,
3584 }
else if(is_set(p->flags,
xpf_dirty)) {
3585 char *spaces = calloc(80, 1);
3586 int s_count = 0, s_max = 80;
3587 char *prefix_del = NULL;
3588 char *prefix_moved = NULL;
3589 const char *
flags = prefix;
3591 insert_prefix(options, &spaces, &s_count, &s_max, depth);
3592 prefix_del = strdup(prefix);
3593 prefix_del[0] =
'-';
3594 prefix_del[1] =
'-';
3595 prefix_moved = strdup(prefix);
3596 prefix_moved[1] =
'~';
3599 flags = prefix_moved;
3604 __xml_log_element(log_level, file,
function, line,
3607 for (pIter = crm_first_attr(
data); pIter != NULL; pIter = pIter->next) {
3608 const char *aname = (
const char*)pIter->name;
3610 p = pIter->_private;
3615 "%s %s @%s=%s", flags, spaces, aname, value);
3617 }
else if(is_set(p->flags,
xpf_dirty)) {
3626 }
else if(is_set(p->flags,
xpf_moved)) {
3627 flags = prefix_moved;
3633 "%s %s @%s=%s", flags, spaces, aname, value);
3640 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3641 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3644 __xml_log_element(log_level, file,
function, line,
3648 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3649 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3659 const char *prefix, xmlNode *
data,
int depth,
int options)
3661 xmlNode *a_child = NULL;
3663 char *prefix_m = NULL;
3665 if (prefix == NULL) {
3672 "No data to dump as XML");
3677 __xml_log_change_element(log_level, file,
function, line, prefix, data, depth, options);
3685 prefix_m = strdup(prefix);
3692 prefix_m = strdup(prefix);
3701 for (a_child = __xml_first_child(data); a_child != NULL; a_child = __xml_next(a_child)) {
3702 log_data_element(log_level, file,
function, line, prefix, a_child, depth + 1, options);
3705 __xml_log_element(log_level, file,
function, line, prefix, data, depth,
3712 dump_filtered_xml(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max)
3715 xmlAttrPtr xIter = NULL;
3716 static int filter_len =
DIMOF(filter);
3718 for (lpc = 0; options && lpc < filter_len; lpc++) {
3719 filter[lpc].found = FALSE;
3722 for (xIter = crm_first_attr(
data); xIter != NULL; xIter = xIter->next) {
3724 const char *p_name = (
const char *)xIter->name;
3726 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
3727 if (filter[lpc].found == FALSE && strcmp(p_name, filter[lpc].
string) == 0) {
3728 filter[lpc].found = TRUE;
3734 if (skip == FALSE) {
3735 dump_xml_attr(xIter, options, buffer, offset, max);
3741 dump_xml_element(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3743 const char *name = NULL;
3754 if (*buffer == NULL) {
3759 name = crm_element_name(
data);
3762 insert_prefix(options, buffer, offset, max, depth);
3766 dump_filtered_xml(
data, options, buffer, offset, max);
3769 xmlAttrPtr xIter = NULL;
3771 for (xIter = crm_first_attr(
data); xIter != NULL; xIter = xIter->next) {
3772 dump_xml_attr(xIter, options, buffer, offset, max);
3776 if (
data->children == NULL) {
3787 if (
data->children) {
3788 xmlNode *xChild = NULL;
3789 for(xChild =
data->children; xChild != NULL; xChild = xChild->next) {
3790 crm_xml_dump(xChild, options, buffer, offset, max, depth + 1);
3793 insert_prefix(options, buffer, offset, max, depth);
3796 if (options & xml_log_option_formatted) {
3803 dump_xml_text(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3814 if (*buffer == NULL) {
3819 insert_prefix(options, buffer, offset, max, depth);
3830 dump_xml_comment(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3841 if (*buffer == NULL) {
3846 insert_prefix(options, buffer, offset, max, depth);
3881 xmlBuffer *xml_buffer = NULL;
3889 xml_buffer = xmlBufferCreate();
3900 xmlBufferSetAllocationScheme(xml_buffer, XML_BUFFER_ALLOC_DOUBLEIT);
3904 *buffer = strdup((
char *)xml_buffer->content);
3908 if ((now + 1) < next) {
3910 crm_err(
"xmlNodeDump() -> %dbytes took %ds", *max, next - now);
3913 xmlBufferFree(xml_buffer);
3918 switch(data->type) {
3919 case XML_ELEMENT_NODE:
3921 dump_xml_element(data, options, buffer, offset, max, depth);
3926 dump_xml_text(data, options, buffer, offset, max, depth);
3929 case XML_COMMENT_NODE:
3930 dump_xml_comment(data, options, buffer, offset, max, depth);
3933 crm_warn(
"Unhandled type: %d", data->type);
3969 char *buffer = NULL;
3970 int offset = 0, max = 0;
3979 char *buffer = NULL;
3980 int offset = 0, max = 0;
3989 char *buffer = NULL;
3990 int offset = 0, max = 0;
3992 crm_xml_dump(an_xml_node, 0, &buffer, &offset, &max, 0);
3999 if (xml_root != NULL && xml_root->children != NULL) {
4033 char *value_copy = NULL;
4036 if (value != NULL) {
4037 value_copy = strdup(value);
4046 crm_trace(
"Cannot remove %s from %s", name, obj->name);
4048 }
else if(TRACKING_CHANGES(obj)) {
4051 xmlAttr *attr = xmlHasProp(obj, (
const xmlChar *)name);
4059 xmlUnsetProp(obj, (
const xmlChar *)name);
4066 xmlNode *child = NULL;
4071 for (child = __xml_first_child(a_node); child != NULL; child = __xml_next(child)) {
4081 if (filename == NULL) {
4089 crm_info(
"Saving %s to %s", desc, filename);
4097 gboolean result = TRUE;
4098 int root_nodes_seen = 0;
4099 static struct qb_log_callsite *digest_cs = NULL;
4103 xmlNode *child_diff = NULL;
4105 xmlNode *removed =
find_xml_node(diff,
"diff-removed", FALSE);
4108 if (digest_cs == NULL) {
4110 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
4115 for (child_diff = __xml_first_child(removed); child_diff != NULL;
4116 child_diff = __xml_next(child_diff)) {
4117 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
4118 if (root_nodes_seen == 0) {
4124 if (root_nodes_seen == 0) {
4127 }
else if (root_nodes_seen > 1) {
4128 crm_err(
"(-) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
4132 root_nodes_seen = 0;
4135 xmlNode *child_diff = NULL;
4137 for (child_diff = __xml_first_child(added); child_diff != NULL;
4138 child_diff = __xml_next(child_diff)) {
4139 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
4140 if (root_nodes_seen == 0) {
4147 if (root_nodes_seen > 1) {
4148 crm_err(
"(+) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
4151 }
else if (result && digest) {
4152 char *new_digest = NULL;
4157 crm_info(
"Digest mis-match: expected %s, calculated %s", digest, new_digest);
4160 crm_trace(
"%p %0.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
4161 if (digest_cs && digest_cs->targets) {
4168 crm_trace(
"Digest matched: expected %s, calculated %s", digest, new_digest);
4172 }
else if (result) {
4180 __xml_diff_object(xmlNode * old, xmlNode *
new)
4182 xmlNode *cIter = NULL;
4183 xmlAttr *pIter = NULL;
4187 crm_node_created(
new);
4188 __xml_acl_post_process(
new);
4201 for (pIter = crm_first_attr(
new); pIter != NULL; pIter = pIter->next) {
4208 for (pIter = crm_first_attr(old); pIter != NULL; ) {
4209 xmlAttr *prop = pIter;
4211 const char *name = (
const char *)pIter->name;
4213 xmlAttr *exists = xmlHasProp(
new, pIter->name);
4215 pIter = pIter->next;
4216 if(exists == NULL) {
4217 p =
new->doc->_private;
4221 exists = xmlSetProp(
new, (
const xmlChar *)name, (
const xmlChar *)old_value);
4224 p = exists->_private;
4227 crm_trace(
"Lost %s@%s=%s", old->name, name, old_value);
4231 int p_new = __xml_offset((xmlNode*)exists);
4232 int p_old = __xml_offset((xmlNode*)prop);
4235 p = exists->_private;
4238 if(strcmp(value, old_value) != 0) {
4242 crm_trace(
"Modified %s@%s %s->%s", old->name, name, old_value, vcopy);
4243 xmlSetProp(
new, prop->name, (
const xmlChar *)old_value);
4247 }
else if(p_old != p_new) {
4248 crm_info(
"Moved %s@%s (%d -> %d)", old->name, name, p_old, p_new);
4249 __xml_node_dirty(
new);
4257 p = exists->_private;
4264 for (pIter = crm_first_attr(
new); pIter != NULL; ) {
4265 xmlAttr *prop = pIter;
4268 pIter = pIter->next;
4270 char *name = strdup((
const char *)prop->name);
4273 crm_trace(
"Created %s@%s=%s", new->name, name, value);
4276 crm_attr_dirty(prop);
4278 xmlUnsetProp(
new, prop->name);
4286 for (cIter = __xml_first_child(old); cIter != NULL; ) {
4287 xmlNode *old_child = cIter;
4288 xmlNode *new_child =
find_entity(
new, crm_element_name(cIter),
ID(cIter));
4290 cIter = __xml_next(cIter);
4292 __xml_diff_object(old_child, new_child);
4299 xmlNode *top = xmlDocGetRootElement(candidate->doc);
4301 __xml_node_clean(candidate);
4302 __xml_acl_apply(top);
4305 if(NULL ==
find_entity(
new, crm_element_name(old_child),
ID(old_child))) {
4311 for (cIter = __xml_first_child(
new); cIter != NULL; ) {
4312 xmlNode *new_child = cIter;
4313 xmlNode *old_child =
find_entity(old, crm_element_name(cIter),
ID(cIter));
4315 cIter = __xml_next(cIter);
4316 if(old_child == NULL) {
4319 __xml_diff_object(old_child, new_child);
4323 int p_new = __xml_offset(new_child);
4324 int p_old = __xml_offset(old_child);
4327 if(p_old != p_new) {
4328 crm_info(
"%s.%s moved from %d to %d - %d",
4329 new_child->name,
ID(new_child), p_old, p_new);
4330 __xml_node_dirty(
new);
4334 p = old_child->_private;
4338 p = new_child->_private;
4356 __xml_diff_object(old,
new);
4362 xmlNode *tmp1 = NULL;
4379 if (added->children == NULL && removed->children == NULL) {
4390 xmlNode *cIter = NULL;
4391 xmlAttrPtr pIter = NULL;
4392 gboolean can_prune = TRUE;
4393 const char *name = crm_element_name(xml_node);
4402 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4403 const char *p_name = (
const char *)pIter->name;
4411 cIter = __xml_first_child(xml_node);
4413 xmlNode *child = cIter;
4415 cIter = __xml_next(cIter);
4427 xmlNode * xml_node, xmlNode * parent)
4430 xmlNode *child = NULL;
4431 xmlAttrPtr pIter = NULL;
4432 xmlNode *new_parent = parent;
4433 const char *name = crm_element_name(xml_node);
4435 CRM_CHECK(xml_node != NULL && name != NULL,
return);
4438 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4439 const char *p_name = (
const char *)pIter->name;
4440 const char *p_value = crm_attr_value(pIter);
4442 lower_bound = context;
4446 if (lower_bound >= 0 || upper_bound >= 0) {
4452 if (upper_bound >= 0) {
4461 for (child = __xml_first_child(us); child != NULL; child = __xml_next(child)) {
4473 if (xml_node->properties) {
4476 }
else if (depth < context) {
4477 xmlNode *child = NULL;
4479 for (child = __xml_first_child(xml_node); child != NULL; child = __xml_next(child)) {
4489 find_xml_comment(xmlNode * root, xmlNode * search_comment)
4491 xmlNode *a_child = NULL;
4493 CRM_CHECK(search_comment->type == XML_COMMENT_NODE,
return NULL);
4495 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
4496 if (a_child->type != XML_COMMENT_NODE) {
4499 if (
safe_str_eq((
const char *)a_child->content, (
const char *)search_comment->content)) {
4508 subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right,
4512 CRM_CHECK(left->type == XML_COMMENT_NODE,
return NULL);
4515 ||
safe_str_neq((
const char *)left->content, (
const char *)right->content)) {
4516 xmlNode *deleted = NULL;
4529 gboolean full, gboolean * changed,
const char *marker)
4531 gboolean dummy = FALSE;
4532 gboolean skip = FALSE;
4533 xmlNode *diff = NULL;
4534 xmlNode *right_child = NULL;
4535 xmlNode *left_child = NULL;
4536 xmlAttrPtr xIter = NULL;
4538 const char *
id = NULL;
4539 const char *name = NULL;
4540 const char *value = NULL;
4541 const char *right_val = NULL;
4544 static int filter_len =
DIMOF(filter);
4546 if (changed == NULL) {
4554 if (left->type == XML_COMMENT_NODE) {
4555 return subtract_xml_comment(parent, left, right, changed);
4559 if (right == NULL) {
4560 xmlNode *deleted = NULL;
4562 crm_trace(
"Processing <%s id=%s> (complete copy)", crm_element_name(left),
id);
4570 name = crm_element_name(left);
4576 if (value != NULL && strcmp(value,
"removed:top") == 0) {
4577 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
4586 for (lpc = 0; lpc < filter_len; lpc++) {
4587 filter[lpc].found = FALSE;
4591 for (left_child = __xml_first_child(left); left_child != NULL;
4592 left_child = __xml_next(left_child)) {
4593 gboolean child_changed = FALSE;
4595 if (left_child->type == XML_COMMENT_NODE) {
4596 right_child = find_xml_comment(right, left_child);
4599 right_child =
find_entity(right, crm_element_name(left_child),
ID(left_child));
4603 if (child_changed) {
4608 if (*changed == FALSE) {
4612 xmlAttrPtr pIter = NULL;
4614 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4615 const char *p_name = (
const char *)pIter->name;
4616 const char *p_value = crm_attr_value(pIter);
4618 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4625 xmlSetProp(diff, (
const xmlChar *)
XML_ATTR_ID, (
const xmlChar *)
id);
4629 for (xIter = crm_first_attr(left); xIter != NULL; xIter = xIter->next) {
4630 const char *prop_name = (
const char *)xIter->name;
4631 xmlAttrPtr right_attr = NULL;
4639 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
4640 if (filter[lpc].found == FALSE && strcmp(prop_name, filter[lpc].
string) == 0) {
4641 filter[lpc].found = TRUE;
4651 right_attr = xmlHasProp(right, (
const xmlChar *)prop_name);
4653 p = right_attr->_private;
4657 if (right_val == NULL || (p && is_set(p->flags,
xpf_deleted))) {
4661 xmlAttrPtr pIter = NULL;
4663 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4664 const char *p_name = (
const char *)pIter->name;
4665 const char *p_value = crm_attr_value(pIter);
4667 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4674 xmlSetProp(diff, (
const xmlChar *)prop_name, (
const xmlChar *)value);
4682 if (strcmp(left_value, right_val) == 0) {
4688 xmlAttrPtr pIter = NULL;
4690 crm_trace(
"Changes detected to %s in <%s id=%s>", prop_name,
4691 crm_element_name(left),
id);
4692 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4693 const char *p_name = (
const char *)pIter->name;
4694 const char *p_value = crm_attr_value(pIter);
4696 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4701 crm_trace(
"Changes detected to %s (%s -> %s) in <%s id=%s>",
4702 prop_name, left_value, right_val, crm_element_name(left),
id);
4709 if (*changed == FALSE) {
4713 }
else if (full == FALSE &&
id) {
4721 add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update)
4724 CRM_CHECK(update->type == XML_COMMENT_NODE,
return 0);
4726 if (target == NULL) {
4727 target = find_xml_comment(parent, update);
4730 if (target == NULL) {
4734 }
else if (
safe_str_neq((
const char *)target->content, (
const char *)update->content)) {
4735 xmlFree(target->content);
4736 target->content = xmlStrdup(update->content);
4743 add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff)
4745 xmlNode *a_child = NULL;
4746 const char *object_id = NULL;
4747 const char *object_name = NULL;
4756 if (update->type == XML_COMMENT_NODE) {
4757 return add_xml_comment(parent, target, update);
4760 object_name = crm_element_name(update);
4761 object_id =
ID(update);
4763 CRM_CHECK(object_name != NULL,
return 0);
4765 if (target == NULL && object_id == NULL) {
4769 }
else if (target == NULL) {
4770 target =
find_entity(parent, object_name, object_id);
4773 if (target == NULL) {
4776 #if XML_PARSER_DEBUG 4778 object_id ?
" id=" :
"", object_id ? object_id :
"");
4781 crm_trace(
"Found node <%s%s%s/> to update",
4782 crm_str(object_name), object_id ?
" id=" :
"", object_id ? object_id :
"");
4788 if (as_diff == FALSE) {
4794 xmlAttrPtr pIter = NULL;
4796 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4797 const char *p_name = (
const char *)pIter->name;
4798 const char *p_value = crm_attr_value(pIter);
4801 xmlUnsetProp(target, (
const xmlChar *)p_name);
4802 xmlSetProp(target, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4806 for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
4807 #if XML_PARSER_DEBUG 4808 crm_trace(
"Updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
4813 #if XML_PARSER_DEBUG 4822 gboolean can_update = TRUE;
4823 xmlNode *child_of_child = NULL;
4826 CRM_CHECK(to_update != NULL,
return FALSE);
4828 if (
safe_str_neq(crm_element_name(to_update), crm_element_name(child))) {
4834 }
else if (can_update) {
4835 #if XML_PARSER_DEBUG 4841 for (child_of_child = __xml_first_child(child); child_of_child != NULL;
4842 child_of_child = __xml_next(child_of_child)) {
4855 const char *tag,
const char *field,
const char *value, gboolean search_matches)
4857 int match_found = 0;
4860 CRM_CHECK(children != NULL,
return FALSE);
4862 if (tag != NULL &&
safe_str_neq(tag, crm_element_name(root))) {
4867 if (*children == NULL) {
4874 if (search_matches || match_found == 0) {
4875 xmlNode *child = NULL;
4877 for (child = __xml_first_child(root); child != NULL; child = __xml_next(child)) {
4878 match_found +=
find_xml_children(children, child, tag, field, value, search_matches);
4888 gboolean can_delete = FALSE;
4889 xmlNode *child_of_child = NULL;
4891 const char *up_id = NULL;
4892 const char *child_id = NULL;
4893 const char *right_val = NULL;
4896 CRM_CHECK(update != NULL,
return FALSE);
4899 child_id =
ID(child);
4901 if (up_id == NULL || (child_id && strcmp(child_id, up_id) == 0)) {
4904 if (
safe_str_neq(crm_element_name(update), crm_element_name(child))) {
4907 if (can_delete && delete_only) {
4908 xmlAttrPtr pIter = NULL;
4910 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4911 const char *p_name = (
const char *)pIter->name;
4912 const char *p_value = crm_attr_value(pIter);
4921 if (can_delete && parent != NULL) {
4923 if (delete_only || update == NULL) {
4928 xmlDoc *doc = tmp->doc;
4929 xmlNode *old = NULL;
4932 old = xmlReplaceNode(child, tmp);
4936 __xml_acl_apply(tmp);
4940 xmlDocSetRootElement(doc, old);
4946 }
else if (can_delete) {
4951 child_of_child = __xml_first_child(child);
4952 while (child_of_child) {
4953 xmlNode *next = __xml_next(child_of_child);
4959 child_of_child = NULL;
4961 child_of_child = next;
4971 const char *name = key;
4972 const char *s_value = value;
4974 xmlNode *xml_node = user_data;
4981 crm_trace(
"dumped: name=%s value=%s", name, s_value);
4987 const char *name = key;
4988 const char *s_value = value;
4990 xmlNode *xml_node = user_data;
4992 if (isdigit(name[0])) {
5000 crm_trace(
"dumped: %s=%s", name, s_value);
5003 crm_trace(
"duplicate: %s=%s", name, s_value);
5010 const char *name = key;
5011 const char *s_value = value;
5013 xmlNode *xml_node = user_data;
5019 crm_trace(
"duplicate: %s=%s", name, s_value);
5026 char *crm_name = NULL;
5028 if (key == NULL || value == NULL) {
5030 }
else if (((
char *)key)[0] ==
'#') {
5032 }
else if (strstr(key,
":")) {
5044 xmlNode *child = NULL;
5045 xmlAttrPtr pIter = NULL;
5046 xmlNode *nvpair_list = NULL;
5047 GHashTable *nvpair_hash = g_hash_table_new_full(
crm_str_hash, g_str_equal,
5050 CRM_CHECK(parent != NULL,
return nvpair_hash);
5053 if (nvpair_list == NULL) {
5054 crm_trace(
"No attributes in %s", crm_element_name(parent));
5060 for (pIter = crm_first_attr(nvpair_list); pIter != NULL; pIter = pIter->next) {
5061 const char *p_name = (
const char *)pIter->name;
5062 const char *p_value = crm_attr_value(pIter);
5064 crm_trace(
"Added %s=%s", p_name, p_value);
5066 g_hash_table_insert(nvpair_hash, strdup(p_name), strdup(p_value));
5069 for (child = __xml_first_child(nvpair_list); child != NULL; child = __xml_next(child)) {
5070 if (strcmp((
const char *)child->name,
XML_TAG_PARAM) == 0) {
5075 if (key != NULL && value != NULL) {
5076 g_hash_table_insert(nvpair_hash, strdup(key), strdup(value));
5084 typedef struct name_value_s {
5090 sort_pairs(gconstpointer a, gconstpointer b)
5102 rc = strcmp(pair_a->name, pair_b->name);
5105 }
else if (rc > 0) {
5112 dump_pair(gpointer
data, gpointer user_data)
5115 xmlNode *parent = user_data;
5121 sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive)
5123 xmlNode *child = NULL;
5127 xmlNode *result = NULL;
5128 const char *name = NULL;
5129 xmlAttrPtr pIter = NULL;
5133 name = crm_element_name(input);
5138 for (pIter = crm_first_attr(input); pIter != NULL; pIter = pIter->next) {
5139 const char *p_name = (
const char *)pIter->name;
5140 const char *p_value = crm_attr_value(pIter);
5143 pair->name = p_name;
5144 pair->value = p_value;
5145 unsorted = g_list_prepend(unsorted, pair);
5149 sorted = g_list_sort(unsorted, sort_pairs);
5150 g_list_foreach(sorted, dump_pair, result);
5151 g_list_free_full(sorted, free);
5153 for (child = __xml_first_child(input); child != NULL; child = __xml_next(child)) {
5165 validate_with_dtd(xmlDocPtr doc, gboolean to_logs,
const char *dtd_file)
5167 gboolean valid = TRUE;
5169 xmlDtdPtr dtd = NULL;
5170 xmlValidCtxtPtr cvp = NULL;
5173 CRM_CHECK(dtd_file != NULL,
return FALSE);
5175 dtd = xmlParseDTD(NULL, (
const xmlChar *)dtd_file);
5177 crm_err(
"Could not locate/parse DTD: %s", dtd_file);
5181 cvp = xmlNewValidCtxt();
5184 cvp->userData = (
void *)LOG_ERR;
5185 cvp->error = (xmlValidityErrorFunc)
xml_log;
5186 cvp->warning = (xmlValidityWarningFunc)
xml_log;
5188 cvp->userData = (
void *)stderr;
5189 cvp->error = (xmlValidityErrorFunc) fprintf;
5190 cvp->warning = (xmlValidityWarningFunc) fprintf;
5193 if (!xmlValidateDtd(cvp, doc, dtd)) {
5196 xmlFreeValidCtxt(cvp);
5199 crm_err(
"Internal error: No valid context");
5209 xmlNode *match = NULL;
5211 for (match = __xml_first_child(parent); match != NULL; match = __xml_next(match)) {
5217 if (name == NULL || strcmp((
const char *)match->name, name) == 0) {
5226 relaxng_invalid_stderr(
void *userData, xmlErrorPtr error)
5246 crm_err(
"Structured error: line=%d, level=%d %s", error->line, error->level, error->message);
5251 validate_with_relaxng(xmlDocPtr doc, gboolean to_logs,
const char *relaxng_file,
5252 relaxng_ctx_cache_t ** cached_ctx)
5255 gboolean valid = TRUE;
5256 relaxng_ctx_cache_t *ctx = NULL;
5259 CRM_CHECK(relaxng_file != NULL,
return FALSE);
5261 if (cached_ctx && *cached_ctx) {
5265 crm_info(
"Creating RNG parser context");
5266 ctx = calloc(1,
sizeof(relaxng_ctx_cache_t));
5268 xmlLoadExtDtdDefaultValue = 1;
5269 ctx->parser = xmlRelaxNGNewParserCtxt(relaxng_file);
5270 CRM_CHECK(ctx->parser != NULL,
goto cleanup);
5273 xmlRelaxNGSetParserErrors(ctx->parser,
5274 (xmlRelaxNGValidityErrorFunc)
xml_log,
5275 (xmlRelaxNGValidityWarningFunc) xml_log,
5276 GUINT_TO_POINTER(LOG_ERR));
5278 xmlRelaxNGSetParserErrors(ctx->parser,
5279 (xmlRelaxNGValidityErrorFunc) fprintf,
5280 (xmlRelaxNGValidityWarningFunc) fprintf, stderr);
5283 ctx->rng = xmlRelaxNGParse(ctx->parser);
5284 CRM_CHECK(ctx->rng != NULL,
crm_err(
"Could not find/parse %s", relaxng_file);
5287 ctx->valid = xmlRelaxNGNewValidCtxt(ctx->rng);
5288 CRM_CHECK(ctx->valid != NULL,
goto cleanup);
5291 xmlRelaxNGSetValidErrors(ctx->valid,
5292 (xmlRelaxNGValidityErrorFunc)
xml_log,
5293 (xmlRelaxNGValidityWarningFunc) xml_log,
5294 GUINT_TO_POINTER(LOG_ERR));
5296 xmlRelaxNGSetValidErrors(ctx->valid,
5297 (xmlRelaxNGValidityErrorFunc) fprintf,
5298 (xmlRelaxNGValidityWarningFunc) fprintf, stderr);
5305 xmlLineNumbersDefault(1);
5306 rc = xmlRelaxNGValidateDoc(ctx->valid, doc);
5310 }
else if (rc < 0) {
5311 crm_err(
"Internal libxml error during validation\n");
5320 if (ctx->parser != NULL) {
5321 xmlRelaxNGFreeParserCtxt(ctx->parser);
5323 if (ctx->valid != NULL) {
5324 xmlRelaxNGFreeValidCtxt(ctx->valid);
5326 if (ctx->rng != NULL) {
5327 xmlRelaxNGFree(ctx->rng);
5338 static bool init = TRUE;
5347 xmlSetBufferAllocationScheme(XML_BUFFER_ALLOC_DOUBLEIT);
5350 xmlDeregisterNodeDefault(pcmkDeregisterNode);
5351 xmlRegisterNodeDefault(pcmkRegisterNode);
5353 __xml_build_schema_list();
5361 relaxng_ctx_cache_t *ctx = NULL;
5363 crm_info(
"Cleaning up memory from libxml2");
5364 for (; lpc < xml_schema_max; lpc++) {
5366 switch (known_schemas[lpc].
type) {
5375 ctx = (relaxng_ctx_cache_t *) known_schemas[lpc].cache;
5379 if (ctx->parser != NULL) {
5380 xmlRelaxNGFreeParserCtxt(ctx->parser);
5382 if (ctx->valid != NULL) {
5383 xmlRelaxNGFreeValidCtxt(ctx->valid);
5385 if (ctx->rng != NULL) {
5386 xmlRelaxNGFree(ctx->rng);
5389 known_schemas[lpc].cache = NULL;
5394 free(known_schemas[lpc].name);
5395 free(known_schemas[lpc].location);
5396 free(known_schemas[lpc].transform);
5398 free(known_schemas);
5399 xsltCleanupGlobals();
5404 validate_with(xmlNode * xml,
int method, gboolean to_logs)
5406 xmlDocPtr doc = NULL;
5407 gboolean valid = FALSE;
5415 type = known_schemas[method].type;
5422 file = get_schema_path(known_schemas[method].name, known_schemas[method].location);
5427 valid = validate_with_dtd(doc, to_logs, file);
5431 validate_with_relaxng(doc, to_logs, file,
5432 (relaxng_ctx_cache_t **) & (known_schemas[method].cache));
5435 crm_err(
"Unknown validator type: %d", type);
5445 dump_file(
const char *filename)
5453 fp = fopen(filename,
"r");
5456 fprintf(stderr,
"%4d ", ++line);
5462 }
else if (ch ==
'\n') {
5463 fprintf(stderr,
"\n%4d ", ++line);
5477 xmlNode *xml = NULL;
5478 gboolean rc = FALSE;
5479 char *filename = strdup(
CRM_STATE_DIR "/cib-invalid.XXXXXX");
5481 umask(S_IWGRP | S_IWOTH | S_IROTH);
5482 fd = mkstemp(filename);
5485 dump_file(filename);
5487 doc = xmlParseFile(filename);
5488 xml = xmlDocGetRootElement(doc);
5503 if (validation == NULL) {
5507 if (validation == NULL) {
5519 for (lpc = 0; lpc < xml_schema_max; lpc++) {
5520 if(validate_with(xml_blob, lpc, FALSE)) {
5523 crm_info(
"XML validated against %s", known_schemas[lpc].name);
5524 if(known_schemas[lpc].after_transform == 0) {
5534 if (strcmp(validation,
"none") == 0) {
5537 }
else if(version < xml_schema_max) {
5538 return validate_with(xml_blob, version, to_logs);
5542 crm_err(
"Unknown validator: %s", validation);
5548 apply_transformation(xmlNode * xml,
const char *transform)
5551 xmlNode *out = NULL;
5552 xmlDocPtr res = NULL;
5553 xmlDocPtr doc = NULL;
5554 xsltStylesheet *xslt = NULL;
5558 xform = get_schema_path(NULL, transform);
5560 xmlLoadExtDtdDefaultValue = 1;
5561 xmlSubstituteEntitiesDefault(1);
5563 xslt = xsltParseStylesheetFile((
const xmlChar *)xform);
5566 res = xsltApplyStylesheet(xslt, doc, NULL);
5569 out = xmlDocGetRootElement(res);
5573 xsltFreeStylesheet(xslt);
5585 if (version < 0 || version >= xml_schema_max) {
5588 return known_schemas[
version].name;
5599 for (; lpc < xml_schema_max; lpc++) {
5612 xmlNode *xml = NULL;
5614 int max_stable_schemas = xml_latest_schema_index();
5615 int lpc = 0, match = -1, rc =
pcmk_ok;
5617 CRM_CHECK(best != NULL,
return -EINVAL);
5618 CRM_CHECK(xml_blob != NULL,
return -EINVAL);
5619 CRM_CHECK(*xml_blob != NULL,
return -EINVAL);
5625 if (value != NULL) {
5629 if (lpc >= 0 && transform == FALSE) {
5632 }
else if (lpc < 0) {
5638 if (match >= max_stable_schemas) {
5645 while(lpc <= max_stable_schemas) {
5646 gboolean valid = TRUE;
5648 crm_debug(
"Testing '%s' validation (%d of %d)",
5649 known_schemas[lpc].name ? known_schemas[lpc].name :
"<unset>",
5650 lpc, max_stable_schemas);
5651 valid = validate_with(xml, lpc, to_logs);
5656 crm_trace(
"%s validation failed", known_schemas[lpc].name ? known_schemas[lpc].name :
"<unset>");
5659 if (valid && transform) {
5660 xmlNode *upgrade = NULL;
5661 int next = known_schemas[lpc].after_transform;
5664 crm_trace(
"Stopping at %s", known_schemas[lpc].name);
5667 }
else if (max > 0 && lpc == max) {
5668 crm_trace(
"Upgrade limit reached at %s (lpc=%d, next=%d, max=%d)",
5669 known_schemas[lpc].name, lpc, next, max);
5672 }
else if (max > 0 && next > max) {
5673 crm_debug(
"Upgrade limit reached at %s (lpc=%d, next=%d, max=%d)",
5674 known_schemas[lpc].name, lpc, next, max);
5677 }
else if (known_schemas[lpc].transform == NULL) {
5678 crm_debug(
"%s-style configuration is also valid for %s",
5679 known_schemas[lpc].name, known_schemas[next].name);
5681 if (validate_with(xml, next, to_logs)) {
5682 crm_debug(
"Configuration valid for schema: %s", known_schemas[next].name);
5688 crm_info(
"Configuration not valid for schema: %s", known_schemas[next].name);
5692 crm_debug(
"Upgrading %s-style configuration to %s with %s",
5693 known_schemas[lpc].name, known_schemas[next].name,
5694 known_schemas[lpc].transform ? known_schemas[lpc].transform :
"no-op");
5697 upgrade = apply_transformation(xml, known_schemas[lpc].transform);
5699 if (upgrade == NULL) {
5700 crm_err(
"Transformation %s failed", known_schemas[lpc].transform);
5703 }
else if (validate_with(upgrade, next, to_logs)) {
5704 crm_info(
"Transformation %s successful", known_schemas[lpc].transform);
5712 crm_err(
"Transformation %s did not produce a valid configuration",
5713 known_schemas[lpc].transform);
5722 if (*best > match) {
5723 crm_info(
"%s the configuration from %s to %s",
5724 transform?
"Transformed":
"Upgraded",
5725 value ? value :
"<none>", known_schemas[*best].name);
5741 int min_version = xml_minimum_schema_index();
5743 if (version < min_version) {
5744 xmlNode *converted = NULL;
5750 if (version < min_version) {
5752 crm_config_err(
"Your current configuration could only be upgraded to %s... " 5753 "the minimum requirement is %s.\n",
crm_str(value),
5756 fprintf(stderr,
"Your current configuration could only be upgraded to %s... " 5757 "the minimum requirement is %s.\n",
5769 if (version < xml_latest_schema_index()) {
5771 "which is acceptable but not the most recent",
5774 }
else if (to_logs) {
5775 crm_info(
"Your configuration was internally updated to the latest version (%s)",
5783 " It is highly encouraged and prevents many common cluster issues.");
5786 fprintf(stderr,
"Configuration validation is currently disabled." 5787 " It is highly encouraged and prevents many common cluster issues.\n");
5801 const char *tag = NULL;
5802 const char *ref = NULL;
5803 xmlNode *result = input;
5804 char *xpath_string = NULL;
5806 if (result == NULL) {
5809 }
else if (top == NULL) {
5813 tag = crm_element_name(result);
5817 int xpath_max = 512, offset = 0;
5819 xpath_string = calloc(1, xpath_max);
5821 offset += snprintf(xpath_string + offset, xpath_max - offset,
"//%s[@id='%s']", tag, ref);
5825 if (result == NULL) {
5826 char *nodePath = (
char *)xmlGetNodePath(top);
5828 crm_err(
"No match for %s found in %s: Invalid configuration", xpath_string,
5841 xmlAttr *attr = NULL;
5844 crm_err(
"Couldn't find %s in NULL", name ? name :
"<null>");
5848 }
else if (name == NULL) {
5849 crm_err(
"Couldn't find NULL in %s", crm_element_name(data));
5853 attr = xmlHasProp(data, (
const xmlChar *)name);
5854 if (attr == NULL || attr->children == NULL) {
5857 return (
const char *)attr->children->content;
#define CRM_CHECK(expr, failure_action)
gboolean daemon_option_enabled(const char *daemon, const char *option)
#define XML_ATTR_UPDATE_ORIG
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
#define crm_notice(fmt, args...)
#define XML_ATTR_UPDATE_CLIENT
xmlNode * diff_xml_object(xmlNode *old, xmlNode *new, gboolean suppress)
gboolean safe_str_neq(const char *a, const char *b)
char * crm_generate_uuid(void)
int add_xml_object(xmlNode *parent, xmlNode *target, xmlNode *update, gboolean as_diff)
void log_data_element(int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, int options)
#define XML_ATTR_NUMUPDATES
struct xml_acl_s xml_acl_t
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
bool xml_acl_enabled(xmlNode *xml)
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
const char * __xml_acl_to_text(enum xml_private_flags flags)
#define crm_config_err(fmt...)
#define pcmk_err_old_data
#define XML_ATTR_UPDATE_USER
int char2score(const char *score)
int write_xml_fd(xmlNode *xml_node, const char *filename, int fd, gboolean compress)
void fix_plus_plus_recursive(xmlNode *target)
#define buffer_print(buffer, max, offset, fmt, args...)
#define XML_ACL_TAG_WRITE
#define XML_NVPAIR_ATTR_NAME
void purge_diff_markers(xmlNode *a_node)
xmlNode * stdin2xml(void)
void xml_acl_disable(xmlNode *xml)
int get_attr_name(const char *input, size_t offset, size_t max)
#define CRM_DTD_DIRECTORY
void g_hash_destroy_str(gpointer data)
#define CRM_LOG_ASSERT(expr)
#define do_crm_log_alias(level, file, function, line, fmt, args...)
Log a message as if it came from a different code location.
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
#define clear_bit(word, bit)
unsigned int crm_trace_nonlog
#define XML_CIB_TAG_NVPAIR
char * strerror(int errnum)
void hash2field(gpointer key, gpointer value, gpointer user_data)
xmlNode * first_named_child(xmlNode *parent, const char *name)
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
char * xml_get_path(xmlNode *xml)
char * crm_meta_name(const char *field)
gboolean validate_xml_verbose(xmlNode *xml_blob)
#define XML_ATTR_GENERATION
const char * crm_element_value_const(const xmlNode *data, const char *name)
xmlNode * filename2xml(const char *filename)
int find_xml_children(xmlNode **children, xmlNode *root, const char *tag, const char *field, const char *value, gboolean search_matches)
void expand_plus_plus(xmlNode *target, const char *name, const char *value)
#define XML_ACL_ATTR_REFv1
#define XML_ACL_ATTR_KIND
#define pcmk_err_diff_failed
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
#define pcmk_err_diff_resync
#define crm_warn(fmt, args...)
#define set_bit(word, bit)
xmlNode * copy_xml(xmlNode *src)
bool pcmk_acl_required(const char *user)
void diff_filter_context(int context, int upper_bound, int lower_bound, xmlNode *xml_node, xmlNode *parent)
#define crm_debug(fmt, args...)
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define XML_ACL_ATTR_XPATH
void xml_log_patchset(uint8_t log_level, const char *function, xmlNode *patchset)
#define pcmk_err_schema_validation
#define XML_ACL_TAG_PERMISSION
void free_xml(xmlNode *child)
#define crm_trace(fmt, args...)
#define crm_log_xml_explicit(xml, text)
#define XML_PRIVATE_MAGIC
const char * get_schema_name(int version)
#define crm_log_xml_debug(xml, text)
void save_xml_to_file(xmlNode *xml, const char *desc, const char *filename)
struct name_value_s name_value_t
bool xml_acl_denied(xmlNode *xml)
#define XML_ACL_TAG_USERv1
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Wrappers for and extensions to libxml2.
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
#define crm_log_xml_warn(xml, text)
#define XML_ATTR_VALIDATION
#define XML_ACL_ATTR_ATTRIBUTE
#define XML_DIFF_POSITION
#define XML_TAG_RESOURCE_REF
void crm_xml_cleanup(void)
xmlNode * add_node_copy(xmlNode *parent, xmlNode *src_node)
int crm_element_value_int(xmlNode *data, const char *name, int *dest)
xmlDoc * getDocPtr(xmlNode *node)
char * dump_xml_formatted(xmlNode *an_xml_node)
void xml_calculate_changes(xmlNode *old, xmlNode *new)
const char * crm_xml_add_last_written(xmlNode *xml_node)
xmlNode * string2xml(const char *input)
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config_changed, bool manage_version)
void xml_log_changes(uint8_t log_level, const char *function, xmlNode *xml)
#define pcmk_err_transform_failed
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
int crm_element_value_const_int(const xmlNode *data, const char *name, int *dest)
#define XML_ACL_ATTR_TAGv1
char * dump_xml_formatted_with_text(xmlNode *an_xml_node)
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
#define crm_config_warn(fmt...)
xmlNode * get_message_xml(xmlNode *msg, const char *field)
char * dump_xml_unformatted(xmlNode *an_xml_node)
int write_xml_file(xmlNode *xml_node, const char *filename, gboolean compress)
void copy_in_properties(xmlNode *target, xmlNode *src)
#define crm_log_xml_err(xml, text)
char * crm_element_value_copy(xmlNode *data, const char *name)
int update_validation(xmlNode **xml_blob, int *best, int max, gboolean transform, gboolean to_logs)
#define crm_perror(level, fmt, args...)
Log a system error message.
void strip_text_nodes(xmlNode *xml)
gboolean xml_has_children(const xmlNode *xml_root)
#define crm_err(fmt, args...)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#define XML_CIB_ATTR_WRITTEN
#define XML_ACL_TAG_ROLE_REFv1
int get_attr_value(const char *input, size_t offset, size_t max)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
xmlNode * find_xml_node(xmlNode *root, const char *search_path, gboolean must_find)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
void xml_accept_changes(xmlNode *xml)
int compare_version(const char *version1, const char *version2)
#define crm_log_xml_info(xml, text)
#define XML_ATTR_GENERATION_ADMIN
#define XML_NVPAIR_ATTR_VALUE
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
#define XML_ATTR_CRM_VERSION
void xml_log(int priority, const char *fmt,...) G_GNUC_PRINTF(2
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
char * crm_xml_escape(const char *text)
gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
gboolean update_xml_child(xmlNode *child, xmlNode *to_update)
int get_tag_name(const char *input, size_t offset, size_t max)
xmlNode * subtract_xml_object(xmlNode *parent, xmlNode *left, xmlNode *right, gboolean full, gboolean *changed, const char *marker)
#define XML_CIB_TAG_OBJ_REF
xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
#define crm_log_xml_trace(xml, text)
GHashTable * xml2list(xmlNode *parent)
bool xml_tracking_changes(xmlNode *xml)
gboolean crm_is_true(const char *s)
#define XML_ACL_TAG_ROLE_REF
const char * xml_latest_schema(void)
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
gboolean apply_xml_diff(xmlNode *old, xmlNode *diff, xmlNode **new)
#define XML_CIB_TAG_CONFIGURATION
char * crm_itoa(int an_int)
#define safe_str_eq(a, b)
int add_node_nocopy(xmlNode *parent, const char *name, xmlNode *child)
int in_upper_context(int depth, int context, xmlNode *xml_node)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
struct xml_private_s xml_private_t
gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)
const char * crm_element_value(xmlNode *data, const char *name)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void xml_remove_prop(xmlNode *obj, const char *name)
long long crm_int_helper(const char *text, char **end_text)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
#define crm_info(fmt, args...)
int get_schema_version(const char *name)
gboolean can_prune_leaf(xmlNode *xml_node)
bool xml_patch_versions(xmlNode *patchset, int add[3], int del[3])
enum crm_ais_msg_types type
bool xml_document_dirty(xmlNode *xml)