21 #include <sys/param.h>
23 #include <sys/types.h>
39 # include <libxml/parser.h>
40 # include <libxml/tree.h>
43 #define XML_BUFFER_SIZE 4096
44 #define XML_PARSER_DEBUG 0
47 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset);
75 typedef struct xml_private_s
84 typedef struct xml_acl_s {
91 static filter_t filter[] = {
100 static xmlNode *subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right, gboolean * changed);
101 static xmlNode *find_xml_comment(xmlNode * root, xmlNode * search_comment);
102 static int add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update);
103 static bool __xml_acl_check(xmlNode *xml,
const char *name,
enum xml_private_flags mode);
106 #define CHUNK_SIZE 1024
107 static inline bool TRACKING_CHANGES(xmlNode *xml)
109 if(xml == NULL || xml->doc == NULL || xml->doc->_private == NULL) {
117 #define buffer_print(buffer, max, offset, fmt, args...) do { \
120 rc = snprintf((buffer) + (offset), (max) - (offset), fmt, ##args); \
122 if(buffer && rc < 0) { \
123 crm_perror(LOG_ERR, "snprintf failed at offset %d", offset); \
124 (buffer)[(offset)] = 0; \
125 } else if(rc >= ((max) - (offset))) { \
127 (max) = QB_MAX(CHUNK_SIZE, (max) * 2); \
128 tmp = realloc_safe((buffer), (max) + 1); \
138 insert_prefix(
int options,
char **buffer,
int *offset,
int *max,
int depth)
141 size_t spaces = 2 * depth;
143 if ((*buffer) == NULL || spaces >= ((*max) - (*offset))) {
145 (*buffer) = realloc_safe((*buffer), (*max) + 1);
147 memset((*buffer) + (*offset),
' ', spaces);
153 set_parent_flag(xmlNode *xml,
long flag)
156 for(; xml; xml = xml->parent) {
169 set_doc_flag(xmlNode *xml,
long flag)
172 if(xml && xml->doc && xml->doc->_private){
182 __xml_node_dirty(xmlNode *xml)
189 __xml_node_clean(xmlNode *xml)
191 xmlNode *cIter = NULL;
198 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
199 __xml_node_clean(cIter);
204 crm_node_created(xmlNode *xml)
206 xmlNode *cIter = NULL;
209 if(p && TRACKING_CHANGES(xml)) {
212 __xml_node_dirty(xml);
215 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
216 crm_node_created(cIter);
222 crm_attr_dirty(xmlAttr *a)
224 xmlNode *parent = a->parent;
233 __xml_node_dirty(parent);
236 int get_tag_name(
const char *input,
size_t offset,
size_t max);
237 int get_attr_name(
const char *input,
size_t offset,
size_t max);
242 xmlNode * xml_node, xmlNode * parent);
244 int add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff);
246 static inline const char *
247 crm_attr_value(xmlAttr * attr)
249 if (attr == NULL || attr->children == NULL) {
252 return (
const char *)attr->children->content;
255 static inline xmlAttr *
256 crm_first_attr(xmlNode * xml)
261 return xml->properties;
264 #define XML_PRIVATE_MAGIC (long) 0x81726354
267 __xml_acl_free(
void *
data)
287 g_list_free_full(p->acls, __xml_acl_free);
291 if(p->deleted_paths) {
292 g_list_free_full(p->deleted_paths, free);
293 p->deleted_paths = NULL;
302 __xml_private_clean(p);
307 pcmkDeregisterNode(xmlNodePtr node)
309 __xml_private_free(node->_private);
313 pcmkRegisterNode(xmlNodePtr node)
318 case XML_ELEMENT_NODE:
319 case XML_DOCUMENT_NODE:
320 case XML_ATTRIBUTE_NODE:
321 case XML_COMMENT_NODE:
330 case XML_CDATA_SECTION_NODE:
334 crm_trace(
"Ignoring %p %d", node, node->type);
339 if(p && TRACKING_CHANGES(node)) {
344 __xml_node_dirty(node);
367 if(target == NULL || target->doc == NULL || target->doc->_private == NULL){
373 }
else if (tag == NULL && ref == NULL && xpath == NULL) {
378 p = target->doc->_private;
385 acl->xpath = strdup(xpath);
386 crm_trace(
"Using xpath: %s", acl->xpath);
393 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"//%s", tag);
403 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@id='%s'", ref);
407 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
" and ");
411 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@%s", attr);
419 acl->xpath = strdup(buffer);
420 crm_trace(
"Built xpath: %s", acl->xpath);
423 p->acls = g_list_append(p->acls, acl);
429 __xml_acl_parse_entry(xmlNode * acl_top, xmlNode * acl_entry, xmlNode *target)
431 xmlNode *child = NULL;
433 for (child = __xml_first_child(acl_entry); child; child = __xml_next(child)) {
434 const char *tag = crm_element_name(child);
441 crm_trace(
"Processing %s %p", tag, child);
450 xmlNode *role = NULL;
452 for (role = __xml_first_child(acl_top); role; role = __xml_next(role)) {
456 if (role_id && strcmp(ref_role, role_id) == 0) {
457 crm_debug(
"Unpacking referenced role: %s", role_id);
458 __xml_acl_parse_entry(acl_top, role, target);
475 crm_warn(
"Unknown ACL entry: %s/%s", tag, kind);
521 __xml_acl_apply(xmlNode *xml)
525 xmlXPathObjectPtr xpathObj = NULL;
528 p = xml->doc->_private;
529 crm_trace(
"Not applying ACLs for %s", p->user);
533 p = xml->doc->_private;
534 for(aIter = p->acls; aIter != NULL; aIter = aIter->next) {
535 int max = 0, lpc = 0;
539 max = numXpathResults(xpathObj);
541 for(lpc = 0; lpc < max; lpc++) {
546 crm_trace(
"Applying %x to %s for %s", acl->mode, path, acl->xpath);
548 #ifdef SUSE_ACL_COMPAT
549 if(is_not_set(p->flags, acl->mode)) {
553 crm_config_warn(
"Configuration element %s is matched by multiple ACL rules, only the first applies ('%s' wins over '%s')",
561 p->flags |= acl->mode;
564 crm_trace(
"Now enforcing ACL: %s (%d matches)", acl->xpath, max);
571 p = xml->doc->_private;
572 crm_info(
"Enforcing default ACL for %s to %s", p->user, crm_element_name(xml));
578 __xml_acl_unpack(xmlNode *source, xmlNode *target,
const char *user)
583 if(target == NULL || target->doc == NULL || target->doc->_private == NULL) {
587 p = target->doc->_private;
589 crm_trace(
"no acls needed for '%s'", user);
591 }
else if(p->acls == NULL) {
595 p->user = strdup(user);
598 xmlNode *child = NULL;
600 for (child = __xml_first_child(acls); child; child = __xml_next(child)) {
601 const char *tag = crm_element_name(child);
606 if(
id && strcmp(
id, user) == 0) {
608 __xml_acl_parse_entry(acls, child, target);
623 }
else if(is_set(allowed, requested)) {
642 __xml_purge_attributes(xmlNode *xml)
644 xmlNode *child = NULL;
645 xmlAttr *xIter = NULL;
646 bool readable_children = FALSE;
650 crm_trace(
"%s[@id=%s] is readable", crm_element_name(xml),
ID(xml));
654 xIter = crm_first_attr(xml);
655 while(xIter != NULL) {
656 xmlAttr *tmp = xIter;
657 const char *prop_name = (
const char *)xIter->name;
664 xmlUnsetProp(xml, tmp->name);
667 child = __xml_first_child(xml);
668 while ( child != NULL ) {
669 xmlNode *tmp = child;
671 child = __xml_next(child);
672 readable_children |= __xml_purge_attributes(tmp);
675 if(readable_children == FALSE) {
678 return readable_children;
685 xmlNode *target = NULL;
691 crm_trace(
"no acls needed for '%s'", user);
695 crm_trace(
"filtering copy of %p for '%s'", xml, user);
701 __xml_acl_unpack(acl_source, target, user);
703 __xml_acl_apply(target);
705 doc = target->doc->_private;
706 for(aIter = doc->acls; aIter != NULL && target; aIter = aIter->next) {
713 }
else if(acl->xpath) {
715 xmlXPathObjectPtr xpathObj =
xpath_search(target, acl->xpath);
717 max = numXpathResults(xpathObj);
718 for(lpc = 0; lpc < max; lpc++) {
721 crm_trace(
"Purging attributes from %s", acl->xpath);
722 if(__xml_purge_attributes(match) == FALSE && match == target) {
723 crm_trace(
"No access to the entire document for %s", user);
728 crm_trace(
"Enforced ACL %s (%d matches)", acl->xpath, max);
733 p = target->_private;
734 if(is_set(p->flags,
xpf_acl_deny) && __xml_purge_attributes(target) == FALSE) {
735 crm_trace(
"No access to the entire document for %s", user);
740 g_list_free_full(doc->acls, __xml_acl_free);
744 crm_trace(
"Ordinary user '%s' cannot access the CIB without any defined ACLs", doc->user);
757 __xml_acl_post_process(xmlNode * xml)
759 xmlNode *cIter = __xml_first_child(xml);
763 xmlAttr *xIter = NULL;
770 for (xIter = crm_first_attr(xml); xIter != NULL; xIter = xIter->next) {
771 const char *prop_name = (
const char *)xIter->name;
778 crm_trace(
"Creation of %s=%s is allowed", crm_element_name(xml),
ID(xml));
782 crm_trace(
"Cannot add new node %s at %s", crm_element_name(xml), path);
784 if(xml != xmlDocGetRootElement(xml->doc)) {
795 while (cIter != NULL) {
796 xmlNode *child = cIter;
797 cIter = __xml_next(cIter);
798 __xml_acl_post_process(child);
805 if(xml && xml->doc && xml->doc->_private){
820 __xml_acl_apply(xml);
821 __xml_acl_post_process(xml);
829 if(xml && xml->doc && xml->doc->_private){
841 crm_trace(
"Tracking changes%s to %p", enforce_acls?
" with ACLs":
"", xml);
844 if(acl_source == NULL) {
848 __xml_acl_unpack(acl_source, xml, user);
849 __xml_acl_apply(xml);
866 if(xml != NULL && xml->doc && xml->doc->_private) {
922 static int __xml_offset(xmlNode *xml)
925 xmlNode *cIter = NULL;
927 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
930 if(is_not_set(p->flags,
xpf_skip)) {
938 static int __xml_offset_no_deletions(xmlNode *xml)
941 xmlNode *cIter = NULL;
943 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
955 __xml_build_changes(xmlNode * xml, xmlNode *patchset)
957 xmlNode *cIter = NULL;
958 xmlAttr *pIter = NULL;
959 xmlNode *change = NULL;
966 if(__get_prefix(NULL, xml->parent, buffer, offset) > 0) {
967 int position = __xml_offset_no_deletions(xml);
980 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
981 xmlNode *attr = NULL;
992 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1017 xmlNode *result = NULL;
1022 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1025 p = pIter->_private;
1027 crm_xml_add(result, (
const char *)pIter->name, value);
1032 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1033 __xml_build_changes(cIter, patchset);
1037 if(patchset && is_set(p->flags,
xpf_moved)) {
1041 crm_trace(
"%s.%s moved to position %d", xml->name,
ID(xml), __xml_offset(xml));
1042 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1053 __xml_accept_changes(xmlNode * xml)
1055 xmlNode *cIter = NULL;
1056 xmlAttr *pIter = NULL;
1060 pIter = crm_first_attr(xml);
1062 while (pIter != NULL) {
1063 const xmlChar *name = pIter->name;
1065 p = pIter->_private;
1066 pIter = pIter->next;
1076 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1077 __xml_accept_changes(cIter);
1082 is_config_change(xmlNode *xml)
1089 p = config->_private;
1095 if(xml->doc && xml->doc->_private) {
1096 p = xml->doc->_private;
1097 for(gIter = p->deleted_paths; gIter; gIter = gIter->next) {
1098 char *path = gIter->data;
1110 xml_repair_v1_diff(xmlNode * last, xmlNode * next, xmlNode * local_diff, gboolean changed)
1113 xmlNode *cib = NULL;
1114 xmlNode *diff_child = NULL;
1116 const char *tag = NULL;
1118 const char *vfields[] = {
1124 if (local_diff == NULL) {
1129 tag =
"diff-removed";
1131 if (diff_child == NULL) {
1141 for(lpc = 0; last && lpc <
DIMOF(vfields); lpc++){
1145 if(changed || lpc == 2) {
1152 if (diff_child == NULL) {
1162 for(lpc = 0; next && lpc <
DIMOF(vfields); lpc++){
1169 xmlAttrPtr xIter = NULL;
1171 for (xIter = next->properties; xIter; xIter = xIter->next) {
1172 const char *p_name = (
const char *)xIter->name;
1175 xmlSetProp(cib, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
1183 xml_create_patchset_v1(xmlNode *source, xmlNode *target,
bool config,
bool suppress)
1189 xml_repair_v1_diff(source, target, patchset, config);
1196 xml_create_patchset_v2(xmlNode *source, xmlNode *target)
1204 xmlNode *patchset = NULL;
1205 const char *vfields[] = {
1217 doc = target->doc->_private;
1225 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1235 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1244 for(gIter = doc->deleted_paths; gIter; gIter = gIter->next) {
1251 __xml_build_changes(target, patchset);
1255 static gboolean patch_legacy_mode(
void)
1257 static gboolean init = TRUE;
1258 static gboolean legacy = FALSE;
1274 bool config = FALSE;
1275 xmlNode *patch = NULL;
1284 config = is_config_change(target);
1285 if(config_changed) {
1286 *config_changed = config;
1289 if(manage_version && config) {
1296 }
else if(manage_version) {
1303 if(patch_legacy_mode()) {
1312 crm_trace(
"Using patch format %d for version: %s", format, version);
1317 patch = xml_create_patchset_v1(source, target, config, FALSE);
1320 patch = xml_create_patchset_v2(source, target);
1323 crm_err(
"Unknown patch format: %d", format);
1334 const char *version = NULL;
1335 char *digest = NULL;
1337 if (patch == NULL || source == NULL || target == NULL) {
1346 if (format > 1 && with_digest == FALSE) {
1360 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
1361 const char *prefix, xmlNode *
data,
int depth,
int options);
1367 xmlNode *child = NULL;
1368 xmlNode *added = NULL;
1369 xmlNode *removed = NULL;
1370 gboolean is_first = TRUE;
1372 int add[] = { 0, 0, 0 };
1373 int del[] = { 0, 0, 0 };
1375 const char *fmt = NULL;
1376 const char *digest = NULL;
1379 static struct qb_log_callsite *patchset_cs = NULL;
1381 if (patchset_cs == NULL) {
1382 patchset_cs = qb_log_callsite_get(
function, __FILE__,
"xml-patchset", log_level, __LINE__, 0);
1385 if (patchset == NULL) {
1389 }
else if (log_level == 0) {
1399 if (add[2] != del[2] || add[1] != del[1] || add[0] != del[0]) {
1401 "Diff: --- %d.%d.%d %s", del[0], del[1], del[2], fmt);
1403 "Diff: +++ %d.%d.%d %s", add[0], add[1], add[2], digest);
1405 }
else if (patchset != NULL && (add[0] || add[1] || add[2])) {
1407 "%s: Local-only Change: %d.%d.%d",
function ?
function :
"",
1408 add[0], add[1], add[2]);
1413 xmlNode *change = NULL;
1415 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
1420 }
else if(strcmp(op,
"create") == 0) {
1421 int lpc = 0, max = 0;
1424 max = strlen(prefix);
1425 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1428 for(lpc = 2; lpc < max; lpc++) {
1432 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1436 }
else if(strcmp(op,
"move") == 0) {
1439 }
else if(strcmp(op,
"modify") == 0) {
1447 buffer_unset[0] = 0;
1448 for (child = __xml_first_child(clist); child != NULL; child = __xml_next(child)) {
1453 }
else if(strcmp(op,
"set") == 0) {
1459 o_set += snprintf(buffer_set + o_set,
XML_BUFFER_SIZE - o_set,
"@%s=%s", name, value);
1461 }
else if(strcmp(op,
"unset") == 0) {
1463 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
", ");
1465 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
"@%s", name);
1469 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"+ %s: %s", xpath, buffer_set);
1472 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s: %s", xpath, buffer_unset);
1475 }
else if(strcmp(op,
"delete") == 0) {
1482 if (log_level < LOG_DEBUG ||
function == NULL) {
1487 for (child = __xml_first_child(removed); child != NULL; child = __xml_next(child)) {
1499 for (child = __xml_first_child(added); child != NULL; child = __xml_next(child)) {
1519 doc = xml->doc->_private;
1524 for(gIter = doc->deleted_paths; gIter; gIter = gIter->next) {
1525 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s", (
char*)gIter->data);
1535 xmlNode *top = NULL;
1542 crm_trace(
"Accepting changes to %p", xml);
1543 doc = xml->doc->_private;
1544 top = xmlDocGetRootElement(xml->doc);
1546 __xml_private_clean(xml->doc->_private);
1554 __xml_accept_changes(top);
1558 find_element(xmlNode *haystack, xmlNode *needle)
1561 return (needle->type == XML_COMMENT_NODE)?
1562 find_xml_comment(haystack, needle)
1563 :
find_entity(haystack, crm_element_name(needle),
ID(needle));
1568 __subtract_xml_object(xmlNode * target, xmlNode * patch)
1570 xmlNode *patch_child = NULL;
1571 xmlNode *cIter = NULL;
1572 xmlAttrPtr xIter = NULL;
1575 const char *name = NULL;
1576 const char *value = NULL;
1578 if (target == NULL || patch == NULL) {
1582 if (target->type == XML_COMMENT_NODE) {
1585 subtract_xml_comment(target->parent, target, patch, &dummy);
1588 name = crm_element_name(target);
1596 if (value != NULL && strcmp(value,
"removed:top") == 0) {
1597 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
1603 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1604 const char *p_name = (
const char *)xIter->name;
1613 cIter = __xml_first_child(target);
1615 xmlNode *target_child = cIter;
1617 cIter = __xml_next(cIter);
1618 patch_child = find_element(patch, target_child);
1619 __subtract_xml_object(target_child, patch_child);
1625 __add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * patch)
1627 xmlNode *patch_child = NULL;
1628 xmlNode *target_child = NULL;
1629 xmlAttrPtr xIter = NULL;
1631 const char *
id = NULL;
1632 const char *name = NULL;
1633 const char *value = NULL;
1635 if (patch == NULL) {
1637 }
else if (parent == NULL && target == NULL) {
1645 && strcmp(value,
"added:top") == 0) {
1647 name = crm_element_name(patch);
1648 crm_trace(
"We are the root of the addition: %s.id=%s", name,
id);
1652 }
else if(target == NULL) {
1654 name = crm_element_name(patch);
1655 crm_err(
"Could not locate: %s.id=%s", name,
id);
1659 if (target->type == XML_COMMENT_NODE) {
1660 add_xml_comment(parent, target, patch);
1663 name = crm_element_name(target);
1668 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1669 const char *p_name = (
const char *)xIter->name;
1677 for (patch_child = __xml_first_child(patch); patch_child != NULL;
1678 patch_child = __xml_next(patch_child)) {
1680 target_child = find_element(target, patch_child);
1681 __add_xml_object(target, target_child, patch_child);
1697 find_patch_xml_node(xmlNode *patchset,
int format,
bool added,
1698 xmlNode **patch_node)
1705 label = added?
"diff-added" :
"diff-removed";
1708 if (cib_node != NULL) {
1709 *patch_node = cib_node;
1713 label = added?
"target" :
"source";
1718 crm_warn(
"Unknown patch format: %d", format);
1729 xmlNode *tmp = NULL;
1731 const char *vfields[] = {
1741 if (!find_patch_xml_node(patchset, format, FALSE, &tmp)) {
1745 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1747 crm_trace(
"Got %d for del[%s]", del[lpc], vfields[lpc]);
1752 if (!find_patch_xml_node(patchset, format, TRUE, &tmp)) {
1756 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1758 crm_trace(
"Got %d for add[%s]", add[lpc], vfields[lpc]);
1766 xml_patch_version_check(xmlNode *xml, xmlNode *patchset,
int format)
1769 bool changed = FALSE;
1771 int this[] = { 0, 0, 0 };
1772 int add[] = { 0, 0, 0 };
1773 int del[] = { 0, 0, 0 };
1775 const char *vfields[] = {
1781 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1783 crm_trace(
"Got %d for this[%s]",
this[lpc], vfields[lpc]);
1784 if (
this[lpc] < 0) {
1792 add[2] =
this[2] + 1;
1793 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1794 del[lpc] =
this[lpc];
1799 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1800 if(
this[lpc] < del[lpc]) {
1801 crm_debug(
"Current %s is too low (%d.%d.%d < %d.%d.%d --> %d.%d.%d)", vfields[lpc],
1802 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2]);
1805 }
else if(
this[lpc] > del[lpc]) {
1806 crm_info(
"Current %s is too high (%d.%d.%d > %d.%d.%d --> %d.%d.%d) %p", vfields[lpc],
1807 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2], patchset);
1813 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1814 if(add[lpc] > del[lpc]) {
1819 if(changed == FALSE) {
1820 crm_notice(
"Versions did not change in patch %d.%d.%d", add[0], add[1], add[2]);
1824 crm_debug(
"Can apply patch %d.%d.%d to %d.%d.%d",
1825 add[0], add[1], add[2],
this[0],
this[1],
this[2]);
1830 xml_apply_patchset_v1(xmlNode *xml, xmlNode *patchset,
bool check_version)
1833 int root_nodes_seen = 0;
1836 xmlNode *child_diff = NULL;
1837 xmlNode *added =
find_xml_node(patchset,
"diff-added", FALSE);
1838 xmlNode *removed =
find_xml_node(patchset,
"diff-removed", FALSE);
1842 for (child_diff = __xml_first_child(removed); child_diff != NULL;
1843 child_diff = __xml_next(child_diff)) {
1844 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1845 if (root_nodes_seen == 0) {
1846 __subtract_xml_object(xml, child_diff);
1851 if (root_nodes_seen > 1) {
1852 crm_err(
"(-) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1856 root_nodes_seen = 0;
1859 xmlNode *child_diff = NULL;
1861 for (child_diff = __xml_first_child(added); child_diff != NULL;
1862 child_diff = __xml_next(child_diff)) {
1863 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1864 if (root_nodes_seen == 0) {
1865 __add_xml_object(NULL, xml, child_diff);
1871 if (root_nodes_seen > 1) {
1872 crm_err(
"(+) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1884 __first_xml_child_match(xmlNode *parent,
const char *name,
const char *
id)
1886 xmlNode *cIter = NULL;
1888 for (cIter = __xml_first_child(parent); cIter != NULL; cIter = __xml_next(cIter)) {
1889 if(strcmp((
const char *)cIter->name, name) != 0) {
1892 const char *cid =
ID(cIter);
1893 if(cid == NULL || strcmp(cid,
id) != 0) {
1903 __xml_find_path(xmlNode *top,
const char *key)
1905 xmlNode *target = (xmlNode*)top->doc;
1909 char *current = strdup(key);
1914 rc = sscanf (current,
"/%[^/]%s", section, remainder);
1924 }
else if(tag && section) {
1925 int f = sscanf (section,
"%[^[][@id='%[^']", tag,
id);
1929 target = __first_xml_child_match(target, tag, NULL);
1932 target = __first_xml_child_match(target, tag,
id);
1940 if(rc == 1 || target == NULL) {
1945 char *tmp = current;
1946 current = remainder;
1953 char *path = (
char *)xmlGetNodePath(target);
1955 crm_trace(
"Found %s for %s", path, key);
1970 xml_apply_patchset_v2(xmlNode *xml, xmlNode *patchset,
bool check_version)
1973 xmlNode *change = NULL;
1974 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
1975 xmlNode *match = NULL;
1979 crm_trace(
"Processing %s %s", change->name, op);
1987 match = __xml_find_path(xml, xpath);
1989 crm_trace(
"Performing %s on %s with %p", op, xpath, match);
1991 if(match == NULL && strcmp(op,
"delete") == 0) {
1992 crm_debug(
"No %s match for %s in %p", op, xpath, xml->doc);
1995 }
else if(match == NULL) {
1996 crm_err(
"No %s match for %s in %p", op, xpath, xml->doc);
2000 }
else if(strcmp(op,
"create") == 0) {
2002 xmlNode *child = NULL;
2003 xmlNode *match_child = NULL;
2005 match_child = match->children;
2008 while(match_child && position != __xml_offset(match_child)) {
2009 match_child = match_child->next;
2012 child = xmlDocCopyNode(change->children, match->doc, 1);
2014 crm_trace(
"Adding %s at position %d", child->name, position);
2015 xmlAddPrevSibling(match_child, child);
2017 }
else if(match->last) {
2018 crm_trace(
"Adding %s at position %d (end)", child->name, position);
2019 xmlAddNextSibling(match->last, child);
2022 crm_trace(
"Adding %s at position %d (first)", child->name, position);
2024 xmlAddChild(match, child);
2026 crm_node_created(child);
2028 }
else if(strcmp(op,
"move") == 0) {
2032 if(position != __xml_offset(match)) {
2033 xmlNode *match_child = NULL;
2036 if(p > __xml_offset(match)) {
2041 match_child = match->parent->children;
2043 while(match_child && p != __xml_offset(match_child)) {
2044 match_child = match_child->next;
2047 crm_trace(
"Moving %s to position %d (was %d, prev %p, %s %p)",
2048 match->name, position, __xml_offset(match), match->prev,
2049 match_child?
"next":
"last", match_child?match_child:match->parent->last);
2052 xmlAddPrevSibling(match_child, match);
2056 xmlAddNextSibling(match->parent->last, match);
2060 crm_trace(
"%s is already in position %d", match->name, position);
2063 if(position != __xml_offset(match)) {
2064 crm_err(
"Moved %s.%d to position %d instead of %d (%p)",
2065 match->name,
ID(match), __xml_offset(match), position, match->prev);
2069 }
else if(strcmp(op,
"delete") == 0) {
2072 }
else if(strcmp(op,
"modify") == 0) {
2073 xmlAttr *pIter = crm_first_attr(match);
2080 while(pIter != NULL) {
2081 const char *name = (
const char *)pIter->name;
2083 pIter = pIter->next;
2087 for (pIter = crm_first_attr(attrs); pIter != NULL; pIter = pIter->next) {
2088 const char *name = (
const char *)pIter->name;
2095 crm_err(
"Unknown operation: %s", op);
2106 xmlNode *old = NULL;
2109 if(patchset == NULL) {
2117 rc = xml_patch_version_check(xml, patchset, format);
2131 rc = xml_apply_patchset_v1(xml, patchset, check_version);
2134 rc = xml_apply_patchset_v2(xml, patchset, check_version);
2137 crm_err(
"Unknown patch format: %d", format);
2143 static struct qb_log_callsite *digest_cs = NULL;
2145 char *new_digest = NULL;
2148 if (digest_cs == NULL) {
2150 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
2156 crm_info(
"v%d digest mis-match: expected %s, calculated %s", format, digest, new_digest);
2159 if (digest_cs && digest_cs->targets) {
2165 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
2169 crm_trace(
"v%d digest matched: expected %s, calculated %s", format, digest, new_digest);
2181 xmlNode *a_child = NULL;
2182 const char *name =
"NULL";
2185 name = crm_element_name(root);
2188 if (search_path == NULL) {
2189 crm_warn(
"Will never find <NULL>");
2193 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
2194 if (strcmp((
const char *)a_child->name, search_path) == 0) {
2201 crm_warn(
"Could not find %s in %s.", search_path, name);
2202 }
else if (root != NULL) {
2203 crm_trace(
"Could not find %s in %s.", search_path, name);
2205 crm_trace(
"Could not find %s in <NULL>.", search_path);
2214 xmlNode *a_child = NULL;
2216 for (a_child = __xml_first_child(parent); a_child != NULL; a_child = __xml_next(a_child)) {
2218 if (node_name == NULL || strcmp((
const char *)a_child->name, node_name) == 0) {
2219 const char *cid =
ID(a_child);
2220 if (
id == NULL || (cid != NULL && strcmp(
id, cid) == 0)) {
2226 crm_trace(
"node <%s id=%s> not found in %s.", node_name,
id, crm_element_name(parent));
2234 crm_warn(
"No node to copy properties from");
2236 }
else if (target == NULL) {
2237 crm_err(
"No node to copy properties into");
2240 xmlAttrPtr pIter = NULL;
2242 for (pIter = crm_first_attr(src); pIter != NULL; pIter = pIter->next) {
2243 const char *p_name = (
const char *)pIter->name;
2244 const char *p_value = crm_attr_value(pIter);
2257 xmlNode *child = NULL;
2258 xmlAttrPtr pIter = NULL;
2260 for (pIter = crm_first_attr(target); pIter != NULL; pIter = pIter->next) {
2261 const char *p_name = (
const char *)pIter->name;
2262 const char *p_value = crm_attr_value(pIter);
2266 for (child = __xml_first_child(target); child != NULL; child = __xml_next(child)) {
2279 const char *old_value = NULL;
2281 if (value == NULL || name == NULL) {
2287 if (old_value == NULL) {
2289 goto set_unexpanded;
2291 }
else if (strstr(value, name) != value) {
2292 goto set_unexpanded;
2295 name_len = strlen(name);
2296 value_len = strlen(value);
2297 if (value_len < (name_len + 2)
2298 || value[name_len] !=
'+' || (value[name_len + 1] !=
'+' && value[name_len + 1] !=
'=')) {
2299 goto set_unexpanded;
2305 if (old_value != value) {
2309 if (value[name_len + 1] !=
'+') {
2310 const char *offset_s = value + (name_len + 2);
2314 int_value += offset;
2324 if (old_value == value) {
2341 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2342 xmlDocSetRootElement(doc, node);
2343 xmlSetTreeDoc(node, doc);
2351 xmlNode *child = NULL;
2354 CRM_CHECK(src_node != NULL,
return NULL);
2356 child = xmlDocCopyNode(src_node, doc, 1);
2357 xmlAddChild(parent, child);
2358 crm_node_created(child);
2381 xmlNode *parent = xml;
2385 if(docp->acls == NULL) {
2386 crm_trace(
"Ordinary user %s cannot access the CIB without any defined ACLs", docp->user);
2391 offset = __get_prefix(NULL, xml, buffer, offset);
2393 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"[@%s]", name);
2403 xmlAttr *attr = xmlHasProp(xml, (
const xmlChar *)name);
2410 while(parent && parent->_private) {
2412 if(__xml_acl_mode_test(p->flags, mode)) {
2416 crm_trace(
"%x access denied to %s: parent", mode, buffer);
2420 parent = parent->parent;
2423 crm_trace(
"%x access denied to %s: default", mode, buffer);
2437 xmlAttr *attr = NULL;
2442 if (value == NULL) {
2445 #if XML_PARANOIA_CHECKS
2447 const char *old_value = NULL;
2452 CRM_CHECK(old_value != value,
crm_err(
"Cannot reset %s with crm_xml_add(%s)", name, value);
2457 if(TRACKING_CHANGES(node)) {
2460 if(old == NULL || value == NULL || strcmp(old, value) != 0) {
2465 if(dirty && __xml_acl_check(node, name,
xpf_acl_create) == FALSE) {
2466 crm_trace(
"Cannot add %s=%s to %s", name, value, node->name);
2470 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2472 crm_attr_dirty(attr);
2475 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2476 return (
char *)attr->children->content;
2483 xmlAttr *attr = NULL;
2484 const char *old_value = NULL;
2487 CRM_CHECK(name != NULL && name[0] != 0,
return NULL);
2492 CRM_CHECK(old_value != value,
return value);
2496 crm_trace(
"Cannot replace %s=%s to %s", name, value, node->name);
2499 }
else if (old_value != NULL && value == NULL) {
2503 }
else if (value == NULL) {
2507 if(TRACKING_CHANGES(node)) {
2508 if(old_value == NULL || value == NULL || strcmp(old_value, value) != 0) {
2513 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2515 crm_attr_dirty(attr);
2517 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2518 return (
char *)attr->children->content;
2525 const char *added =
crm_xml_add(node, name, number);
2535 xmlNode *node = NULL;
2537 if (name == NULL || name[0] == 0) {
2538 CRM_CHECK(name != NULL && name[0] == 0,
return NULL);
2542 if (parent == NULL) {
2543 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2544 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2545 xmlDocSetRootElement(doc, node);
2549 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2550 xmlAddChild(parent, node);
2552 crm_node_created(node);
2557 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset)
2559 const char *
id =
ID(xml);
2561 if(offset == 0 && prefix == NULL && xml->parent) {
2562 offset = __get_prefix(NULL, xml->parent, buffer, offset);
2566 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s[@id='%s']", (
const char *)xml->name,
id);
2567 }
else if(xml->name) {
2568 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s", (
const char *)xml->name);
2580 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
2581 return strdup(buffer);
2589 if (child != NULL) {
2590 xmlNode *top = NULL;
2591 xmlDoc *doc = child->doc;
2595 top = xmlDocGetRootElement(doc);
2598 if (doc != NULL && top == child) {
2602 }
else if(__xml_acl_check(child, NULL,
xpf_acl_write) == FALSE) {
2606 __get_prefix(NULL, child, buffer, offset);
2607 crm_trace(
"Cannot remove %s %x", buffer, p->flags);
2611 if(doc && TRACKING_CHANGES(child) && is_not_set(p->flags,
xpf_created)) {
2615 if(__get_prefix(NULL, child, buffer, offset) > 0) {
2616 crm_trace(
"Deleting %s %p from %p", buffer, child, doc);
2618 p->deleted_paths = g_list_append(p->deleted_paths, strdup(buffer));
2626 xmlUnlinkNode(child);
2635 xmlDoc *doc = xmlNewDoc((
const xmlChar *)
"1.0");
2636 xmlNode *copy = xmlDocCopyNode(src, doc, 1);
2638 xmlDocSetRootElement(doc, copy);
2639 xmlSetTreeDoc(copy, doc);
2644 crm_xml_err(
void *ctx,
const char *msg, ...)
2645 G_GNUC_PRINTF(2, 3);
2648 crm_xml_err(
void *ctx, const
char *msg, ...)
2653 static int buffer_len = 0;
2654 static char *buffer = NULL;
2655 static struct qb_log_callsite *xml_error_cs = NULL;
2657 va_start(args, msg);
2658 len = vasprintf(&buf, msg, args);
2660 if(xml_error_cs == NULL) {
2661 xml_error_cs = qb_log_callsite_get(
2665 if (strchr(buf,
'\n')) {
2668 crm_err(
"XML Error: %s%s", buffer, buf);
2671 crm_err(
"XML Error: %s", buf);
2673 if (xml_error_cs && xml_error_cs->targets) {
2674 crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__,
"xml library error", TRUE, TRUE);
2679 }
else if (buffer == NULL) {
2685 buffer = realloc_safe(buffer, 1 + buffer_len + len);
2686 memcpy(buffer + buffer_len, buf, len);
2688 buffer[buffer_len] = 0;
2698 xmlNode *xml = NULL;
2699 xmlDocPtr output = NULL;
2700 xmlParserCtxtPtr ctxt = NULL;
2701 xmlErrorPtr last_error = NULL;
2703 if (input == NULL) {
2704 crm_err(
"Can't parse NULL input");
2709 ctxt = xmlNewParserCtxt();
2714 xmlCtxtResetLastError(ctxt);
2715 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2718 xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL,
2719 XML_PARSE_NOBLANKS | XML_PARSE_RECOVER);
2721 xml = xmlDocGetRootElement(output);
2723 last_error = xmlCtxtGetLastError(ctxt);
2724 if (last_error && last_error->code != XML_ERR_OK) {
2730 crm_warn(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2731 last_error->domain, last_error->level, last_error->code, last_error->message);
2733 if (last_error->code == XML_ERR_DOCUMENT_EMPTY) {
2736 }
else if (last_error->code != XML_ERR_DOCUMENT_END) {
2737 crm_err(
"Couldn't%s parse %d chars: %s", xml ?
" fully" :
"", (
int)strlen(input),
2744 int len = strlen(input);
2748 crm_warn(
"Parse error[+%.3d]: %.80s", lpc, input+lpc);
2756 xmlFreeParserCtxt(ctxt);
2763 size_t data_length = 0;
2764 size_t read_chars = 0;
2766 char *xml_buffer = NULL;
2767 xmlNode *xml_obj = NULL;
2777 xml_buffer = realloc_safe(xml_buffer, next);
2778 read_chars = fread(xml_buffer + data_length, 1,
XML_BUFFER_SIZE, stdin);
2779 data_length += read_chars;
2780 }
while (read_chars > 0);
2782 if (data_length == 0) {
2783 crm_warn(
"No XML supplied on stdin");
2788 xml_buffer[data_length] =
'\0';
2798 decompress_file(
const char *filename)
2800 char *buffer = NULL;
2804 size_t length = 0, read_len = 0;
2806 BZFILE *bz_file = NULL;
2807 FILE *input = fopen(filename,
"r");
2809 if (input == NULL) {
2810 crm_perror(LOG_ERR,
"Could not open %s for reading", filename);
2814 bz_file = BZ2_bzReadOpen(&rc, input, 0, 0, NULL, 0);
2817 BZ2_bzReadClose(&rc, bz_file);
2822 while (rc == BZ_OK) {
2824 read_len = BZ2_bzRead(&rc, bz_file, buffer + length,
XML_BUFFER_SIZE);
2826 crm_trace(
"Read %ld bytes from file: %d", (
long)read_len, rc);
2828 if (rc == BZ_OK || rc == BZ_STREAM_END) {
2833 buffer[length] =
'\0';
2835 if (rc != BZ_STREAM_END) {
2836 crm_err(
"Couldn't read compressed xml from file");
2841 BZ2_bzReadClose(&rc, bz_file);
2845 crm_err(
"Cannot read compressed files:" " bzlib was not available at compile time");
2853 xmlNode *iter = xml->children;
2856 xmlNode *next = iter->next;
2858 switch (iter->type) {
2861 xmlUnlinkNode(iter);
2865 case XML_ELEMENT_NODE:
2882 xmlNode *xml = NULL;
2883 xmlDocPtr output = NULL;
2884 gboolean uncompressed = TRUE;
2885 xmlParserCtxtPtr ctxt = NULL;
2886 xmlErrorPtr last_error = NULL;
2887 static int xml_options = XML_PARSE_NOBLANKS | XML_PARSE_RECOVER;
2890 ctxt = xmlNewParserCtxt();
2895 xmlCtxtResetLastError(ctxt);
2896 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2903 if (filename == NULL) {
2905 output = xmlCtxtReadFd(ctxt, STDIN_FILENO,
"unknown.xml", NULL, xml_options);
2907 }
else if (uncompressed) {
2908 output = xmlCtxtReadFile(ctxt, filename, NULL, xml_options);
2911 char *input = decompress_file(filename);
2913 output = xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL, xml_options);
2917 if (output && (xml = xmlDocGetRootElement(output))) {
2921 last_error = xmlCtxtGetLastError(ctxt);
2922 if (last_error && last_error->code != XML_ERR_OK) {
2928 crm_err(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2929 last_error->domain, last_error->level, last_error->code, last_error->message);
2931 if (last_error && last_error->code != XML_ERR_OK) {
2932 crm_err(
"Couldn't%s parse %s", xml ?
" fully" :
"", filename);
2939 xmlFreeParserCtxt(ctxt);
2954 time_t now = time(NULL);
2955 char *now_str = ctime(&now);
2962 write_xml_stream(xmlNode * xml_node,
const char *filename, FILE * stream, gboolean compress)
2965 char *buffer = NULL;
2966 unsigned int out = 0;
2970 crm_trace(
"Writing XML out to %s", filename);
2971 if (xml_node == NULL) {
2972 crm_err(
"Cannot write NULL to %s", filename);
2987 unsigned int in = 0;
2988 BZFILE *bz_file = NULL;
2990 bz_file = BZ2_bzWriteOpen(&rc, stream, 5, 0, 30);
2992 crm_err(
"bzWriteOpen failed: %d", rc);
2994 BZ2_bzWrite(&rc, bz_file, buffer, strlen(buffer));
2996 crm_err(
"bzWrite() failed: %d", rc);
3001 BZ2_bzWriteClose(&rc, bz_file, 0, &in, &out);
3003 crm_err(
"bzWriteClose() failed: %d", rc);
3006 crm_trace(
"%s: In: %d, out: %d", filename, in, out);
3010 crm_err(
"Cannot write compressed files:" " bzlib was not available at compile time");
3015 res = fprintf(stream,
"%s", buffer);
3017 crm_perror(LOG_ERR,
"Cannot write output to %s", filename);
3024 if (fflush(stream) != 0) {
3025 crm_perror(LOG_ERR,
"fflush for %s failed", filename);
3030 if (fsync(fileno(stream)) < 0 && errno != EROFS && errno != EINVAL) {
3031 crm_perror(LOG_ERR,
"fsync for %s failed", filename);
3037 crm_trace(
"Saved %d bytes to the Cib as XML", res);
3044 write_xml_fd(xmlNode * xml_node,
const char *filename,
int fd, gboolean compress)
3046 FILE *stream = NULL;
3049 stream = fdopen(fd,
"w");
3050 return write_xml_stream(xml_node, filename, stream, compress);
3056 FILE *stream = NULL;
3058 stream = fopen(filename,
"w");
3060 return write_xml_stream(xml_node, filename, stream, compress);
3068 return __xml_first_child(tmp);
3081 crm_xml_escape_shuffle(
char *text,
int start,
int *length,
const char *replace)
3084 int offset = strlen(replace) - 1;
3087 text = realloc_safe(text, *length);
3089 for (lpc = (*length) - 1; lpc > (start + offset); lpc--) {
3090 text[lpc] = text[lpc - offset];
3093 memcpy(text + start, replace, offset + 1);
3102 int length = 1 + strlen(text);
3103 char *copy = strdup(text);
3120 for (index = 0; index < length; index++) {
3121 switch (copy[index]) {
3125 copy = crm_xml_escape_shuffle(copy, index, &length,
"<");
3129 copy = crm_xml_escape_shuffle(copy, index, &length,
">");
3133 copy = crm_xml_escape_shuffle(copy, index, &length,
""");
3137 copy = crm_xml_escape_shuffle(copy, index, &length,
"'");
3141 copy = crm_xml_escape_shuffle(copy, index, &length,
"&");
3146 copy = crm_xml_escape_shuffle(copy, index, &length,
" ");
3151 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\n");
3155 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\r");
3165 if(copy[index] <
' ' || copy[index] >
'~') {
3169 copy = crm_xml_escape_shuffle(copy, index, &length, replace);
3183 dump_xml_attr(xmlAttrPtr attr,
int options,
char **buffer,
int *offset,
int *max)
3185 char *p_value = NULL;
3186 const char *p_name = NULL;
3190 if (attr == NULL || attr->children == NULL) {
3199 p_name = (
const char *)attr->name;
3201 buffer_print(*buffer, *max, *offset,
" %s=\"%s\"", p_name, p_value);
3206 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
3207 const char *prefix, xmlNode *
data,
int depth,
int options)
3211 const char *name = NULL;
3212 const char *hidden = NULL;
3214 xmlNode *child = NULL;
3215 xmlAttrPtr pIter = NULL;
3221 name = crm_element_name(data);
3224 char *buffer = NULL;
3226 insert_prefix(options, &buffer, &offset, &max, depth);
3228 if (data->type == XML_COMMENT_NODE) {
3229 buffer_print(buffer, max, offset,
"<!--%s-->", data->content);
3235 for (pIter = crm_first_attr(data); pIter != NULL; pIter = pIter->next) {
3237 const char *p_name = (
const char *)pIter->name;
3238 const char *p_value = crm_attr_value(pIter);
3239 char *p_copy = NULL;
3248 }
else if (hidden != NULL && p_name[0] != 0 && strstr(hidden, p_name) != NULL) {
3249 p_copy = strdup(
"*****");
3255 buffer_print(buffer, max, offset,
" %s=\"%s\"", p_name, p_copy);
3270 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3274 if(data->type == XML_COMMENT_NODE) {
3284 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3290 char *buffer = NULL;
3292 insert_prefix(options, &buffer, &offset, &max, depth);
3295 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3301 __xml_log_change_element(
int log_level,
const char *file,
const char *
function,
int line,
3302 const char *prefix, xmlNode * data,
int depth,
int options)
3305 char *prefix_m = NULL;
3306 xmlNode *child = NULL;
3307 xmlAttrPtr pIter = NULL;
3315 prefix_m = strdup(prefix);
3320 __xml_log_element(log_level, file,
function, line,
3323 }
else if(is_set(p->flags,
xpf_dirty)) {
3324 char *spaces = calloc(80, 1);
3325 int s_count = 0, s_max = 80;
3326 char *prefix_del = NULL;
3327 char *prefix_moved = NULL;
3328 const char *
flags = prefix;
3330 insert_prefix(options, &spaces, &s_count, &s_max, depth);
3331 prefix_del = strdup(prefix);
3332 prefix_del[0] =
'-';
3333 prefix_del[1] =
'-';
3334 prefix_moved = strdup(prefix);
3335 prefix_moved[1] =
'~';
3338 flags = prefix_moved;
3343 __xml_log_element(log_level, file,
function, line,
3346 for (pIter = crm_first_attr(data); pIter != NULL; pIter = pIter->next) {
3347 const char *aname = (
const char*)pIter->name;
3349 p = pIter->_private;
3354 "%s %s @%s=%s", flags, spaces, aname, value);
3356 }
else if(is_set(p->flags,
xpf_dirty)) {
3365 }
else if(is_set(p->flags,
xpf_moved)) {
3366 flags = prefix_moved;
3372 "%s %s @%s=%s", flags, spaces, aname, value);
3379 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3380 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3383 __xml_log_element(log_level, file,
function, line,
3387 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3388 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3398 const char *prefix, xmlNode * data,
int depth,
int options)
3400 xmlNode *a_child = NULL;
3402 char *prefix_m = NULL;
3404 if (prefix == NULL) {
3411 "No data to dump as XML");
3416 __xml_log_change_element(log_level, file,
function, line, prefix, data, depth, options);
3424 prefix_m = strdup(prefix);
3431 prefix_m = strdup(prefix);
3440 for (a_child = __xml_first_child(data); a_child != NULL; a_child = __xml_next(a_child)) {
3441 log_data_element(log_level, file,
function, line, prefix, a_child, depth + 1, options);
3444 __xml_log_element(log_level, file,
function, line, prefix, data, depth,
3451 dump_filtered_xml(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max)
3454 xmlAttrPtr xIter = NULL;
3455 static int filter_len =
DIMOF(filter);
3457 for (lpc = 0; options && lpc < filter_len; lpc++) {
3458 filter[lpc].found = FALSE;
3461 for (xIter = crm_first_attr(data); xIter != NULL; xIter = xIter->next) {
3463 const char *p_name = (
const char *)xIter->name;
3465 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
3466 if (filter[lpc].found == FALSE && strcmp(p_name, filter[lpc].
string) == 0) {
3467 filter[lpc].found = TRUE;
3473 if (skip == FALSE) {
3474 dump_xml_attr(xIter, options, buffer, offset, max);
3480 dump_xml_element(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3482 const char *name = NULL;
3493 if (*buffer == NULL) {
3498 name = crm_element_name(data);
3501 insert_prefix(options, buffer, offset, max, depth);
3505 dump_filtered_xml(data, options, buffer, offset, max);
3508 xmlAttrPtr xIter = NULL;
3510 for (xIter = crm_first_attr(data); xIter != NULL; xIter = xIter->next) {
3511 dump_xml_attr(xIter, options, buffer, offset, max);
3515 if (data->children == NULL) {
3526 if (data->children) {
3527 xmlNode *xChild = NULL;
3528 for(xChild = data->children; xChild != NULL; xChild = xChild->next) {
3529 crm_xml_dump(xChild, options, buffer, offset, max, depth + 1);
3532 insert_prefix(options, buffer, offset, max, depth);
3535 if (options & xml_log_option_formatted) {
3542 dump_xml_text(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3553 if (*buffer == NULL) {
3558 insert_prefix(options, buffer, offset, max, depth);
3560 buffer_print(*buffer, *max, *offset,
"%s", data->content);
3562 if (options & xml_log_option_formatted) {
3569 dump_xml_comment(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3580 if (*buffer == NULL) {
3585 insert_prefix(options, buffer, offset, max, depth);
3588 buffer_print(*buffer, *max, *offset,
"%s", data->content);
3591 if (options & xml_log_option_formatted) {
3597 crm_xml_dump(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3605 if (is_not_set(options, xml_log_option_filtered)) {
3620 xmlBuffer *xml_buffer = NULL;
3628 xml_buffer = xmlBufferCreate();
3639 xmlBufferSetAllocationScheme(xml_buffer, XML_BUFFER_ALLOC_DOUBLEIT);
3641 *max = xmlNodeDump(xml_buffer, doc, data, 0, (options & xml_log_option_formatted));
3643 *buffer = strdup((
char *)xml_buffer->content);
3647 if ((now + 1) < next) {
3649 crm_err(
"xmlNodeDump() -> %dbytes took %ds", *max, next - now);
3652 xmlBufferFree(xml_buffer);
3657 switch(data->type) {
3658 case XML_ELEMENT_NODE:
3660 dump_xml_element(data, options, buffer, offset, max, depth);
3665 dump_xml_text(data, options, buffer, offset, max, depth);
3668 case XML_COMMENT_NODE:
3669 dump_xml_comment(data, options, buffer, offset, max, depth);
3672 crm_warn(
"Unhandled type: %d", data->type);
3708 char *buffer = NULL;
3709 int offset = 0, max = 0;
3718 char *buffer = NULL;
3719 int offset = 0, max = 0;
3721 crm_xml_dump(an_xml_node, xml_log_option_formatted, &buffer, &offset, &max, 0);
3728 char *buffer = NULL;
3729 int offset = 0, max = 0;
3731 crm_xml_dump(an_xml_node, 0, &buffer, &offset, &max, 0);
3738 if (xml_root != NULL && xml_root->children != NULL) {
3772 char *value_copy = NULL;
3775 if (value != NULL) {
3776 value_copy = strdup(value);
3785 crm_trace(
"Cannot remove %s from %s", name, obj->name);
3787 }
else if(TRACKING_CHANGES(obj)) {
3790 xmlAttr *attr = xmlHasProp(obj, (
const xmlChar *)name);
3798 xmlUnsetProp(obj, (
const xmlChar *)name);
3805 xmlNode *child = NULL;
3810 for (child = __xml_first_child(a_node); child != NULL; child = __xml_next(child)) {
3820 if (filename == NULL) {
3828 crm_info(
"Saving %s to %s", desc, filename);
3836 gboolean result = TRUE;
3837 int root_nodes_seen = 0;
3838 static struct qb_log_callsite *digest_cs = NULL;
3842 xmlNode *child_diff = NULL;
3844 xmlNode *removed =
find_xml_node(diff,
"diff-removed", FALSE);
3847 if (digest_cs == NULL) {
3849 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
3854 for (child_diff = __xml_first_child(removed); child_diff != NULL;
3855 child_diff = __xml_next(child_diff)) {
3856 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
3857 if (root_nodes_seen == 0) {
3863 if (root_nodes_seen == 0) {
3866 }
else if (root_nodes_seen > 1) {
3867 crm_err(
"(-) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
3871 root_nodes_seen = 0;
3874 xmlNode *child_diff = NULL;
3876 for (child_diff = __xml_first_child(added); child_diff != NULL;
3877 child_diff = __xml_next(child_diff)) {
3878 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
3879 if (root_nodes_seen == 0) {
3886 if (root_nodes_seen > 1) {
3887 crm_err(
"(+) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
3890 }
else if (result && digest) {
3891 char *new_digest = NULL;
3896 crm_info(
"Digest mis-match: expected %s, calculated %s", digest, new_digest);
3899 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
3900 if (digest_cs && digest_cs->targets) {
3907 crm_trace(
"Digest matched: expected %s, calculated %s", digest, new_digest);
3911 }
else if (result) {
3919 __xml_diff_object(xmlNode * old, xmlNode *
new)
3921 xmlNode *cIter = NULL;
3922 xmlAttr *pIter = NULL;
3926 crm_node_created(
new);
3927 __xml_acl_post_process(
new);
3940 for (pIter = crm_first_attr(
new); pIter != NULL; pIter = pIter->next) {
3947 for (pIter = crm_first_attr(old); pIter != NULL; ) {
3948 xmlAttr *prop = pIter;
3950 const char *name = (
const char *)pIter->name;
3952 xmlAttr *exists = xmlHasProp(
new, pIter->name);
3954 pIter = pIter->next;
3955 if(exists == NULL) {
3956 p =
new->doc->_private;
3960 exists = xmlSetProp(
new, (
const xmlChar *)name, (
const xmlChar *)old_value);
3963 p = exists->_private;
3966 crm_trace(
"Lost %s@%s=%s", old->name, name, old_value);
3970 int p_new = __xml_offset((xmlNode*)exists);
3971 int p_old = __xml_offset((xmlNode*)prop);
3974 p = exists->_private;
3977 if(strcmp(value, old_value) != 0) {
3983 crm_trace(
"Modified %s@%s %s->%s", old->name, name, old_value, vcopy);
3984 xmlSetProp(
new, prop->name, (
const xmlChar *)old_value);
3988 }
else if(p_old != p_new) {
3989 crm_info(
"Moved %s@%s (%d -> %d)", old->name, name, p_old, p_new);
3990 __xml_node_dirty(
new);
3998 p = exists->_private;
4005 for (pIter = crm_first_attr(
new); pIter != NULL; ) {
4006 xmlAttr *prop = pIter;
4009 pIter = pIter->next;
4011 char *name = strdup((
const char *)prop->name);
4014 crm_trace(
"Created %s@%s=%s", new->name, name, value);
4017 crm_attr_dirty(prop);
4019 xmlUnsetProp(
new, prop->name);
4027 for (cIter = __xml_first_child(old); cIter != NULL; ) {
4028 xmlNode *old_child = cIter;
4029 xmlNode *new_child = find_element(
new, cIter);
4031 cIter = __xml_next(cIter);
4033 __xml_diff_object(old_child, new_child);
4038 xmlNode *top = xmlDocGetRootElement(candidate->doc);
4040 __xml_node_clean(candidate);
4041 __xml_acl_apply(top);
4044 if (find_element(
new, old_child) == NULL) {
4052 for (cIter = __xml_first_child(
new); cIter != NULL; ) {
4053 xmlNode *new_child = cIter;
4054 xmlNode *old_child = find_element(old, cIter);
4056 cIter = __xml_next(cIter);
4057 if(old_child == NULL) {
4060 __xml_diff_object(old_child, new_child);
4064 int p_new = __xml_offset(new_child);
4065 int p_old = __xml_offset(old_child);
4067 if(p_old != p_new) {
4070 crm_info(
"%s.%s moved from %d to %d",
4071 new_child->name,
ID(new_child), p_old, p_new);
4072 __xml_node_dirty(
new);
4076 p = old_child->_private;
4078 p = new_child->_private;
4096 __xml_diff_object(old,
new);
4102 xmlNode *tmp1 = NULL;
4119 if (added->children == NULL && removed->children == NULL) {
4130 xmlNode *cIter = NULL;
4131 xmlAttrPtr pIter = NULL;
4132 gboolean can_prune = TRUE;
4133 const char *name = crm_element_name(xml_node);
4142 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4143 const char *p_name = (
const char *)pIter->name;
4151 cIter = __xml_first_child(xml_node);
4153 xmlNode *child = cIter;
4155 cIter = __xml_next(cIter);
4167 xmlNode * xml_node, xmlNode * parent)
4170 xmlNode *child = NULL;
4171 xmlAttrPtr pIter = NULL;
4172 xmlNode *new_parent = parent;
4173 const char *name = crm_element_name(xml_node);
4175 CRM_CHECK(xml_node != NULL && name != NULL,
return);
4178 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4179 const char *p_name = (
const char *)pIter->name;
4180 const char *p_value = crm_attr_value(pIter);
4182 lower_bound = context;
4186 if (lower_bound >= 0 || upper_bound >= 0) {
4192 if (upper_bound >= 0) {
4201 for (child = __xml_first_child(us); child != NULL; child = __xml_next(child)) {
4213 if (xml_node->properties) {
4216 }
else if (depth < context) {
4217 xmlNode *child = NULL;
4219 for (child = __xml_first_child(xml_node); child != NULL; child = __xml_next(child)) {
4229 find_xml_comment(xmlNode * root, xmlNode * search_comment)
4231 xmlNode *a_child = NULL;
4233 CRM_CHECK(search_comment->type == XML_COMMENT_NODE,
return NULL);
4235 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
4236 if (a_child->type != XML_COMMENT_NODE) {
4239 if (
safe_str_eq((
const char *)a_child->content, (
const char *)search_comment->content)) {
4248 subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right,
4252 CRM_CHECK(left->type == XML_COMMENT_NODE,
return NULL);
4255 ||
safe_str_neq((
const char *)left->content, (
const char *)right->content)) {
4256 xmlNode *deleted = NULL;
4269 gboolean full, gboolean * changed,
const char *marker)
4271 gboolean dummy = FALSE;
4272 gboolean skip = FALSE;
4273 xmlNode *diff = NULL;
4274 xmlNode *right_child = NULL;
4275 xmlNode *left_child = NULL;
4276 xmlAttrPtr xIter = NULL;
4278 const char *
id = NULL;
4279 const char *name = NULL;
4280 const char *value = NULL;
4281 const char *right_val = NULL;
4284 static int filter_len =
DIMOF(filter);
4286 if (changed == NULL) {
4294 if (left->type == XML_COMMENT_NODE) {
4295 return subtract_xml_comment(parent, left, right, changed);
4299 if (right == NULL) {
4300 xmlNode *deleted = NULL;
4302 crm_trace(
"Processing <%s id=%s> (complete copy)", crm_element_name(left),
id);
4310 name = crm_element_name(left);
4316 if (value != NULL && strcmp(value,
"removed:top") == 0) {
4317 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
4326 for (lpc = 0; lpc < filter_len; lpc++) {
4327 filter[lpc].found = FALSE;
4331 for (left_child = __xml_first_child(left); left_child != NULL;
4332 left_child = __xml_next(left_child)) {
4333 gboolean child_changed = FALSE;
4335 right_child = find_element(right, left_child);
4337 if (child_changed) {
4342 if (*changed == FALSE) {
4346 xmlAttrPtr pIter = NULL;
4348 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4349 const char *p_name = (
const char *)pIter->name;
4350 const char *p_value = crm_attr_value(pIter);
4352 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4359 xmlSetProp(diff, (
const xmlChar *)
XML_ATTR_ID, (
const xmlChar *)
id);
4363 for (xIter = crm_first_attr(left); xIter != NULL; xIter = xIter->next) {
4364 const char *prop_name = (
const char *)xIter->name;
4365 xmlAttrPtr right_attr = NULL;
4373 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
4374 if (filter[lpc].found == FALSE && strcmp(prop_name, filter[lpc].
string) == 0) {
4375 filter[lpc].found = TRUE;
4385 right_attr = xmlHasProp(right, (
const xmlChar *)prop_name);
4387 p = right_attr->_private;
4391 if (right_val == NULL || (p && is_set(p->flags,
xpf_deleted))) {
4395 xmlAttrPtr pIter = NULL;
4397 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4398 const char *p_name = (
const char *)pIter->name;
4399 const char *p_value = crm_attr_value(pIter);
4401 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4408 xmlSetProp(diff, (
const xmlChar *)prop_name, (
const xmlChar *)value);
4416 if (strcmp(left_value, right_val) == 0) {
4422 xmlAttrPtr pIter = NULL;
4424 crm_trace(
"Changes detected to %s in <%s id=%s>", prop_name,
4425 crm_element_name(left),
id);
4426 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4427 const char *p_name = (
const char *)pIter->name;
4428 const char *p_value = crm_attr_value(pIter);
4430 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4435 crm_trace(
"Changes detected to %s (%s -> %s) in <%s id=%s>",
4436 prop_name, left_value, right_val, crm_element_name(left),
id);
4443 if (*changed == FALSE) {
4447 }
else if (full == FALSE &&
id) {
4455 add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update)
4458 CRM_CHECK(update->type == XML_COMMENT_NODE,
return 0);
4460 if (target == NULL) {
4461 target = find_xml_comment(parent, update);
4464 if (target == NULL) {
4468 }
else if (
safe_str_neq((
const char *)target->content, (
const char *)update->content)) {
4469 xmlFree(target->content);
4470 target->content = xmlStrdup(update->content);
4477 add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff)
4479 xmlNode *a_child = NULL;
4480 const char *object_id = NULL;
4481 const char *object_name = NULL;
4490 if (update->type == XML_COMMENT_NODE) {
4491 return add_xml_comment(parent, target, update);
4494 object_name = crm_element_name(update);
4495 object_id =
ID(update);
4497 CRM_CHECK(object_name != NULL,
return 0);
4499 if (target == NULL && object_id == NULL) {
4503 }
else if (target == NULL) {
4504 target =
find_entity(parent, object_name, object_id);
4507 if (target == NULL) {
4510 #if XML_PARSER_DEBUG
4512 object_id ?
" id=" :
"", object_id ? object_id :
"");
4515 crm_trace(
"Found node <%s%s%s/> to update",
4516 crm_str(object_name), object_id ?
" id=" :
"", object_id ? object_id :
"");
4522 if (as_diff == FALSE) {
4528 xmlAttrPtr pIter = NULL;
4530 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4531 const char *p_name = (
const char *)pIter->name;
4532 const char *p_value = crm_attr_value(pIter);
4535 xmlUnsetProp(target, (
const xmlChar *)p_name);
4536 xmlSetProp(target, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4540 for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
4541 #if XML_PARSER_DEBUG
4542 crm_trace(
"Updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
4547 #if XML_PARSER_DEBUG
4556 gboolean can_update = TRUE;
4557 xmlNode *child_of_child = NULL;
4560 CRM_CHECK(to_update != NULL,
return FALSE);
4562 if (
safe_str_neq(crm_element_name(to_update), crm_element_name(child))) {
4568 }
else if (can_update) {
4569 #if XML_PARSER_DEBUG
4575 for (child_of_child = __xml_first_child(child); child_of_child != NULL;
4576 child_of_child = __xml_next(child_of_child)) {
4589 const char *tag,
const char *field,
const char *value, gboolean search_matches)
4591 int match_found = 0;
4594 CRM_CHECK(children != NULL,
return FALSE);
4596 if (tag != NULL &&
safe_str_neq(tag, crm_element_name(root))) {
4601 if (*children == NULL) {
4608 if (search_matches || match_found == 0) {
4609 xmlNode *child = NULL;
4611 for (child = __xml_first_child(root); child != NULL; child = __xml_next(child)) {
4612 match_found +=
find_xml_children(children, child, tag, field, value, search_matches);
4622 gboolean can_delete = FALSE;
4623 xmlNode *child_of_child = NULL;
4625 const char *up_id = NULL;
4626 const char *child_id = NULL;
4627 const char *right_val = NULL;
4630 CRM_CHECK(update != NULL,
return FALSE);
4633 child_id =
ID(child);
4635 if (up_id == NULL || (child_id && strcmp(child_id, up_id) == 0)) {
4638 if (
safe_str_neq(crm_element_name(update), crm_element_name(child))) {
4641 if (can_delete && delete_only) {
4642 xmlAttrPtr pIter = NULL;
4644 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4645 const char *p_name = (
const char *)pIter->name;
4646 const char *p_value = crm_attr_value(pIter);
4655 if (can_delete && parent != NULL) {
4657 if (delete_only || update == NULL) {
4662 xmlDoc *doc = tmp->doc;
4663 xmlNode *old = NULL;
4666 old = xmlReplaceNode(child, tmp);
4670 __xml_acl_apply(tmp);
4674 xmlDocSetRootElement(doc, old);
4680 }
else if (can_delete) {
4685 child_of_child = __xml_first_child(child);
4686 while (child_of_child) {
4687 xmlNode *next = __xml_next(child_of_child);
4693 child_of_child = NULL;
4695 child_of_child = next;
4705 const char *name = key;
4706 const char *s_value = value;
4708 xmlNode *xml_node = user_data;
4715 crm_trace(
"dumped: name=%s value=%s", name, s_value);
4721 const char *name = key;
4722 const char *s_value = value;
4724 xmlNode *xml_node = user_data;
4726 if (isdigit(name[0])) {
4734 crm_trace(
"dumped: %s=%s", name, s_value);
4737 crm_trace(
"duplicate: %s=%s", name, s_value);
4744 const char *name = key;
4745 const char *s_value = value;
4747 xmlNode *xml_node = user_data;
4753 crm_trace(
"duplicate: %s=%s", name, s_value);
4760 char *crm_name = NULL;
4762 if (key == NULL || value == NULL) {
4764 }
else if (((
char *)key)[0] ==
'#') {
4766 }
else if (strstr(key,
":")) {
4778 xmlNode *child = NULL;
4779 xmlAttrPtr pIter = NULL;
4780 xmlNode *nvpair_list = NULL;
4781 GHashTable *nvpair_hash = g_hash_table_new_full(
crm_str_hash, g_str_equal,
4784 CRM_CHECK(parent != NULL,
return nvpair_hash);
4787 if (nvpair_list == NULL) {
4788 crm_trace(
"No attributes in %s", crm_element_name(parent));
4794 for (pIter = crm_first_attr(nvpair_list); pIter != NULL; pIter = pIter->next) {
4795 const char *p_name = (
const char *)pIter->name;
4796 const char *p_value = crm_attr_value(pIter);
4798 crm_trace(
"Added %s=%s", p_name, p_value);
4800 g_hash_table_insert(nvpair_hash, strdup(p_name), strdup(p_value));
4803 for (child = __xml_first_child(nvpair_list); child != NULL; child = __xml_next(child)) {
4804 if (strcmp((
const char *)child->name,
XML_TAG_PARAM) == 0) {
4809 if (key != NULL && value != NULL) {
4810 g_hash_table_insert(nvpair_hash, strdup(key), strdup(value));
4818 typedef struct name_value_s {
4824 sort_pairs(gconstpointer a, gconstpointer b)
4836 rc = strcmp(pair_a->name, pair_b->name);
4839 }
else if (rc > 0) {
4846 dump_pair(gpointer data, gpointer user_data)
4849 xmlNode *parent = user_data;
4855 sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive)
4857 xmlNode *child = NULL;
4861 xmlNode *result = NULL;
4862 const char *name = NULL;
4863 xmlAttrPtr pIter = NULL;
4867 name = crm_element_name(input);
4872 for (pIter = crm_first_attr(input); pIter != NULL; pIter = pIter->next) {
4873 const char *p_name = (
const char *)pIter->name;
4874 const char *p_value = crm_attr_value(pIter);
4877 pair->name = p_name;
4878 pair->value = p_value;
4879 unsorted = g_list_prepend(unsorted, pair);
4883 sorted = g_list_sort(unsorted, sort_pairs);
4884 g_list_foreach(sorted, dump_pair, result);
4885 g_list_free_full(sorted, free);
4887 for (child = __xml_first_child(input); child != NULL; child = __xml_next(child)) {
4901 xmlNode *match = NULL;
4903 for (match = __xml_first_child(parent); match != NULL; match = __xml_next(match)) {
4909 if (name == NULL || strcmp((
const char *)match->name, name) == 0) {
4919 static bool init = TRUE;
4928 xmlSetBufferAllocationScheme(XML_BUFFER_ALLOC_DOUBLEIT);
4931 xmlDeregisterNodeDefault(pcmkDeregisterNode);
4932 xmlRegisterNodeDefault(pcmkRegisterNode);
4941 crm_info(
"Cleaning up memory from libxml2");
4949 const char *tag = NULL;
4950 const char *ref = NULL;
4951 xmlNode *result = input;
4952 char *xpath_string = NULL;
4954 if (result == NULL) {
4957 }
else if (top == NULL) {
4961 tag = crm_element_name(result);
4965 int xpath_max = 512, offset = 0;
4967 xpath_string = calloc(1, xpath_max);
4969 offset += snprintf(xpath_string + offset, xpath_max - offset,
"//%s[@id='%s']", tag, ref);
4973 if (result == NULL) {
4974 char *nodePath = (
char *)xmlGetNodePath(top);
4976 crm_err(
"No match for %s found in %s: Invalid configuration", xpath_string,
4989 xmlAttr *attr = NULL;
4992 crm_err(
"Couldn't find %s in NULL", name ? name :
"<null>");
4996 }
else if (name == NULL) {
4997 crm_err(
"Couldn't find NULL in %s", crm_element_name(data));
5001 attr = xmlHasProp(data, (
const xmlChar *)name);
5002 if (attr == NULL || attr->children == NULL) {
5005 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)
void crm_schema_init(void)
#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 pcmk_err_old_data
long long crm_int_helper(const char *text, char **end_text)
#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...)
void crm_schema_cleanup(void)
#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_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
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)
#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
#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 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
#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_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)
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)
gboolean crm_ends_with(const char *s, const char *match)
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)
#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
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
char * crm_xml_escape(const char *text)
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)
#define XML_ACL_TAG_ROLE_REF
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)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
#define crm_info(fmt, args...)
void g_hash_destroy_str(gpointer data)
gboolean can_prune_leaf(xmlNode *xml_node)
bool xml_patch_versions(xmlNode *patchset, int add[3], int del[3])
bool xml_document_dirty(xmlNode *xml)