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 {
89 typedef struct xml_deleted_obj_s {
96 static filter_t filter[] = {
105 static xmlNode *subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right, gboolean * changed);
106 static xmlNode *find_xml_comment(xmlNode * root, xmlNode * search_comment, gboolean exact);
107 static int add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update);
108 static bool __xml_acl_check(xmlNode *xml,
const char *name,
enum xml_private_flags mode);
111 #define CHUNK_SIZE 1024 112 static inline bool TRACKING_CHANGES(xmlNode *xml)
114 if(xml == NULL || xml->doc == NULL || xml->doc->_private == NULL) {
122 #define buffer_print(buffer, max, offset, fmt, args...) do { \ 125 rc = snprintf((buffer) + (offset), (max) - (offset), fmt, ##args); \ 127 if(buffer && rc < 0) { \ 128 crm_perror(LOG_ERR, "snprintf failed at offset %d", offset); \ 129 (buffer)[(offset)] = 0; \ 130 } else if(rc >= ((max) - (offset))) { \ 132 (max) = QB_MAX(CHUNK_SIZE, (max) * 2); \ 133 tmp = realloc_safe((buffer), (max) + 1); \ 143 insert_prefix(
int options,
char **buffer,
int *offset,
int *max,
int depth)
146 size_t spaces = 2 * depth;
148 if ((*buffer) == NULL || spaces >= ((*max) - (*offset))) {
150 (*buffer) = realloc_safe((*buffer), (*max) + 1);
152 memset((*buffer) + (*offset),
' ', spaces);
158 set_parent_flag(xmlNode *xml,
long flag)
161 for(; xml; xml = xml->parent) {
174 set_doc_flag(xmlNode *xml,
long flag)
177 if(xml && xml->doc && xml->doc->_private){
187 __xml_node_dirty(xmlNode *xml)
194 __xml_node_clean(xmlNode *xml)
196 xmlNode *cIter = NULL;
203 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
204 __xml_node_clean(cIter);
209 crm_node_created(xmlNode *xml)
211 xmlNode *cIter = NULL;
214 if(p && TRACKING_CHANGES(xml)) {
217 __xml_node_dirty(xml);
220 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
221 crm_node_created(cIter);
227 crm_attr_dirty(xmlAttr *a)
229 xmlNode *parent = a->parent;
238 __xml_node_dirty(parent);
241 int get_tag_name(
const char *input,
size_t offset,
size_t max);
242 int get_attr_name(
const char *input,
size_t offset,
size_t max);
247 xmlNode * xml_node, xmlNode * parent);
249 int add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff);
251 static inline const char *
252 crm_attr_value(xmlAttr * attr)
254 if (attr == NULL || attr->children == NULL) {
257 return (
const char *)attr->children->content;
260 static inline xmlAttr *
261 crm_first_attr(xmlNode * xml)
266 return xml->properties;
269 #define XML_PRIVATE_MAGIC (long) 0x81726354 272 __xml_acl_free(
void *
data)
283 __xml_deleted_obj_free(
void *
data)
288 free(deleted_obj->path);
303 g_list_free_full(p->acls, __xml_acl_free);
307 if(p->deleted_objs) {
308 g_list_free_full(p->deleted_objs, __xml_deleted_obj_free);
309 p->deleted_objs = NULL;
318 __xml_private_clean(p);
323 pcmkDeregisterNode(xmlNodePtr node)
325 __xml_private_free(node->_private);
329 pcmkRegisterNode(xmlNodePtr node)
334 case XML_ELEMENT_NODE:
335 case XML_DOCUMENT_NODE:
336 case XML_ATTRIBUTE_NODE:
337 case XML_COMMENT_NODE:
346 case XML_CDATA_SECTION_NODE:
350 crm_trace(
"Ignoring %p %d", node, node->type);
355 if(p && TRACKING_CHANGES(node)) {
360 __xml_node_dirty(node);
383 if(target == NULL || target->doc == NULL || target->doc->_private == NULL){
389 }
else if (tag == NULL && ref == NULL && xpath == NULL) {
394 p = target->doc->_private;
401 acl->xpath = strdup(xpath);
402 crm_trace(
"Using xpath: %s", acl->xpath);
409 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"//%s", tag);
419 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@id='%s'", ref);
423 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
" and ");
427 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@%s", attr);
435 acl->xpath = strdup(buffer);
436 crm_trace(
"Built xpath: %s", acl->xpath);
439 p->acls = g_list_append(p->acls, acl);
445 __xml_acl_parse_entry(xmlNode * acl_top, xmlNode * acl_entry, xmlNode *target)
447 xmlNode *child = NULL;
449 for (child = __xml_first_child(acl_entry); child; child = __xml_next(child)) {
450 const char *tag = crm_element_name(child);
457 crm_trace(
"Processing %s %p", tag, child);
466 xmlNode *role = NULL;
468 for (role = __xml_first_child(acl_top); role; role = __xml_next(role)) {
472 if (role_id && strcmp(ref_role, role_id) == 0) {
473 crm_debug(
"Unpacking referenced role: %s", role_id);
474 __xml_acl_parse_entry(acl_top, role, target);
491 crm_warn(
"Unknown ACL entry: %s/%s", tag, kind);
537 __xml_acl_apply(xmlNode *xml)
541 xmlXPathObjectPtr xpathObj = NULL;
544 p = xml->doc->_private;
545 crm_trace(
"Not applying ACLs for %s", p->user);
549 p = xml->doc->_private;
550 for(aIter = p->acls; aIter != NULL; aIter = aIter->next) {
551 int max = 0, lpc = 0;
555 max = numXpathResults(xpathObj);
557 for(lpc = 0; lpc < max; lpc++) {
562 crm_trace(
"Applying %x to %s for %s", acl->mode, path, acl->xpath);
564 #ifdef SUSE_ACL_COMPAT 565 if(is_not_set(p->flags, acl->mode)) {
569 crm_config_warn(
"Configuration element %s is matched by multiple ACL rules, only the first applies ('%s' wins over '%s')",
577 p->flags |= acl->mode;
580 crm_trace(
"Now enforcing ACL: %s (%d matches)", acl->xpath, max);
587 p = xml->doc->_private;
588 crm_info(
"Enforcing default ACL for %s to %s", p->user, crm_element_name(xml));
594 __xml_acl_unpack(xmlNode *source, xmlNode *target,
const char *user)
599 if(target == NULL || target->doc == NULL || target->doc->_private == NULL) {
603 p = target->doc->_private;
605 crm_trace(
"no acls needed for '%s'", user);
607 }
else if(p->acls == NULL) {
611 p->user = strdup(user);
614 xmlNode *child = NULL;
616 for (child = __xml_first_child(acls); child; child = __xml_next(child)) {
617 const char *tag = crm_element_name(child);
622 if(
id && strcmp(
id, user) == 0) {
624 __xml_acl_parse_entry(acls, child, target);
639 }
else if(is_set(allowed, requested)) {
658 __xml_purge_attributes(xmlNode *xml)
660 xmlNode *child = NULL;
661 xmlAttr *xIter = NULL;
662 bool readable_children = FALSE;
666 crm_trace(
"%s[@id=%s] is readable", crm_element_name(xml),
ID(xml));
670 xIter = crm_first_attr(xml);
671 while(xIter != NULL) {
672 xmlAttr *tmp = xIter;
673 const char *prop_name = (
const char *)xIter->name;
680 xmlUnsetProp(xml, tmp->name);
683 child = __xml_first_child(xml);
684 while ( child != NULL ) {
685 xmlNode *tmp = child;
687 child = __xml_next(child);
688 readable_children |= __xml_purge_attributes(tmp);
691 if(readable_children == FALSE) {
694 return readable_children;
701 xmlNode *target = NULL;
707 crm_trace(
"no acls needed for '%s'", user);
711 crm_trace(
"filtering copy of %p for '%s'", xml, user);
717 __xml_acl_unpack(acl_source, target, user);
719 __xml_acl_apply(target);
721 doc = target->doc->_private;
722 for(aIter = doc->acls; aIter != NULL && target; aIter = aIter->next) {
729 }
else if(acl->xpath) {
731 xmlXPathObjectPtr xpathObj =
xpath_search(target, acl->xpath);
733 max = numXpathResults(xpathObj);
734 for(lpc = 0; lpc < max; lpc++) {
737 crm_trace(
"Purging attributes from %s", acl->xpath);
738 if(__xml_purge_attributes(match) == FALSE && match == target) {
739 crm_trace(
"No access to the entire document for %s", user);
744 crm_trace(
"Enforced ACL %s (%d matches)", acl->xpath, max);
749 p = target->_private;
750 if(is_set(p->flags,
xpf_acl_deny) && __xml_purge_attributes(target) == FALSE) {
751 crm_trace(
"No access to the entire document for %s", user);
756 g_list_free_full(doc->acls, __xml_acl_free);
760 crm_trace(
"Ordinary user '%s' cannot access the CIB without any defined ACLs", doc->user);
773 __xml_acl_post_process(xmlNode * xml)
775 xmlNode *cIter = __xml_first_child(xml);
779 xmlAttr *xIter = NULL;
786 for (xIter = crm_first_attr(xml); xIter != NULL; xIter = xIter->next) {
787 const char *prop_name = (
const char *)xIter->name;
794 crm_trace(
"Creation of %s=%s is allowed", crm_element_name(xml),
ID(xml));
798 crm_trace(
"Cannot add new node %s at %s", crm_element_name(xml), path);
800 if(xml != xmlDocGetRootElement(xml->doc)) {
811 while (cIter != NULL) {
812 xmlNode *child = cIter;
813 cIter = __xml_next(cIter);
814 __xml_acl_post_process(child);
821 if(xml && xml->doc && xml->doc->_private){
836 __xml_acl_apply(xml);
837 __xml_acl_post_process(xml);
845 if(xml && xml->doc && xml->doc->_private){
857 crm_trace(
"Tracking changes%s to %p", enforce_acls?
" with ACLs":
"", xml);
860 if(acl_source == NULL) {
864 __xml_acl_unpack(acl_source, xml, user);
865 __xml_acl_apply(xml);
882 if(xml != NULL && xml->doc && xml->doc->_private) {
938 static int __xml_offset(xmlNode *xml)
941 xmlNode *cIter = NULL;
943 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
946 if(is_not_set(p->flags,
xpf_skip)) {
954 static int __xml_offset_no_deletions(xmlNode *xml)
957 xmlNode *cIter = NULL;
959 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
971 __xml_build_changes(xmlNode * xml, xmlNode *patchset)
973 xmlNode *cIter = NULL;
974 xmlAttr *pIter = NULL;
975 xmlNode *change = NULL;
982 if(__get_prefix(NULL, xml->parent, buffer, offset) > 0) {
983 int position = __xml_offset_no_deletions(xml);
996 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
997 xmlNode *attr = NULL;
1004 if(change == NULL) {
1008 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1033 xmlNode *result = NULL;
1038 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1041 p = pIter->_private;
1043 crm_xml_add(result, (
const char *)pIter->name, value);
1048 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1049 __xml_build_changes(cIter, patchset);
1053 if(patchset && is_set(p->flags,
xpf_moved)) {
1057 crm_trace(
"%s.%s moved to position %d", xml->name,
ID(xml), __xml_offset(xml));
1058 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1069 __xml_accept_changes(xmlNode * xml)
1071 xmlNode *cIter = NULL;
1072 xmlAttr *pIter = NULL;
1076 pIter = crm_first_attr(xml);
1078 while (pIter != NULL) {
1079 const xmlChar *name = pIter->name;
1081 p = pIter->_private;
1082 pIter = pIter->next;
1092 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1093 __xml_accept_changes(cIter);
1098 is_config_change(xmlNode *xml)
1105 p = config->_private;
1111 if(xml->doc && xml->doc->_private) {
1112 p = xml->doc->_private;
1113 for(gIter = p->deleted_objs; gIter; gIter = gIter->next) {
1126 xml_repair_v1_diff(xmlNode * last, xmlNode * next, xmlNode * local_diff, gboolean changed)
1129 xmlNode *cib = NULL;
1130 xmlNode *diff_child = NULL;
1132 const char *tag = NULL;
1134 const char *vfields[] = {
1140 if (local_diff == NULL) {
1145 tag =
"diff-removed";
1147 if (diff_child == NULL) {
1157 for(lpc = 0; last && lpc <
DIMOF(vfields); lpc++){
1161 if(changed || lpc == 2) {
1168 if (diff_child == NULL) {
1178 for(lpc = 0; next && lpc <
DIMOF(vfields); lpc++){
1185 xmlAttrPtr xIter = NULL;
1187 for (xIter = next->properties; xIter; xIter = xIter->next) {
1188 const char *p_name = (
const char *)xIter->name;
1191 xmlSetProp(cib, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
1199 xml_create_patchset_v1(xmlNode *source, xmlNode *target,
bool config,
bool suppress)
1205 xml_repair_v1_diff(source, target, patchset, config);
1212 xml_create_patchset_v2(xmlNode *source, xmlNode *target)
1220 xmlNode *patchset = NULL;
1221 const char *vfields[] = {
1233 doc = target->doc->_private;
1241 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1251 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1260 for(gIter = doc->deleted_objs; gIter; gIter = gIter->next) {
1266 if (deleted_obj->position >= 0) {
1271 __xml_build_changes(target, patchset);
1275 static gboolean patch_legacy_mode(
void)
1277 static gboolean init = TRUE;
1278 static gboolean legacy = FALSE;
1294 bool config = FALSE;
1295 xmlNode *patch = NULL;
1304 config = is_config_change(target);
1305 if(config_changed) {
1306 *config_changed = config;
1309 if(manage_version && config) {
1316 }
else if(manage_version) {
1323 if(patch_legacy_mode()) {
1332 crm_trace(
"Using patch format %d for version: %s", format, version);
1337 patch = xml_create_patchset_v1(source, target, config, FALSE);
1340 patch = xml_create_patchset_v2(source, target);
1343 crm_err(
"Unknown patch format: %d", format);
1355 char *digest = NULL;
1357 if (patch == NULL || source == NULL || target == NULL) {
1366 if (format > 1 && with_digest == FALSE) {
1380 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
1381 const char *prefix, xmlNode *
data,
int depth,
int options);
1387 xmlNode *child = NULL;
1388 xmlNode *added = NULL;
1389 xmlNode *removed = NULL;
1390 gboolean is_first = TRUE;
1392 int add[] = { 0, 0, 0 };
1393 int del[] = { 0, 0, 0 };
1395 const char *fmt = NULL;
1396 const char *digest = NULL;
1399 static struct qb_log_callsite *patchset_cs = NULL;
1401 if (patchset_cs == NULL) {
1402 patchset_cs = qb_log_callsite_get(
function, __FILE__,
"xml-patchset", log_level, __LINE__, 0);
1405 if (patchset == NULL) {
1409 }
else if (log_level == 0) {
1419 if (add[2] != del[2] || add[1] != del[1] || add[0] != del[0]) {
1421 "Diff: --- %d.%d.%d %s", del[0], del[1], del[2], fmt);
1423 "Diff: +++ %d.%d.%d %s", add[0], add[1], add[2], digest);
1425 }
else if (patchset != NULL && (add[0] || add[1] || add[2])) {
1427 "%s: Local-only Change: %d.%d.%d",
function ?
function :
"",
1428 add[0], add[1], add[2]);
1433 xmlNode *change = NULL;
1435 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
1440 }
else if(strcmp(op,
"create") == 0) {
1441 int lpc = 0, max = 0;
1444 max = strlen(prefix);
1445 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1448 for(lpc = 2; lpc < max; lpc++) {
1452 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1456 }
else if(strcmp(op,
"move") == 0) {
1459 }
else if(strcmp(op,
"modify") == 0) {
1467 buffer_unset[0] = 0;
1468 for (child = __xml_first_child(clist); child != NULL; child = __xml_next(child)) {
1473 }
else if(strcmp(op,
"set") == 0) {
1479 o_set += snprintf(buffer_set + o_set,
XML_BUFFER_SIZE - o_set,
"@%s=%s", name, value);
1481 }
else if(strcmp(op,
"unset") == 0) {
1483 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
", ");
1485 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
"@%s", name);
1489 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"+ %s: %s", xpath, buffer_set);
1492 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s: %s", xpath, buffer_unset);
1495 }
else if(strcmp(op,
"delete") == 0) {
1499 if (position >= 0) {
1500 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s (%d)", xpath, position);
1510 if (log_level < LOG_DEBUG ||
function == NULL) {
1515 for (child = __xml_first_child(removed); child != NULL; child = __xml_next(child)) {
1527 for (child = __xml_first_child(added); child != NULL; child = __xml_next(child)) {
1547 doc = xml->doc->_private;
1552 for(gIter = doc->deleted_objs; gIter; gIter = gIter->next) {
1555 if (deleted_obj->position >= 0) {
1557 deleted_obj->path, deleted_obj->position);
1572 xmlNode *top = NULL;
1579 crm_trace(
"Accepting changes to %p", xml);
1580 doc = xml->doc->_private;
1581 top = xmlDocGetRootElement(xml->doc);
1583 __xml_private_clean(xml->doc->_private);
1591 __xml_accept_changes(top);
1595 find_element(xmlNode *haystack, xmlNode *needle, gboolean exact)
1598 return (needle->type == XML_COMMENT_NODE)?
1599 find_xml_comment(haystack, needle, exact)
1600 :
find_entity(haystack, crm_element_name(needle),
ID(needle));
1605 __subtract_xml_object(xmlNode * target, xmlNode * patch)
1607 xmlNode *patch_child = NULL;
1608 xmlNode *cIter = NULL;
1609 xmlAttrPtr xIter = NULL;
1612 const char *name = NULL;
1613 const char *value = NULL;
1615 if (target == NULL || patch == NULL) {
1619 if (target->type == XML_COMMENT_NODE) {
1622 subtract_xml_comment(target->parent, target, patch, &dummy);
1625 name = crm_element_name(target);
1633 if (value != NULL && strcmp(value,
"removed:top") == 0) {
1634 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
1640 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1641 const char *p_name = (
const char *)xIter->name;
1650 cIter = __xml_first_child(target);
1652 xmlNode *target_child = cIter;
1654 cIter = __xml_next(cIter);
1655 patch_child = find_element(patch, target_child, FALSE);
1656 __subtract_xml_object(target_child, patch_child);
1662 __add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * patch)
1664 xmlNode *patch_child = NULL;
1665 xmlNode *target_child = NULL;
1666 xmlAttrPtr xIter = NULL;
1668 const char *
id = NULL;
1669 const char *name = NULL;
1670 const char *value = NULL;
1672 if (patch == NULL) {
1674 }
else if (parent == NULL && target == NULL) {
1682 && strcmp(value,
"added:top") == 0) {
1684 name = crm_element_name(patch);
1685 crm_trace(
"We are the root of the addition: %s.id=%s", name,
id);
1689 }
else if(target == NULL) {
1691 name = crm_element_name(patch);
1692 crm_err(
"Could not locate: %s.id=%s", name,
id);
1696 if (target->type == XML_COMMENT_NODE) {
1697 add_xml_comment(parent, target, patch);
1700 name = crm_element_name(target);
1705 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1706 const char *p_name = (
const char *)xIter->name;
1714 for (patch_child = __xml_first_child(patch); patch_child != NULL;
1715 patch_child = __xml_next(patch_child)) {
1717 target_child = find_element(target, patch_child, FALSE);
1718 __add_xml_object(target, target_child, patch_child);
1734 find_patch_xml_node(xmlNode *patchset,
int format,
bool added,
1735 xmlNode **patch_node)
1742 label = added?
"diff-added" :
"diff-removed";
1745 if (cib_node != NULL) {
1746 *patch_node = cib_node;
1750 label = added?
"target" :
"source";
1755 crm_warn(
"Unknown patch format: %d", format);
1766 xmlNode *tmp = NULL;
1768 const char *vfields[] = {
1778 if (!find_patch_xml_node(patchset, format, FALSE, &tmp)) {
1782 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1784 crm_trace(
"Got %d for del[%s]", del[lpc], vfields[lpc]);
1789 if (!find_patch_xml_node(patchset, format, TRUE, &tmp)) {
1793 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1795 crm_trace(
"Got %d for add[%s]", add[lpc], vfields[lpc]);
1803 xml_patch_version_check(xmlNode *xml, xmlNode *patchset,
int format)
1806 bool changed = FALSE;
1808 int this[] = { 0, 0, 0 };
1809 int add[] = { 0, 0, 0 };
1810 int del[] = { 0, 0, 0 };
1812 const char *vfields[] = {
1818 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1820 crm_trace(
"Got %d for this[%s]",
this[lpc], vfields[lpc]);
1821 if (
this[lpc] < 0) {
1829 add[2] =
this[2] + 1;
1830 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1831 del[lpc] =
this[lpc];
1836 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1837 if(
this[lpc] < del[lpc]) {
1838 crm_debug(
"Current %s is too low (%d.%d.%d < %d.%d.%d --> %d.%d.%d)", vfields[lpc],
1839 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2]);
1842 }
else if(
this[lpc] > del[lpc]) {
1843 crm_info(
"Current %s is too high (%d.%d.%d > %d.%d.%d --> %d.%d.%d) %p", vfields[lpc],
1844 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2], patchset);
1850 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1851 if(add[lpc] > del[lpc]) {
1856 if(changed == FALSE) {
1857 crm_notice(
"Versions did not change in patch %d.%d.%d", add[0], add[1], add[2]);
1861 crm_debug(
"Can apply patch %d.%d.%d to %d.%d.%d",
1862 add[0], add[1], add[2],
this[0],
this[1],
this[2]);
1867 xml_apply_patchset_v1(xmlNode *xml, xmlNode *patchset,
bool check_version)
1870 int root_nodes_seen = 0;
1873 xmlNode *child_diff = NULL;
1874 xmlNode *added =
find_xml_node(patchset,
"diff-added", FALSE);
1875 xmlNode *removed =
find_xml_node(patchset,
"diff-removed", FALSE);
1879 for (child_diff = __xml_first_child(removed); child_diff != NULL;
1880 child_diff = __xml_next(child_diff)) {
1881 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1882 if (root_nodes_seen == 0) {
1883 __subtract_xml_object(xml, child_diff);
1888 if (root_nodes_seen > 1) {
1889 crm_err(
"(-) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1893 root_nodes_seen = 0;
1896 xmlNode *child_diff = NULL;
1898 for (child_diff = __xml_first_child(added); child_diff != NULL;
1899 child_diff = __xml_next(child_diff)) {
1900 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1901 if (root_nodes_seen == 0) {
1902 __add_xml_object(NULL, xml, child_diff);
1908 if (root_nodes_seen > 1) {
1909 crm_err(
"(+) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1921 __first_xml_child_match(xmlNode *parent,
const char *name,
const char *
id,
int position)
1923 xmlNode *cIter = NULL;
1925 for (cIter = __xml_first_child(parent); cIter != NULL; cIter = __xml_next(cIter)) {
1926 if(strcmp((
const char *)cIter->name, name) != 0) {
1929 const char *cid =
ID(cIter);
1930 if(cid == NULL || strcmp(cid,
id) != 0) {
1936 if (cIter->type == XML_COMMENT_NODE
1938 && __xml_offset(cIter) != position) {
1948 __xml_find_path(xmlNode *top,
const char *key,
int target_position)
1950 xmlNode *target = (xmlNode*)top->doc;
1954 char *current = strdup(key);
1959 rc = sscanf (current,
"/%[^/]%s", section, remainder);
1969 }
else if(tag && section) {
1970 int f = sscanf (section,
"%[^[][@id='%[^']", tag,
id);
1971 int current_position = -1;
1974 if (rc == 1 && target_position >= 0) {
1975 current_position = target_position;
1980 target = __first_xml_child_match(target, tag, NULL, current_position);
1983 target = __first_xml_child_match(target, tag,
id, current_position);
1991 if(rc == 1 || target == NULL) {
1996 char *tmp = current;
1997 current = remainder;
2004 char *path = (
char *)xmlGetNodePath(target);
2006 crm_trace(
"Found %s for %s", path, key);
2021 xml_apply_patchset_v2(xmlNode *xml, xmlNode *patchset,
bool check_version)
2024 xmlNode *change = NULL;
2025 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
2026 xmlNode *match = NULL;
2031 crm_trace(
"Processing %s %s", change->name, op);
2036 if(strcmp(op,
"delete") == 0) {
2042 match = __xml_find_path(xml, xpath, position);
2044 crm_trace(
"Performing %s on %s with %p", op, xpath, match);
2046 if(match == NULL && strcmp(op,
"delete") == 0) {
2047 crm_debug(
"No %s match for %s in %p", op, xpath, xml->doc);
2050 }
else if(match == NULL) {
2051 crm_err(
"No %s match for %s in %p", op, xpath, xml->doc);
2055 }
else if(strcmp(op,
"create") == 0) {
2057 xmlNode *child = NULL;
2058 xmlNode *match_child = NULL;
2060 match_child = match->children;
2063 while(match_child && position != __xml_offset(match_child)) {
2064 match_child = match_child->next;
2067 child = xmlDocCopyNode(change->children, match->doc, 1);
2069 crm_trace(
"Adding %s at position %d", child->name, position);
2070 xmlAddPrevSibling(match_child, child);
2072 }
else if(match->last) {
2073 crm_trace(
"Adding %s at position %d (end)", child->name, position);
2074 xmlAddNextSibling(match->last, child);
2077 crm_trace(
"Adding %s at position %d (first)", child->name, position);
2079 xmlAddChild(match, child);
2081 crm_node_created(child);
2083 }
else if(strcmp(op,
"move") == 0) {
2087 if(position != __xml_offset(match)) {
2088 xmlNode *match_child = NULL;
2091 if(p > __xml_offset(match)) {
2096 match_child = match->parent->children;
2098 while(match_child && p != __xml_offset(match_child)) {
2099 match_child = match_child->next;
2102 crm_trace(
"Moving %s to position %d (was %d, prev %p, %s %p)",
2103 match->name, position, __xml_offset(match), match->prev,
2104 match_child?
"next":
"last", match_child?match_child:match->parent->last);
2107 xmlAddPrevSibling(match_child, match);
2111 xmlAddNextSibling(match->parent->last, match);
2115 crm_trace(
"%s is already in position %d", match->name, position);
2118 if(position != __xml_offset(match)) {
2119 crm_err(
"Moved %s.%d to position %d instead of %d (%p)",
2120 match->name,
ID(match), __xml_offset(match), position, match->prev);
2124 }
else if(strcmp(op,
"delete") == 0) {
2127 }
else if(strcmp(op,
"modify") == 0) {
2128 xmlAttr *pIter = crm_first_attr(match);
2135 while(pIter != NULL) {
2136 const char *name = (
const char *)pIter->name;
2138 pIter = pIter->next;
2142 for (pIter = crm_first_attr(attrs); pIter != NULL; pIter = pIter->next) {
2143 const char *name = (
const char *)pIter->name;
2150 crm_err(
"Unknown operation: %s", op);
2161 xmlNode *old = NULL;
2164 if(patchset == NULL) {
2172 rc = xml_patch_version_check(xml, patchset, format);
2186 rc = xml_apply_patchset_v1(xml, patchset, check_version);
2189 rc = xml_apply_patchset_v2(xml, patchset, check_version);
2192 crm_err(
"Unknown patch format: %d", format);
2198 static struct qb_log_callsite *digest_cs = NULL;
2200 char *new_digest = NULL;
2203 if (digest_cs == NULL) {
2205 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
2211 crm_info(
"v%d digest mis-match: expected %s, calculated %s", format, digest, new_digest);
2214 if (digest_cs && digest_cs->targets) {
2220 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
2224 crm_trace(
"v%d digest matched: expected %s, calculated %s", format, digest, new_digest);
2236 xmlNode *a_child = NULL;
2237 const char *name =
"NULL";
2240 name = crm_element_name(root);
2243 if (search_path == NULL) {
2244 crm_warn(
"Will never find <NULL>");
2248 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
2249 if (strcmp((
const char *)a_child->name, search_path) == 0) {
2256 crm_warn(
"Could not find %s in %s.", search_path, name);
2257 }
else if (root != NULL) {
2258 crm_trace(
"Could not find %s in %s.", search_path, name);
2260 crm_trace(
"Could not find %s in <NULL>.", search_path);
2269 xmlNode *a_child = NULL;
2271 for (a_child = __xml_first_child(parent); a_child != NULL; a_child = __xml_next(a_child)) {
2273 if (node_name == NULL || strcmp((
const char *)a_child->name, node_name) == 0) {
2274 const char *cid =
ID(a_child);
2275 if (
id == NULL || (cid != NULL && strcmp(
id, cid) == 0)) {
2281 crm_trace(
"node <%s id=%s> not found in %s.", node_name,
id, crm_element_name(parent));
2289 crm_warn(
"No node to copy properties from");
2291 }
else if (target == NULL) {
2292 crm_err(
"No node to copy properties into");
2295 xmlAttrPtr pIter = NULL;
2297 for (pIter = crm_first_attr(src); pIter != NULL; pIter = pIter->next) {
2298 const char *p_name = (
const char *)pIter->name;
2299 const char *p_value = crm_attr_value(pIter);
2312 xmlNode *child = NULL;
2313 xmlAttrPtr pIter = NULL;
2315 for (pIter = crm_first_attr(target); pIter != NULL; pIter = pIter->next) {
2316 const char *p_name = (
const char *)pIter->name;
2317 const char *p_value = crm_attr_value(pIter);
2321 for (child = __xml_first_child(target); child != NULL; child = __xml_next(child)) {
2334 const char *old_value = NULL;
2336 if (value == NULL || name == NULL) {
2342 if (old_value == NULL) {
2344 goto set_unexpanded;
2346 }
else if (strstr(value, name) != value) {
2347 goto set_unexpanded;
2350 name_len = strlen(name);
2351 value_len = strlen(value);
2352 if (value_len < (name_len + 2)
2353 || value[name_len] !=
'+' || (value[name_len + 1] !=
'+' && value[name_len + 1] !=
'=')) {
2354 goto set_unexpanded;
2360 if (old_value != value) {
2364 if (value[name_len + 1] !=
'+') {
2365 const char *offset_s = value + (name_len + 2);
2369 int_value += offset;
2379 if (old_value == value) {
2396 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2397 xmlDocSetRootElement(doc, node);
2398 xmlSetTreeDoc(node, doc);
2406 xmlNode *child = NULL;
2409 CRM_CHECK(src_node != NULL,
return NULL);
2411 child = xmlDocCopyNode(src_node, doc, 1);
2412 xmlAddChild(parent, child);
2413 crm_node_created(child);
2436 xmlNode *parent = xml;
2440 if(docp->acls == NULL) {
2441 crm_trace(
"Ordinary user %s cannot access the CIB without any defined ACLs", docp->user);
2446 offset = __get_prefix(NULL, xml, buffer, offset);
2448 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"[@%s]", name);
2458 xmlAttr *attr = xmlHasProp(xml, (
const xmlChar *)name);
2465 while(parent && parent->_private) {
2467 if(__xml_acl_mode_test(p->flags, mode)) {
2471 crm_trace(
"%x access denied to %s: parent", mode, buffer);
2475 parent = parent->parent;
2478 crm_trace(
"%x access denied to %s: default", mode, buffer);
2492 xmlAttr *attr = NULL;
2497 if (value == NULL) {
2500 #if XML_PARANOIA_CHECKS 2502 const char *old_value = NULL;
2507 CRM_CHECK(old_value != value,
crm_err(
"Cannot reset %s with crm_xml_add(%s)", name, value);
2512 if(TRACKING_CHANGES(node)) {
2515 if(old == NULL || value == NULL || strcmp(old, value) != 0) {
2520 if(dirty && __xml_acl_check(node, name,
xpf_acl_create) == FALSE) {
2521 crm_trace(
"Cannot add %s=%s to %s", name, value, node->name);
2525 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2527 crm_attr_dirty(attr);
2530 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2531 return (
char *)attr->children->content;
2538 xmlAttr *attr = NULL;
2539 const char *old_value = NULL;
2542 CRM_CHECK(name != NULL && name[0] != 0,
return NULL);
2547 CRM_CHECK(old_value != value,
return value);
2551 crm_trace(
"Cannot replace %s=%s to %s", name, value, node->name);
2554 }
else if (old_value != NULL && value == NULL) {
2558 }
else if (value == NULL) {
2562 if(TRACKING_CHANGES(node)) {
2563 if(old_value == NULL || value == NULL || strcmp(old_value, value) != 0) {
2568 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2570 crm_attr_dirty(attr);
2572 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2573 return (
char *)attr->children->content;
2580 const char *added =
crm_xml_add(node, name, number);
2590 xmlNode *node = NULL;
2592 if (name == NULL || name[0] == 0) {
2593 CRM_CHECK(name != NULL && name[0] == 0,
return NULL);
2597 if (parent == NULL) {
2598 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2599 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2600 xmlDocSetRootElement(doc, node);
2604 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2605 xmlAddChild(parent, node);
2607 crm_node_created(node);
2612 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset)
2614 const char *
id =
ID(xml);
2616 if(offset == 0 && prefix == NULL && xml->parent) {
2617 offset = __get_prefix(NULL, xml->parent, buffer, offset);
2621 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s[@id='%s']", (
const char *)xml->name,
id);
2622 }
else if(xml->name) {
2623 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s", (
const char *)xml->name);
2635 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
2636 return strdup(buffer);
2642 free_xml_with_position(xmlNode * child,
int position)
2644 if (child != NULL) {
2645 xmlNode *top = NULL;
2646 xmlDoc *doc = child->doc;
2650 top = xmlDocGetRootElement(doc);
2653 if (doc != NULL && top == child) {
2657 }
else if(__xml_acl_check(child, NULL,
xpf_acl_write) == FALSE) {
2661 __get_prefix(NULL, child, buffer, offset);
2662 crm_trace(
"Cannot remove %s %x", buffer, p->flags);
2666 if(doc && TRACKING_CHANGES(child) && is_not_set(p->flags,
xpf_created)) {
2670 if(__get_prefix(NULL, child, buffer, offset) > 0) {
2673 crm_trace(
"Deleting %s %p from %p", buffer, child, doc);
2675 deleted_obj->path = strdup(buffer);
2677 deleted_obj->position = -1;
2679 if (child->type == XML_COMMENT_NODE) {
2680 if (position >= 0) {
2681 deleted_obj->position = position;
2684 deleted_obj->position = __xml_offset(child);
2689 p->deleted_objs = g_list_append(p->deleted_objs, deleted_obj);
2697 xmlUnlinkNode(child);
2707 free_xml_with_position(child, -1);
2713 xmlDoc *doc = xmlNewDoc((
const xmlChar *)
"1.0");
2714 xmlNode *copy = xmlDocCopyNode(src, doc, 1);
2716 xmlDocSetRootElement(doc, copy);
2717 xmlSetTreeDoc(copy, doc);
2722 crm_xml_err(
void *ctx,
const char *msg, ...)
2723 G_GNUC_PRINTF(2, 3);
2726 crm_xml_err(
void *ctx,
const char *msg, ...)
2731 static int buffer_len = 0;
2732 static char *buffer = NULL;
2733 static struct qb_log_callsite *xml_error_cs = NULL;
2735 va_start(args, msg);
2736 len = vasprintf(&buf, msg, args);
2738 if(xml_error_cs == NULL) {
2739 xml_error_cs = qb_log_callsite_get(
2743 if (strchr(buf,
'\n')) {
2746 crm_err(
"XML Error: %s%s", buffer, buf);
2749 crm_err(
"XML Error: %s", buf);
2751 if (xml_error_cs && xml_error_cs->targets) {
2752 crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__,
"xml library error", TRUE, TRUE);
2757 }
else if (buffer == NULL) {
2763 buffer = realloc_safe(buffer, 1 + buffer_len + len);
2764 memcpy(buffer + buffer_len, buf, len);
2766 buffer[buffer_len] = 0;
2776 xmlNode *xml = NULL;
2777 xmlDocPtr output = NULL;
2778 xmlParserCtxtPtr ctxt = NULL;
2779 xmlErrorPtr last_error = NULL;
2781 if (input == NULL) {
2782 crm_err(
"Can't parse NULL input");
2787 ctxt = xmlNewParserCtxt();
2792 xmlCtxtResetLastError(ctxt);
2793 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2796 xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL,
2797 XML_PARSE_NOBLANKS | XML_PARSE_RECOVER);
2799 xml = xmlDocGetRootElement(output);
2801 last_error = xmlCtxtGetLastError(ctxt);
2802 if (last_error && last_error->code != XML_ERR_OK) {
2808 crm_warn(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2809 last_error->domain, last_error->level, last_error->code, last_error->message);
2811 if (last_error->code == XML_ERR_DOCUMENT_EMPTY) {
2814 }
else if (last_error->code != XML_ERR_DOCUMENT_END) {
2815 crm_err(
"Couldn't%s parse %d chars: %s", xml ?
" fully" :
"", (
int)strlen(input),
2822 int len = strlen(input);
2826 crm_warn(
"Parse error[+%.3d]: %.80s", lpc, input+lpc);
2834 xmlFreeParserCtxt(ctxt);
2841 size_t data_length = 0;
2842 size_t read_chars = 0;
2844 char *xml_buffer = NULL;
2845 xmlNode *xml_obj = NULL;
2855 xml_buffer = realloc_safe(xml_buffer, next);
2856 read_chars = fread(xml_buffer + data_length, 1,
XML_BUFFER_SIZE, stdin);
2857 data_length += read_chars;
2858 }
while (read_chars > 0);
2860 if (data_length == 0) {
2861 crm_warn(
"No XML supplied on stdin");
2866 xml_buffer[data_length] =
'\0';
2876 decompress_file(
const char *filename)
2878 char *buffer = NULL;
2882 size_t length = 0, read_len = 0;
2884 BZFILE *bz_file = NULL;
2885 FILE *input = fopen(filename,
"r");
2887 if (input == NULL) {
2888 crm_perror(LOG_ERR,
"Could not open %s for reading", filename);
2892 bz_file = BZ2_bzReadOpen(&rc, input, 0, 0, NULL, 0);
2895 BZ2_bzReadClose(&rc, bz_file);
2900 while (rc == BZ_OK) {
2902 read_len = BZ2_bzRead(&rc, bz_file, buffer + length,
XML_BUFFER_SIZE);
2904 crm_trace(
"Read %ld bytes from file: %d", (
long)read_len, rc);
2906 if (rc == BZ_OK || rc == BZ_STREAM_END) {
2911 buffer[length] =
'\0';
2913 if (rc != BZ_STREAM_END) {
2914 crm_err(
"Couldn't read compressed xml from file");
2919 BZ2_bzReadClose(&rc, bz_file);
2923 crm_err(
"Cannot read compressed files:" " bzlib was not available at compile time");
2931 xmlNode *iter = xml->children;
2934 xmlNode *next = iter->next;
2936 switch (iter->type) {
2939 xmlUnlinkNode(iter);
2943 case XML_ELEMENT_NODE:
2960 xmlNode *xml = NULL;
2961 xmlDocPtr output = NULL;
2962 gboolean uncompressed = TRUE;
2963 xmlParserCtxtPtr ctxt = NULL;
2964 xmlErrorPtr last_error = NULL;
2965 static int xml_options = XML_PARSE_NOBLANKS | XML_PARSE_RECOVER;
2968 ctxt = xmlNewParserCtxt();
2973 xmlCtxtResetLastError(ctxt);
2974 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2981 if (filename == NULL) {
2983 output = xmlCtxtReadFd(ctxt, STDIN_FILENO,
"unknown.xml", NULL, xml_options);
2985 }
else if (uncompressed) {
2986 output = xmlCtxtReadFile(ctxt, filename, NULL, xml_options);
2989 char *input = decompress_file(filename);
2991 output = xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL, xml_options);
2995 if (output && (xml = xmlDocGetRootElement(output))) {
2999 last_error = xmlCtxtGetLastError(ctxt);
3000 if (last_error && last_error->code != XML_ERR_OK) {
3006 crm_err(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
3007 last_error->domain, last_error->level, last_error->code, last_error->message);
3009 if (last_error && last_error->code != XML_ERR_OK) {
3010 crm_err(
"Couldn't%s parse %s", xml ?
" fully" :
"", filename);
3017 xmlFreeParserCtxt(ctxt);
3032 time_t now = time(NULL);
3033 char *now_str = ctime(&now);
3049 for (c =
id; *c; ++c) {
3074 va_start(ap, format);
3075 len = vasprintf(&
id, format, ap);
3085 write_xml_stream(xmlNode * xml_node,
const char *filename, FILE * stream, gboolean compress)
3088 char *buffer = NULL;
3089 unsigned int out = 0;
3093 crm_trace(
"Writing XML out to %s", filename);
3094 if (xml_node == NULL) {
3095 crm_err(
"Cannot write NULL to %s", filename);
3110 unsigned int in = 0;
3111 BZFILE *bz_file = NULL;
3113 bz_file = BZ2_bzWriteOpen(&rc, stream, 5, 0, 30);
3115 crm_err(
"bzWriteOpen failed: %d", rc);
3117 BZ2_bzWrite(&rc, bz_file, buffer, strlen(buffer));
3119 crm_err(
"bzWrite() failed: %d", rc);
3124 BZ2_bzWriteClose(&rc, bz_file, 0, &in, &out);
3126 crm_err(
"bzWriteClose() failed: %d", rc);
3129 crm_trace(
"%s: In: %d, out: %d", filename, in, out);
3133 crm_err(
"Cannot write compressed files:" " bzlib was not available at compile time");
3138 res = fprintf(stream,
"%s", buffer);
3140 crm_perror(LOG_ERR,
"Cannot write output to %s", filename);
3147 if (fflush(stream) != 0) {
3148 crm_perror(LOG_ERR,
"fflush for %s failed", filename);
3153 if (fsync(fileno(stream)) < 0 && errno != EROFS && errno != EINVAL) {
3154 crm_perror(LOG_ERR,
"fsync for %s failed", filename);
3160 crm_trace(
"Saved %d bytes to the Cib as XML", res);
3167 write_xml_fd(xmlNode * xml_node,
const char *filename,
int fd, gboolean compress)
3169 FILE *stream = NULL;
3172 stream = fdopen(fd,
"w");
3173 return write_xml_stream(xml_node, filename, stream, compress);
3179 FILE *stream = NULL;
3181 stream = fopen(filename,
"w");
3183 return write_xml_stream(xml_node, filename, stream, compress);
3191 return __xml_first_child(tmp);
3204 crm_xml_escape_shuffle(
char *text,
int start,
int *length,
const char *replace)
3207 int offset = strlen(replace) - 1;
3210 text = realloc_safe(text, *length);
3212 for (lpc = (*length) - 1; lpc > (start + offset); lpc--) {
3213 text[lpc] = text[lpc - offset];
3216 memcpy(text + start, replace, offset + 1);
3225 int length = 1 + strlen(text);
3226 char *copy = strdup(text);
3243 for (index = 0; index < length; index++) {
3244 switch (copy[index]) {
3248 copy = crm_xml_escape_shuffle(copy, index, &length,
"<");
3252 copy = crm_xml_escape_shuffle(copy, index, &length,
">");
3256 copy = crm_xml_escape_shuffle(copy, index, &length,
""");
3260 copy = crm_xml_escape_shuffle(copy, index, &length,
"'");
3264 copy = crm_xml_escape_shuffle(copy, index, &length,
"&");
3269 copy = crm_xml_escape_shuffle(copy, index, &length,
" ");
3274 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\n");
3278 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\r");
3288 if(copy[index] <
' ' || copy[index] >
'~') {
3292 copy = crm_xml_escape_shuffle(copy, index, &length, replace);
3306 dump_xml_attr(xmlAttrPtr attr,
int options,
char **buffer,
int *offset,
int *max)
3308 char *p_value = NULL;
3309 const char *p_name = NULL;
3313 if (attr == NULL || attr->children == NULL) {
3322 p_name = (
const char *)attr->name;
3324 buffer_print(*buffer, *max, *offset,
" %s=\"%s\"", p_name, p_value);
3329 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
3330 const char *prefix, xmlNode *
data,
int depth,
int options)
3334 const char *name = NULL;
3335 const char *hidden = NULL;
3337 xmlNode *child = NULL;
3338 xmlAttrPtr pIter = NULL;
3344 name = crm_element_name(
data);
3347 char *buffer = NULL;
3349 insert_prefix(options, &buffer, &offset, &max, depth);
3351 if (
data->type == XML_COMMENT_NODE) {
3358 for (pIter = crm_first_attr(
data); pIter != NULL; pIter = pIter->next) {
3360 const char *p_name = (
const char *)pIter->name;
3361 const char *p_value = crm_attr_value(pIter);
3362 char *p_copy = NULL;
3371 }
else if (hidden != NULL && p_name[0] != 0 && strstr(hidden, p_name) != NULL) {
3372 p_copy = strdup(
"*****");
3378 buffer_print(buffer, max, offset,
" %s=\"%s\"", p_name, p_copy);
3393 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3397 if(
data->type == XML_COMMENT_NODE) {
3407 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3413 char *buffer = NULL;
3415 insert_prefix(options, &buffer, &offset, &max, depth);
3418 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3424 __xml_log_change_element(
int log_level,
const char *file,
const char *
function,
int line,
3425 const char *prefix, xmlNode *
data,
int depth,
int options)
3428 char *prefix_m = NULL;
3429 xmlNode *child = NULL;
3430 xmlAttrPtr pIter = NULL;
3438 prefix_m = strdup(prefix);
3443 __xml_log_element(log_level, file,
function, line,
3446 }
else if(is_set(p->flags,
xpf_dirty)) {
3447 char *spaces = calloc(80, 1);
3448 int s_count = 0, s_max = 80;
3449 char *prefix_del = NULL;
3450 char *prefix_moved = NULL;
3451 const char *
flags = prefix;
3453 insert_prefix(options, &spaces, &s_count, &s_max, depth);
3454 prefix_del = strdup(prefix);
3455 prefix_del[0] =
'-';
3456 prefix_del[1] =
'-';
3457 prefix_moved = strdup(prefix);
3458 prefix_moved[1] =
'~';
3461 flags = prefix_moved;
3466 __xml_log_element(log_level, file,
function, line,
3469 for (pIter = crm_first_attr(
data); pIter != NULL; pIter = pIter->next) {
3470 const char *aname = (
const char*)pIter->name;
3472 p = pIter->_private;
3477 "%s %s @%s=%s", flags, spaces, aname, value);
3479 }
else if(is_set(p->flags,
xpf_dirty)) {
3488 }
else if(is_set(p->flags,
xpf_moved)) {
3489 flags = prefix_moved;
3495 "%s %s @%s=%s", flags, spaces, aname, value);
3502 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3503 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3506 __xml_log_element(log_level, file,
function, line,
3510 for (child = __xml_first_child(
data); child != NULL; child = __xml_next(child)) {
3511 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3521 const char *prefix, xmlNode *
data,
int depth,
int options)
3523 xmlNode *a_child = NULL;
3525 char *prefix_m = NULL;
3527 if (prefix == NULL) {
3534 "No data to dump as XML");
3539 __xml_log_change_element(log_level, file,
function, line, prefix, data, depth, options);
3547 prefix_m = strdup(prefix);
3554 prefix_m = strdup(prefix);
3563 for (a_child = __xml_first_child(data); a_child != NULL; a_child = __xml_next(a_child)) {
3564 log_data_element(log_level, file,
function, line, prefix, a_child, depth + 1, options);
3567 __xml_log_element(log_level, file,
function, line, prefix, data, depth,
3574 dump_filtered_xml(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max)
3577 xmlAttrPtr xIter = NULL;
3578 static int filter_len =
DIMOF(filter);
3580 for (lpc = 0; options && lpc < filter_len; lpc++) {
3581 filter[lpc].found = FALSE;
3584 for (xIter = crm_first_attr(
data); xIter != NULL; xIter = xIter->next) {
3586 const char *p_name = (
const char *)xIter->name;
3588 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
3589 if (filter[lpc].found == FALSE && strcmp(p_name, filter[lpc].
string) == 0) {
3590 filter[lpc].found = TRUE;
3596 if (skip == FALSE) {
3597 dump_xml_attr(xIter, options, buffer, offset, max);
3603 dump_xml_element(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3605 const char *name = NULL;
3616 if (*buffer == NULL) {
3621 name = crm_element_name(
data);
3624 insert_prefix(options, buffer, offset, max, depth);
3628 dump_filtered_xml(
data, options, buffer, offset, max);
3631 xmlAttrPtr xIter = NULL;
3633 for (xIter = crm_first_attr(
data); xIter != NULL; xIter = xIter->next) {
3634 dump_xml_attr(xIter, options, buffer, offset, max);
3638 if (
data->children == NULL) {
3649 if (
data->children) {
3650 xmlNode *xChild = NULL;
3651 for(xChild =
data->children; xChild != NULL; xChild = xChild->next) {
3652 crm_xml_dump(xChild, options, buffer, offset, max, depth + 1);
3655 insert_prefix(options, buffer, offset, max, depth);
3658 if (options & xml_log_option_formatted) {
3665 dump_xml_text(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3676 if (*buffer == NULL) {
3681 insert_prefix(options, buffer, offset, max, depth);
3692 dump_xml_comment(xmlNode *
data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3703 if (*buffer == NULL) {
3708 insert_prefix(options, buffer, offset, max, depth);
3743 xmlBuffer *xml_buffer = NULL;
3751 xml_buffer = xmlBufferCreate();
3762 xmlBufferSetAllocationScheme(xml_buffer, XML_BUFFER_ALLOC_DOUBLEIT);
3766 *buffer = strdup((
char *)xml_buffer->content);
3770 if ((now + 1) < next) {
3772 crm_err(
"xmlNodeDump() -> %dbytes took %ds", *max, next - now);
3775 xmlBufferFree(xml_buffer);
3780 switch(data->type) {
3781 case XML_ELEMENT_NODE:
3783 dump_xml_element(data, options, buffer, offset, max, depth);
3788 dump_xml_text(data, options, buffer, offset, max, depth);
3791 case XML_COMMENT_NODE:
3792 dump_xml_comment(data, options, buffer, offset, max, depth);
3795 crm_warn(
"Unhandled type: %d", data->type);
3831 char *buffer = NULL;
3832 int offset = 0, max = 0;
3841 char *buffer = NULL;
3842 int offset = 0, max = 0;
3851 char *buffer = NULL;
3852 int offset = 0, max = 0;
3854 crm_xml_dump(an_xml_node, 0, &buffer, &offset, &max, 0);
3861 if (xml_root != NULL && xml_root->children != NULL) {
3895 char *value_copy = NULL;
3898 if (value != NULL) {
3899 value_copy = strdup(value);
3908 crm_trace(
"Cannot remove %s from %s", name, obj->name);
3910 }
else if(TRACKING_CHANGES(obj)) {
3913 xmlAttr *attr = xmlHasProp(obj, (
const xmlChar *)name);
3921 xmlUnsetProp(obj, (
const xmlChar *)name);
3928 xmlNode *child = NULL;
3933 for (child = __xml_first_child(a_node); child != NULL; child = __xml_next(child)) {
3943 if (filename == NULL) {
3951 crm_info(
"Saving %s to %s", desc, filename);
3959 gboolean result = TRUE;
3960 int root_nodes_seen = 0;
3961 static struct qb_log_callsite *digest_cs = NULL;
3965 xmlNode *child_diff = NULL;
3967 xmlNode *removed =
find_xml_node(diff,
"diff-removed", FALSE);
3970 if (digest_cs == NULL) {
3972 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
3977 for (child_diff = __xml_first_child(removed); child_diff != NULL;
3978 child_diff = __xml_next(child_diff)) {
3979 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
3980 if (root_nodes_seen == 0) {
3986 if (root_nodes_seen == 0) {
3989 }
else if (root_nodes_seen > 1) {
3990 crm_err(
"(-) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
3994 root_nodes_seen = 0;
3997 xmlNode *child_diff = NULL;
3999 for (child_diff = __xml_first_child(added); child_diff != NULL;
4000 child_diff = __xml_next(child_diff)) {
4001 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
4002 if (root_nodes_seen == 0) {
4009 if (root_nodes_seen > 1) {
4010 crm_err(
"(+) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
4013 }
else if (result && digest) {
4014 char *new_digest = NULL;
4019 crm_info(
"Digest mis-match: expected %s, calculated %s", digest, new_digest);
4022 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
4023 if (digest_cs && digest_cs->targets) {
4030 crm_trace(
"Digest matched: expected %s, calculated %s", digest, new_digest);
4034 }
else if (result) {
4042 __xml_diff_object(xmlNode * old, xmlNode *
new)
4044 xmlNode *cIter = NULL;
4045 xmlAttr *pIter = NULL;
4049 crm_node_created(
new);
4050 __xml_acl_post_process(
new);
4063 for (pIter = crm_first_attr(
new); pIter != NULL; pIter = pIter->next) {
4070 for (pIter = crm_first_attr(old); pIter != NULL; ) {
4071 xmlAttr *prop = pIter;
4073 const char *name = (
const char *)pIter->name;
4075 xmlAttr *exists = xmlHasProp(
new, pIter->name);
4077 pIter = pIter->next;
4078 if(exists == NULL) {
4079 p =
new->doc->_private;
4083 exists = xmlSetProp(
new, (
const xmlChar *)name, (
const xmlChar *)old_value);
4086 p = exists->_private;
4089 crm_trace(
"Lost %s@%s=%s", old->name, name, old_value);
4093 int p_new = __xml_offset((xmlNode*)exists);
4094 int p_old = __xml_offset((xmlNode*)prop);
4097 p = exists->_private;
4100 if(strcmp(value, old_value) != 0) {
4106 crm_trace(
"Modified %s@%s %s->%s", old->name, name, old_value, vcopy);
4107 xmlSetProp(
new, prop->name, (
const xmlChar *)old_value);
4111 }
else if(p_old != p_new) {
4112 crm_info(
"Moved %s@%s (%d -> %d)", old->name, name, p_old, p_new);
4113 __xml_node_dirty(
new);
4121 p = exists->_private;
4128 for (pIter = crm_first_attr(
new); pIter != NULL; ) {
4129 xmlAttr *prop = pIter;
4132 pIter = pIter->next;
4134 char *name = strdup((
const char *)prop->name);
4137 crm_trace(
"Created %s@%s=%s", new->name, name, value);
4140 crm_attr_dirty(prop);
4142 xmlUnsetProp(
new, prop->name);
4150 for (cIter = __xml_first_child(old); cIter != NULL; ) {
4151 xmlNode *old_child = cIter;
4152 xmlNode *new_child = find_element(
new, cIter, TRUE);
4154 cIter = __xml_next(cIter);
4156 __xml_diff_object(old_child, new_child);
4161 xmlNode *top = xmlDocGetRootElement(candidate->doc);
4163 __xml_node_clean(candidate);
4164 __xml_acl_apply(top);
4166 free_xml_with_position(candidate, __xml_offset(old_child));
4168 if (find_element(
new, old_child, TRUE) == NULL) {
4176 for (cIter = __xml_first_child(
new); cIter != NULL; ) {
4177 xmlNode *new_child = cIter;
4178 xmlNode *old_child = find_element(old, cIter, TRUE);
4180 cIter = __xml_next(cIter);
4181 if(old_child == NULL) {
4184 __xml_diff_object(old_child, new_child);
4188 int p_new = __xml_offset(new_child);
4189 int p_old = __xml_offset(old_child);
4191 if(p_old != p_new) {
4194 crm_info(
"%s.%s moved from %d to %d",
4195 new_child->name,
ID(new_child), p_old, p_new);
4196 __xml_node_dirty(
new);
4200 p = old_child->_private;
4202 p = new_child->_private;
4220 __xml_diff_object(old,
new);
4226 xmlNode *tmp1 = NULL;
4243 if (added->children == NULL && removed->children == NULL) {
4254 xmlNode *cIter = NULL;
4255 xmlAttrPtr pIter = NULL;
4256 gboolean can_prune = TRUE;
4257 const char *name = crm_element_name(xml_node);
4266 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4267 const char *p_name = (
const char *)pIter->name;
4275 cIter = __xml_first_child(xml_node);
4277 xmlNode *child = cIter;
4279 cIter = __xml_next(cIter);
4291 xmlNode * xml_node, xmlNode * parent)
4294 xmlNode *child = NULL;
4295 xmlAttrPtr pIter = NULL;
4296 xmlNode *new_parent = parent;
4297 const char *name = crm_element_name(xml_node);
4299 CRM_CHECK(xml_node != NULL && name != NULL,
return);
4302 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4303 const char *p_name = (
const char *)pIter->name;
4304 const char *p_value = crm_attr_value(pIter);
4306 lower_bound = context;
4310 if (lower_bound >= 0 || upper_bound >= 0) {
4316 if (upper_bound >= 0) {
4325 for (child = __xml_first_child(us); child != NULL; child = __xml_next(child)) {
4337 if (xml_node->properties) {
4340 }
else if (depth < context) {
4341 xmlNode *child = NULL;
4343 for (child = __xml_first_child(xml_node); child != NULL; child = __xml_next(child)) {
4353 find_xml_comment(xmlNode * root, xmlNode * search_comment, gboolean exact)
4355 xmlNode *a_child = NULL;
4356 int search_offset = __xml_offset(search_comment);
4358 CRM_CHECK(search_comment->type == XML_COMMENT_NODE,
return NULL);
4360 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
4362 int offset = __xml_offset(a_child);
4365 if (offset < search_offset) {
4368 }
else if (offset > search_offset) {
4377 if (a_child->type == XML_COMMENT_NODE
4378 &&
safe_str_eq((
const char *)a_child->content, (
const char *)search_comment->content)) {
4390 subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right,
4394 CRM_CHECK(left->type == XML_COMMENT_NODE,
return NULL);
4397 ||
safe_str_neq((
const char *)left->content, (
const char *)right->content)) {
4398 xmlNode *deleted = NULL;
4411 gboolean full, gboolean * changed,
const char *marker)
4413 gboolean dummy = FALSE;
4414 gboolean skip = FALSE;
4415 xmlNode *diff = NULL;
4416 xmlNode *right_child = NULL;
4417 xmlNode *left_child = NULL;
4418 xmlAttrPtr xIter = NULL;
4420 const char *
id = NULL;
4421 const char *name = NULL;
4422 const char *value = NULL;
4423 const char *right_val = NULL;
4426 static int filter_len =
DIMOF(filter);
4428 if (changed == NULL) {
4436 if (left->type == XML_COMMENT_NODE) {
4437 return subtract_xml_comment(parent, left, right, changed);
4441 if (right == NULL) {
4442 xmlNode *deleted = NULL;
4444 crm_trace(
"Processing <%s id=%s> (complete copy)", crm_element_name(left),
id);
4452 name = crm_element_name(left);
4458 if (value != NULL && strcmp(value,
"removed:top") == 0) {
4459 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
4468 for (lpc = 0; lpc < filter_len; lpc++) {
4469 filter[lpc].found = FALSE;
4473 for (left_child = __xml_first_child(left); left_child != NULL;
4474 left_child = __xml_next(left_child)) {
4475 gboolean child_changed = FALSE;
4477 right_child = find_element(right, left_child, FALSE);
4479 if (child_changed) {
4484 if (*changed == FALSE) {
4488 xmlAttrPtr pIter = NULL;
4490 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4491 const char *p_name = (
const char *)pIter->name;
4492 const char *p_value = crm_attr_value(pIter);
4494 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4501 xmlSetProp(diff, (
const xmlChar *)
XML_ATTR_ID, (
const xmlChar *)
id);
4505 for (xIter = crm_first_attr(left); xIter != NULL; xIter = xIter->next) {
4506 const char *prop_name = (
const char *)xIter->name;
4507 xmlAttrPtr right_attr = NULL;
4515 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
4516 if (filter[lpc].found == FALSE && strcmp(prop_name, filter[lpc].
string) == 0) {
4517 filter[lpc].found = TRUE;
4527 right_attr = xmlHasProp(right, (
const xmlChar *)prop_name);
4529 p = right_attr->_private;
4533 if (right_val == NULL || (p && is_set(p->flags,
xpf_deleted))) {
4537 xmlAttrPtr pIter = NULL;
4539 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4540 const char *p_name = (
const char *)pIter->name;
4541 const char *p_value = crm_attr_value(pIter);
4543 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4550 xmlSetProp(diff, (
const xmlChar *)prop_name, (
const xmlChar *)value);
4558 if (strcmp(left_value, right_val) == 0) {
4564 xmlAttrPtr pIter = NULL;
4566 crm_trace(
"Changes detected to %s in <%s id=%s>", prop_name,
4567 crm_element_name(left),
id);
4568 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4569 const char *p_name = (
const char *)pIter->name;
4570 const char *p_value = crm_attr_value(pIter);
4572 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4577 crm_trace(
"Changes detected to %s (%s -> %s) in <%s id=%s>",
4578 prop_name, left_value, right_val, crm_element_name(left),
id);
4585 if (*changed == FALSE) {
4589 }
else if (full == FALSE &&
id) {
4597 add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update)
4600 CRM_CHECK(update->type == XML_COMMENT_NODE,
return 0);
4602 if (target == NULL) {
4603 target = find_xml_comment(parent, update, FALSE);
4606 if (target == NULL) {
4610 }
else if (
safe_str_neq((
const char *)target->content, (
const char *)update->content)) {
4611 xmlFree(target->content);
4612 target->content = xmlStrdup(update->content);
4619 add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff)
4621 xmlNode *a_child = NULL;
4622 const char *object_id = NULL;
4623 const char *object_name = NULL;
4632 if (update->type == XML_COMMENT_NODE) {
4633 return add_xml_comment(parent, target, update);
4636 object_name = crm_element_name(update);
4637 object_id =
ID(update);
4639 CRM_CHECK(object_name != NULL,
return 0);
4641 if (target == NULL && object_id == NULL) {
4645 }
else if (target == NULL) {
4646 target =
find_entity(parent, object_name, object_id);
4649 if (target == NULL) {
4652 #if XML_PARSER_DEBUG 4654 object_id ?
" id=" :
"", object_id ? object_id :
"");
4657 crm_trace(
"Found node <%s%s%s/> to update",
4658 crm_str(object_name), object_id ?
" id=" :
"", object_id ? object_id :
"");
4664 if (as_diff == FALSE) {
4670 xmlAttrPtr pIter = NULL;
4672 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4673 const char *p_name = (
const char *)pIter->name;
4674 const char *p_value = crm_attr_value(pIter);
4677 xmlUnsetProp(target, (
const xmlChar *)p_name);
4678 xmlSetProp(target, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4682 for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
4683 #if XML_PARSER_DEBUG 4684 crm_trace(
"Updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
4689 #if XML_PARSER_DEBUG 4698 gboolean can_update = TRUE;
4699 xmlNode *child_of_child = NULL;
4702 CRM_CHECK(to_update != NULL,
return FALSE);
4704 if (
safe_str_neq(crm_element_name(to_update), crm_element_name(child))) {
4710 }
else if (can_update) {
4711 #if XML_PARSER_DEBUG 4717 for (child_of_child = __xml_first_child(child); child_of_child != NULL;
4718 child_of_child = __xml_next(child_of_child)) {
4731 const char *tag,
const char *field,
const char *value, gboolean search_matches)
4733 int match_found = 0;
4736 CRM_CHECK(children != NULL,
return FALSE);
4738 if (tag != NULL &&
safe_str_neq(tag, crm_element_name(root))) {
4743 if (*children == NULL) {
4750 if (search_matches || match_found == 0) {
4751 xmlNode *child = NULL;
4753 for (child = __xml_first_child(root); child != NULL; child = __xml_next(child)) {
4754 match_found +=
find_xml_children(children, child, tag, field, value, search_matches);
4764 gboolean can_delete = FALSE;
4765 xmlNode *child_of_child = NULL;
4767 const char *up_id = NULL;
4768 const char *child_id = NULL;
4769 const char *right_val = NULL;
4772 CRM_CHECK(update != NULL,
return FALSE);
4775 child_id =
ID(child);
4777 if (up_id == NULL || (child_id && strcmp(child_id, up_id) == 0)) {
4780 if (
safe_str_neq(crm_element_name(update), crm_element_name(child))) {
4783 if (can_delete && delete_only) {
4784 xmlAttrPtr pIter = NULL;
4786 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4787 const char *p_name = (
const char *)pIter->name;
4788 const char *p_value = crm_attr_value(pIter);
4797 if (can_delete && parent != NULL) {
4799 if (delete_only || update == NULL) {
4804 xmlDoc *doc = tmp->doc;
4805 xmlNode *old = NULL;
4808 old = xmlReplaceNode(child, tmp);
4812 __xml_acl_apply(tmp);
4816 xmlDocSetRootElement(doc, old);
4822 }
else if (can_delete) {
4827 child_of_child = __xml_first_child(child);
4828 while (child_of_child) {
4829 xmlNode *next = __xml_next(child_of_child);
4835 child_of_child = NULL;
4837 child_of_child = next;
4847 const char *name = key;
4848 const char *s_value = value;
4850 xmlNode *xml_node = user_data;
4857 crm_trace(
"dumped: name=%s value=%s", name, s_value);
4863 const char *name = key;
4864 const char *s_value = value;
4866 xmlNode *xml_node = user_data;
4868 if (isdigit(name[0])) {
4876 crm_trace(
"dumped: %s=%s", name, s_value);
4879 crm_trace(
"duplicate: %s=%s", name, s_value);
4886 const char *name = key;
4887 const char *s_value = value;
4889 xmlNode *xml_node = user_data;
4895 crm_trace(
"duplicate: %s=%s", name, s_value);
4902 char *crm_name = NULL;
4904 if (key == NULL || value == NULL) {
4911 for (crm_name = key; *crm_name; ++crm_name) {
4912 if ((*crm_name ==
'#') || (*crm_name ==
':')) {
4925 xmlNode *child = NULL;
4926 xmlAttrPtr pIter = NULL;
4927 xmlNode *nvpair_list = NULL;
4928 GHashTable *nvpair_hash = g_hash_table_new_full(
crm_str_hash, g_str_equal,
4931 CRM_CHECK(parent != NULL,
return nvpair_hash);
4934 if (nvpair_list == NULL) {
4935 crm_trace(
"No attributes in %s", crm_element_name(parent));
4941 for (pIter = crm_first_attr(nvpair_list); pIter != NULL; pIter = pIter->next) {
4942 const char *p_name = (
const char *)pIter->name;
4943 const char *p_value = crm_attr_value(pIter);
4945 crm_trace(
"Added %s=%s", p_name, p_value);
4947 g_hash_table_insert(nvpair_hash, strdup(p_name), strdup(p_value));
4950 for (child = __xml_first_child(nvpair_list); child != NULL; child = __xml_next(child)) {
4951 if (strcmp((
const char *)child->name,
XML_TAG_PARAM) == 0) {
4956 if (key != NULL && value != NULL) {
4957 g_hash_table_insert(nvpair_hash, strdup(key), strdup(value));
4965 typedef struct name_value_s {
4971 sort_pairs(gconstpointer a, gconstpointer b)
4983 rc = strcmp(pair_a->name, pair_b->name);
4986 }
else if (rc > 0) {
4993 dump_pair(gpointer
data, gpointer user_data)
4996 xmlNode *parent = user_data;
5002 sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive)
5004 xmlNode *child = NULL;
5008 xmlNode *result = NULL;
5009 const char *name = NULL;
5010 xmlAttrPtr pIter = NULL;
5014 name = crm_element_name(input);
5019 for (pIter = crm_first_attr(input); pIter != NULL; pIter = pIter->next) {
5020 const char *p_name = (
const char *)pIter->name;
5021 const char *p_value = crm_attr_value(pIter);
5024 pair->name = p_name;
5025 pair->value = p_value;
5026 unsorted = g_list_prepend(unsorted, pair);
5030 sorted = g_list_sort(unsorted, sort_pairs);
5031 g_list_foreach(sorted, dump_pair, result);
5032 g_list_free_full(sorted, free);
5034 for (child = __xml_first_child(input); child != NULL; child = __xml_next(child)) {
5048 xmlNode *match = NULL;
5050 for (match = __xml_first_child(parent); match != NULL; match = __xml_next(match)) {
5056 if (name == NULL || strcmp((
const char *)match->name, name) == 0) {
5066 static bool init = TRUE;
5075 xmlSetBufferAllocationScheme(XML_BUFFER_ALLOC_DOUBLEIT);
5078 xmlDeregisterNodeDefault(pcmkDeregisterNode);
5079 xmlRegisterNodeDefault(pcmkRegisterNode);
5088 crm_info(
"Cleaning up memory from libxml2");
5096 const char *tag = NULL;
5097 const char *ref = NULL;
5098 xmlNode *result = input;
5099 char *xpath_string = NULL;
5101 if (result == NULL) {
5104 }
else if (top == NULL) {
5108 tag = crm_element_name(result);
5112 int xpath_max = 512, offset = 0;
5114 xpath_string = calloc(1, xpath_max);
5116 offset += snprintf(xpath_string + offset, xpath_max - offset,
"//%s[@id='%s']", tag, ref);
5120 if (result == NULL) {
5121 char *nodePath = (
char *)xmlGetNodePath(top);
5123 crm_err(
"No match for %s found in %s: Invalid configuration", xpath_string,
5136 xmlAttr *attr = NULL;
5139 crm_err(
"Couldn't find %s in NULL", name ? name :
"<null>");
5143 }
else if (name == NULL) {
5144 crm_err(
"Couldn't find NULL in %s", crm_element_name(data));
5148 attr = xmlHasProp(data, (
const xmlChar *)name);
5149 if (attr == NULL || attr->children == NULL) {
5152 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
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
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
void crm_xml_set_id(xmlNode *xml, const char *format,...)
Set the ID of an XML element using a format.
#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)
struct xml_deleted_obj_s xml_deleted_obj_t