21 #include <sys/param.h>
23 #include <sys/types.h>
41 # include <libxml/parser.h>
42 # include <libxml/tree.h>
45 #define XML_BUFFER_SIZE 4096
46 #define XML_PARSER_DEBUG 0
49 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset);
77 typedef struct xml_private_s
86 typedef struct xml_acl_s {
91 typedef struct xml_deleted_obj_s {
98 static filter_t filter[] = {
107 static xmlNode *subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right, gboolean * changed);
108 static xmlNode *find_xml_comment(xmlNode * root, xmlNode * search_comment, gboolean exact);
109 static int add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update);
110 static bool __xml_acl_check(xmlNode *xml,
const char *name,
enum xml_private_flags mode);
113 #define CHUNK_SIZE 1024
114 static inline bool TRACKING_CHANGES(xmlNode *xml)
116 if(xml == NULL || xml->doc == NULL || xml->doc->_private == NULL) {
124 #define buffer_print(buffer, max, offset, fmt, args...) do { \
127 rc = snprintf((buffer) + (offset), (max) - (offset), fmt, ##args); \
129 if(buffer && rc < 0) { \
130 crm_perror(LOG_ERR, "snprintf failed at offset %d", offset); \
131 (buffer)[(offset)] = 0; \
133 } else if(rc >= ((max) - (offset))) { \
135 (max) = QB_MAX(CHUNK_SIZE, (max) * 2); \
136 tmp = realloc_safe((buffer), (max)); \
146 insert_prefix(
int options,
char **buffer,
int *offset,
int *max,
int depth)
149 size_t spaces = 2 * depth;
151 if ((*buffer) == NULL || spaces >= ((*max) - (*offset))) {
153 (*buffer) = realloc_safe((*buffer), (*max));
155 memset((*buffer) + (*offset),
' ', spaces);
161 set_parent_flag(xmlNode *xml,
long flag)
164 for(; xml; xml = xml->parent) {
177 set_doc_flag(xmlNode *xml,
long flag)
180 if(xml && xml->doc && xml->doc->_private){
190 __xml_node_dirty(xmlNode *xml)
197 __xml_node_clean(xmlNode *xml)
199 xmlNode *cIter = NULL;
206 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
207 __xml_node_clean(cIter);
212 crm_node_created(xmlNode *xml)
214 xmlNode *cIter = NULL;
217 if(p && TRACKING_CHANGES(xml)) {
220 __xml_node_dirty(xml);
223 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
224 crm_node_created(cIter);
230 crm_attr_dirty(xmlAttr *a)
232 xmlNode *parent = a->parent;
241 __xml_node_dirty(parent);
244 int get_tag_name(
const char *input,
size_t offset,
size_t max);
245 int get_attr_name(
const char *input,
size_t offset,
size_t max);
250 xmlNode * xml_node, xmlNode * parent);
252 int add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff);
254 static inline const char *
255 crm_attr_value(xmlAttr * attr)
257 if (attr == NULL || attr->children == NULL) {
260 return (
const char *)attr->children->content;
263 static inline xmlAttr *
264 crm_first_attr(xmlNode * xml)
269 return xml->properties;
272 #define XML_PRIVATE_MAGIC (long) 0x81726354
275 __xml_acl_free(
void *
data)
286 __xml_deleted_obj_free(
void *
data)
291 free(deleted_obj->path);
306 g_list_free_full(p->acls, __xml_acl_free);
310 if(p->deleted_objs) {
311 g_list_free_full(p->deleted_objs, __xml_deleted_obj_free);
312 p->deleted_objs = NULL;
321 __xml_private_clean(p);
326 pcmkDeregisterNode(xmlNodePtr node)
328 __xml_private_free(node->_private);
332 pcmkRegisterNode(xmlNodePtr node)
337 case XML_ELEMENT_NODE:
338 case XML_DOCUMENT_NODE:
339 case XML_ATTRIBUTE_NODE:
340 case XML_COMMENT_NODE:
349 case XML_CDATA_SECTION_NODE:
353 crm_trace(
"Ignoring %p %d", node, node->type);
358 if(p && TRACKING_CHANGES(node)) {
363 __xml_node_dirty(node);
386 if(target == NULL || target->doc == NULL || target->doc->_private == NULL){
392 }
else if (tag == NULL && ref == NULL && xpath == NULL) {
397 p = target->doc->_private;
404 acl->xpath = strdup(xpath);
405 crm_trace(
"Using xpath: %s", acl->xpath);
412 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"//%s", tag);
422 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@id='%s'", ref);
426 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
" and ");
430 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"@%s", attr);
438 acl->xpath = strdup(buffer);
439 crm_trace(
"Built xpath: %s", acl->xpath);
442 p->acls = g_list_append(p->acls, acl);
448 __xml_acl_parse_entry(xmlNode * acl_top, xmlNode * acl_entry, xmlNode *target)
450 xmlNode *child = NULL;
452 for (child = __xml_first_child(acl_entry); child; child = __xml_next(child)) {
453 const char *tag = crm_element_name(child);
460 crm_trace(
"Processing %s %p", tag, child);
469 xmlNode *role = NULL;
471 for (role = __xml_first_child(acl_top); role; role = __xml_next(role)) {
475 if (role_id && strcmp(ref_role, role_id) == 0) {
476 crm_debug(
"Unpacking referenced role: %s", role_id);
477 __xml_acl_parse_entry(acl_top, role, target);
494 crm_warn(
"Unknown ACL entry: %s/%s", tag, kind);
540 __xml_acl_apply(xmlNode *xml)
544 xmlXPathObjectPtr xpathObj = NULL;
547 p = xml->doc->_private;
548 crm_trace(
"Not applying ACLs for %s", p->user);
552 p = xml->doc->_private;
553 for(aIter = p->acls; aIter != NULL; aIter = aIter->next) {
554 int max = 0, lpc = 0;
558 max = numXpathResults(xpathObj);
560 for(lpc = 0; lpc < max; lpc++) {
565 crm_trace(
"Applying %x to %s for %s", acl->mode, path, acl->xpath);
567 #ifdef SUSE_ACL_COMPAT
568 if(is_not_set(p->flags, acl->mode)) {
572 crm_config_warn(
"Configuration element %s is matched by multiple ACL rules, only the first applies ('%s' wins over '%s')",
580 p->flags |= acl->mode;
583 crm_trace(
"Now enforcing ACL: %s (%d matches)", acl->xpath, max);
590 p = xml->doc->_private;
591 crm_info(
"Enforcing default ACL for %s to %s", p->user, crm_element_name(xml));
597 __xml_acl_unpack(xmlNode *source, xmlNode *target,
const char *user)
602 if(target == NULL || target->doc == NULL || target->doc->_private == NULL) {
606 p = target->doc->_private;
608 crm_trace(
"no acls needed for '%s'", user);
610 }
else if(p->acls == NULL) {
614 p->user = strdup(user);
617 xmlNode *child = NULL;
619 for (child = __xml_first_child(acls); child; child = __xml_next(child)) {
620 const char *tag = crm_element_name(child);
625 if(
id && strcmp(
id, user) == 0) {
627 __xml_acl_parse_entry(acls, child, target);
642 }
else if(is_set(allowed, requested)) {
661 __xml_purge_attributes(xmlNode *xml)
663 xmlNode *child = NULL;
664 xmlAttr *xIter = NULL;
665 bool readable_children = FALSE;
669 crm_trace(
"%s[@id=%s] is readable", crm_element_name(xml),
ID(xml));
673 xIter = crm_first_attr(xml);
674 while(xIter != NULL) {
675 xmlAttr *tmp = xIter;
676 const char *prop_name = (
const char *)xIter->name;
683 xmlUnsetProp(xml, tmp->name);
686 child = __xml_first_child(xml);
687 while ( child != NULL ) {
688 xmlNode *tmp = child;
690 child = __xml_next(child);
691 readable_children |= __xml_purge_attributes(tmp);
694 if(readable_children == FALSE) {
697 return readable_children;
704 xmlNode *target = NULL;
710 crm_trace(
"no acls needed for '%s'", user);
714 crm_trace(
"filtering copy of %p for '%s'", xml, user);
720 __xml_acl_unpack(acl_source, target, user);
722 __xml_acl_apply(target);
724 doc = target->doc->_private;
725 for(aIter = doc->acls; aIter != NULL && target; aIter = aIter->next) {
732 }
else if(acl->xpath) {
734 xmlXPathObjectPtr xpathObj =
xpath_search(target, acl->xpath);
736 max = numXpathResults(xpathObj);
737 for(lpc = 0; lpc < max; lpc++) {
740 crm_trace(
"Purging attributes from %s", acl->xpath);
741 if(__xml_purge_attributes(match) == FALSE && match == target) {
742 crm_trace(
"No access to the entire document for %s", user);
747 crm_trace(
"Enforced ACL %s (%d matches)", acl->xpath, max);
752 p = target->_private;
753 if(is_set(p->flags,
xpf_acl_deny) && __xml_purge_attributes(target) == FALSE) {
754 crm_trace(
"No access to the entire document for %s", user);
759 g_list_free_full(doc->acls, __xml_acl_free);
763 crm_trace(
"Ordinary user '%s' cannot access the CIB without any defined ACLs", doc->user);
776 __xml_acl_post_process(xmlNode * xml)
778 xmlNode *cIter = __xml_first_child(xml);
782 xmlAttr *xIter = NULL;
789 for (xIter = crm_first_attr(xml); xIter != NULL; xIter = xIter->next) {
790 const char *prop_name = (
const char *)xIter->name;
797 crm_trace(
"Creation of %s=%s is allowed", crm_element_name(xml),
ID(xml));
801 crm_trace(
"Cannot add new node %s at %s", crm_element_name(xml), path);
803 if(xml != xmlDocGetRootElement(xml->doc)) {
814 while (cIter != NULL) {
815 xmlNode *child = cIter;
816 cIter = __xml_next(cIter);
817 __xml_acl_post_process(child);
824 if(xml && xml->doc && xml->doc->_private){
839 __xml_acl_apply(xml);
840 __xml_acl_post_process(xml);
848 if(xml && xml->doc && xml->doc->_private){
860 crm_trace(
"Tracking changes%s to %p", enforce_acls?
" with ACLs":
"", xml);
863 if(acl_source == NULL) {
867 __xml_acl_unpack(acl_source, xml, user);
868 __xml_acl_apply(xml);
885 if(xml != NULL && xml->doc && xml->doc->_private) {
941 static int __xml_offset(xmlNode *xml)
944 xmlNode *cIter = NULL;
946 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
949 if(is_not_set(p->flags,
xpf_skip)) {
957 static int __xml_offset_no_deletions(xmlNode *xml)
960 xmlNode *cIter = NULL;
962 for(cIter = xml; cIter->prev; cIter = cIter->prev) {
974 __xml_build_changes(xmlNode * xml, xmlNode *patchset)
976 xmlNode *cIter = NULL;
977 xmlAttr *pIter = NULL;
978 xmlNode *change = NULL;
985 if(__get_prefix(NULL, xml->parent, buffer, offset) > 0) {
986 int position = __xml_offset_no_deletions(xml);
999 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1000 xmlNode *attr = NULL;
1002 p = pIter->_private;
1007 if(change == NULL) {
1011 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1036 xmlNode *result = NULL;
1041 for (pIter = crm_first_attr(xml); pIter != NULL; pIter = pIter->next) {
1044 p = pIter->_private;
1046 crm_xml_add(result, (
const char *)pIter->name, value);
1051 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1052 __xml_build_changes(cIter, patchset);
1056 if(patchset && is_set(p->flags,
xpf_moved)) {
1060 crm_trace(
"%s.%s moved to position %d", xml->name,
ID(xml), __xml_offset(xml));
1061 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
1072 __xml_accept_changes(xmlNode * xml)
1074 xmlNode *cIter = NULL;
1075 xmlAttr *pIter = NULL;
1079 pIter = crm_first_attr(xml);
1081 while (pIter != NULL) {
1082 const xmlChar *name = pIter->name;
1084 p = pIter->_private;
1085 pIter = pIter->next;
1095 for (cIter = __xml_first_child(xml); cIter != NULL; cIter = __xml_next(cIter)) {
1096 __xml_accept_changes(cIter);
1101 is_config_change(xmlNode *xml)
1108 p = config->_private;
1114 if(xml->doc && xml->doc->_private) {
1115 p = xml->doc->_private;
1116 for(gIter = p->deleted_objs; gIter; gIter = gIter->next) {
1129 xml_repair_v1_diff(xmlNode * last, xmlNode * next, xmlNode * local_diff, gboolean changed)
1132 xmlNode *cib = NULL;
1133 xmlNode *diff_child = NULL;
1135 const char *tag = NULL;
1137 const char *vfields[] = {
1143 if (local_diff == NULL) {
1148 tag =
"diff-removed";
1150 if (diff_child == NULL) {
1160 for(lpc = 0; last && lpc <
DIMOF(vfields); lpc++){
1164 if(changed || lpc == 2) {
1171 if (diff_child == NULL) {
1181 for(lpc = 0; next && lpc <
DIMOF(vfields); lpc++){
1188 xmlAttrPtr xIter = NULL;
1190 for (xIter = next->properties; xIter; xIter = xIter->next) {
1191 const char *p_name = (
const char *)xIter->name;
1194 xmlSetProp(cib, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
1202 xml_create_patchset_v1(xmlNode *source, xmlNode *target,
bool config,
bool suppress)
1208 xml_repair_v1_diff(source, target, patchset, config);
1215 xml_create_patchset_v2(xmlNode *source, xmlNode *target)
1223 xmlNode *patchset = NULL;
1224 const char *vfields[] = {
1236 doc = target->doc->_private;
1244 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1254 for(lpc = 0; lpc <
DIMOF(vfields); lpc++){
1263 for(gIter = doc->deleted_objs; gIter; gIter = gIter->next) {
1269 if (deleted_obj->position >= 0) {
1274 __xml_build_changes(target, patchset);
1278 static gboolean patch_legacy_mode(
void)
1280 static gboolean init = TRUE;
1281 static gboolean legacy = FALSE;
1297 bool config = FALSE;
1298 xmlNode *patch = NULL;
1307 config = is_config_change(target);
1308 if(config_changed) {
1309 *config_changed = config;
1312 if(manage_version && config) {
1319 }
else if(manage_version) {
1326 if(patch_legacy_mode()) {
1335 crm_trace(
"Using patch format %d for version: %s", format, version);
1340 patch = xml_create_patchset_v1(source, target, config, FALSE);
1343 patch = xml_create_patchset_v2(source, target);
1346 crm_err(
"Unknown patch format: %d", format);
1357 const char *version = NULL;
1358 char *digest = NULL;
1360 if (patch == NULL || source == NULL || target == NULL) {
1369 if (format > 1 && with_digest == FALSE) {
1383 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
1384 const char *prefix, xmlNode * data,
int depth,
int options);
1390 xmlNode *child = NULL;
1391 xmlNode *added = NULL;
1392 xmlNode *removed = NULL;
1393 gboolean is_first = TRUE;
1395 int add[] = { 0, 0, 0 };
1396 int del[] = { 0, 0, 0 };
1398 const char *fmt = NULL;
1399 const char *digest = NULL;
1402 static struct qb_log_callsite *patchset_cs = NULL;
1404 if (patchset_cs == NULL) {
1405 patchset_cs = qb_log_callsite_get(
function, __FILE__,
"xml-patchset", log_level, __LINE__, 0);
1408 if (patchset == NULL) {
1412 }
else if (log_level == 0) {
1422 if (add[2] != del[2] || add[1] != del[1] || add[0] != del[0]) {
1424 "Diff: --- %d.%d.%d %s", del[0], del[1], del[2], fmt);
1426 "Diff: +++ %d.%d.%d %s", add[0], add[1], add[2], digest);
1428 }
else if (patchset != NULL && (add[0] || add[1] || add[2])) {
1430 "%s: Local-only Change: %d.%d.%d",
function ?
function :
"",
1431 add[0], add[1], add[2]);
1436 xmlNode *change = NULL;
1438 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
1443 }
else if(strcmp(op,
"create") == 0) {
1444 int lpc = 0, max = 0;
1447 max = strlen(prefix);
1448 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1451 for(lpc = 2; lpc < max; lpc++) {
1455 __xml_log_element(log_level, __FILE__,
function, __LINE__, prefix, change->children,
1459 }
else if(strcmp(op,
"move") == 0) {
1462 }
else if(strcmp(op,
"modify") == 0) {
1470 buffer_unset[0] = 0;
1471 for (child = __xml_first_child(clist); child != NULL; child = __xml_next(child)) {
1476 }
else if(strcmp(op,
"set") == 0) {
1482 o_set += snprintf(buffer_set + o_set,
XML_BUFFER_SIZE - o_set,
"@%s=%s", name, value);
1484 }
else if(strcmp(op,
"unset") == 0) {
1486 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
", ");
1488 o_unset += snprintf(buffer_unset + o_unset,
XML_BUFFER_SIZE - o_unset,
"@%s", name);
1492 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"+ %s: %s", xpath, buffer_set);
1495 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s: %s", xpath, buffer_unset);
1498 }
else if(strcmp(op,
"delete") == 0) {
1502 if (position >= 0) {
1503 do_crm_log_alias(log_level, __FILE__,
function, __LINE__,
"-- %s (%d)", xpath, position);
1513 if (log_level < LOG_DEBUG ||
function == NULL) {
1518 for (child = __xml_first_child(removed); child != NULL; child = __xml_next(child)) {
1530 for (child = __xml_first_child(added); child != NULL; child = __xml_next(child)) {
1550 doc = xml->doc->_private;
1555 for(gIter = doc->deleted_objs; gIter; gIter = gIter->next) {
1558 if (deleted_obj->position >= 0) {
1560 deleted_obj->path, deleted_obj->position);
1575 xmlNode *top = NULL;
1582 crm_trace(
"Accepting changes to %p", xml);
1583 doc = xml->doc->_private;
1584 top = xmlDocGetRootElement(xml->doc);
1586 __xml_private_clean(xml->doc->_private);
1594 __xml_accept_changes(top);
1598 find_element(xmlNode *haystack, xmlNode *needle, gboolean exact)
1601 return (needle->type == XML_COMMENT_NODE)?
1602 find_xml_comment(haystack, needle, exact)
1603 :
find_entity(haystack, crm_element_name(needle),
ID(needle));
1608 __subtract_xml_object(xmlNode * target, xmlNode * patch)
1610 xmlNode *patch_child = NULL;
1611 xmlNode *cIter = NULL;
1612 xmlAttrPtr xIter = NULL;
1615 const char *name = NULL;
1616 const char *value = NULL;
1618 if (target == NULL || patch == NULL) {
1622 if (target->type == XML_COMMENT_NODE) {
1625 subtract_xml_comment(target->parent, target, patch, &dummy);
1628 name = crm_element_name(target);
1636 if (value != NULL && strcmp(value,
"removed:top") == 0) {
1637 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
1643 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1644 const char *p_name = (
const char *)xIter->name;
1653 cIter = __xml_first_child(target);
1655 xmlNode *target_child = cIter;
1657 cIter = __xml_next(cIter);
1658 patch_child = find_element(patch, target_child, FALSE);
1659 __subtract_xml_object(target_child, patch_child);
1665 __add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * patch)
1667 xmlNode *patch_child = NULL;
1668 xmlNode *target_child = NULL;
1669 xmlAttrPtr xIter = NULL;
1671 const char *
id = NULL;
1672 const char *name = NULL;
1673 const char *value = NULL;
1675 if (patch == NULL) {
1677 }
else if (parent == NULL && target == NULL) {
1685 && strcmp(value,
"added:top") == 0) {
1687 name = crm_element_name(patch);
1688 crm_trace(
"We are the root of the addition: %s.id=%s", name,
id);
1692 }
else if(target == NULL) {
1694 name = crm_element_name(patch);
1695 crm_err(
"Could not locate: %s.id=%s", name,
id);
1699 if (target->type == XML_COMMENT_NODE) {
1700 add_xml_comment(parent, target, patch);
1703 name = crm_element_name(target);
1708 for (xIter = crm_first_attr(patch); xIter != NULL; xIter = xIter->next) {
1709 const char *p_name = (
const char *)xIter->name;
1717 for (patch_child = __xml_first_child(patch); patch_child != NULL;
1718 patch_child = __xml_next(patch_child)) {
1720 target_child = find_element(target, patch_child, FALSE);
1721 __add_xml_object(target, target_child, patch_child);
1737 find_patch_xml_node(xmlNode *patchset,
int format,
bool added,
1738 xmlNode **patch_node)
1745 label = added?
"diff-added" :
"diff-removed";
1748 if (cib_node != NULL) {
1749 *patch_node = cib_node;
1753 label = added?
"target" :
"source";
1758 crm_warn(
"Unknown patch format: %d", format);
1769 xmlNode *tmp = NULL;
1771 const char *vfields[] = {
1781 if (!find_patch_xml_node(patchset, format, FALSE, &tmp)) {
1785 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1787 crm_trace(
"Got %d for del[%s]", del[lpc], vfields[lpc]);
1792 if (!find_patch_xml_node(patchset, format, TRUE, &tmp)) {
1796 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1798 crm_trace(
"Got %d for add[%s]", add[lpc], vfields[lpc]);
1806 xml_patch_version_check(xmlNode *xml, xmlNode *patchset,
int format)
1809 bool changed = FALSE;
1811 int this[] = { 0, 0, 0 };
1812 int add[] = { 0, 0, 0 };
1813 int del[] = { 0, 0, 0 };
1815 const char *vfields[] = {
1821 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1823 crm_trace(
"Got %d for this[%s]",
this[lpc], vfields[lpc]);
1824 if (
this[lpc] < 0) {
1832 add[2] =
this[2] + 1;
1833 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1834 del[lpc] =
this[lpc];
1839 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1840 if(
this[lpc] < del[lpc]) {
1841 crm_debug(
"Current %s is too low (%d.%d.%d < %d.%d.%d --> %d.%d.%d)", vfields[lpc],
1842 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2]);
1845 }
else if(
this[lpc] > del[lpc]) {
1846 crm_info(
"Current %s is too high (%d.%d.%d > %d.%d.%d --> %d.%d.%d) %p", vfields[lpc],
1847 this[0],
this[1],
this[2], del[0], del[1], del[2], add[0], add[1], add[2], patchset);
1853 for(lpc = 0; lpc <
DIMOF(vfields); lpc++) {
1854 if(add[lpc] > del[lpc]) {
1859 if(changed == FALSE) {
1860 crm_notice(
"Versions did not change in patch %d.%d.%d", add[0], add[1], add[2]);
1864 crm_debug(
"Can apply patch %d.%d.%d to %d.%d.%d",
1865 add[0], add[1], add[2],
this[0],
this[1],
this[2]);
1870 xml_apply_patchset_v1(xmlNode *xml, xmlNode *patchset)
1873 int root_nodes_seen = 0;
1875 xmlNode *child_diff = NULL;
1876 xmlNode *added =
find_xml_node(patchset,
"diff-added", FALSE);
1877 xmlNode *removed =
find_xml_node(patchset,
"diff-removed", FALSE);
1881 for (child_diff = __xml_first_child(removed); child_diff != NULL;
1882 child_diff = __xml_next(child_diff)) {
1883 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1884 if (root_nodes_seen == 0) {
1885 __subtract_xml_object(xml, child_diff);
1890 if (root_nodes_seen > 1) {
1891 crm_err(
"(-) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1895 root_nodes_seen = 0;
1898 xmlNode *child_diff = NULL;
1900 for (child_diff = __xml_first_child(added); child_diff != NULL;
1901 child_diff = __xml_next(child_diff)) {
1902 CRM_CHECK(root_nodes_seen == 0, rc = FALSE);
1903 if (root_nodes_seen == 0) {
1904 __add_xml_object(NULL, xml, child_diff);
1910 if (root_nodes_seen > 1) {
1911 crm_err(
"(+) Diffs cannot contain more than one change set... saw %d", root_nodes_seen);
1922 __first_xml_child_match(xmlNode *parent,
const char *name,
const char *
id,
int position)
1924 xmlNode *cIter = NULL;
1926 for (cIter = __xml_first_child(parent); cIter != NULL; cIter = __xml_next(cIter)) {
1927 if(strcmp((
const char *)cIter->name, name) != 0) {
1930 const char *cid =
ID(cIter);
1931 if(cid == NULL || strcmp(cid,
id) != 0) {
1937 if (cIter->type == XML_COMMENT_NODE
1939 && __xml_offset(cIter) != position) {
1949 __xml_find_path(xmlNode *top,
const char *key,
int target_position)
1951 xmlNode *target = (xmlNode*)top->doc;
1955 char *current = strdup(key);
1960 rc = sscanf (current,
"/%[^/]%s", section, remainder);
1970 }
else if(tag && section) {
1971 int f = sscanf (section,
"%[^[][@id='%[^']", tag,
id);
1972 int current_position = -1;
1975 if (rc == 1 && target_position >= 0) {
1976 current_position = target_position;
1981 target = __first_xml_child_match(target, tag, NULL, current_position);
1984 target = __first_xml_child_match(target, tag,
id, current_position);
1992 if(rc == 1 || target == NULL) {
1997 char *tmp = current;
1998 current = remainder;
2005 char *path = (
char *)xmlGetNodePath(target);
2007 crm_trace(
"Found %s for %s", path, key);
2022 xml_apply_patchset_v2(xmlNode *xml, xmlNode *patchset)
2025 xmlNode *change = NULL;
2026 for (change = __xml_first_child(patchset); change != NULL; change = __xml_next(change)) {
2027 xmlNode *match = NULL;
2032 crm_trace(
"Processing %s %s", change->name, op);
2037 if(strcmp(op,
"delete") == 0) {
2043 match = __xml_find_path(xml, xpath, position);
2045 crm_trace(
"Performing %s on %s with %p", op, xpath, match);
2047 if(match == NULL && strcmp(op,
"delete") == 0) {
2048 crm_debug(
"No %s match for %s in %p", op, xpath, xml->doc);
2051 }
else if(match == NULL) {
2052 crm_err(
"No %s match for %s in %p", op, xpath, xml->doc);
2056 }
else if(strcmp(op,
"create") == 0) {
2058 xmlNode *child = NULL;
2059 xmlNode *match_child = NULL;
2061 match_child = match->children;
2064 while(match_child && position != __xml_offset(match_child)) {
2065 match_child = match_child->next;
2068 child = xmlDocCopyNode(change->children, match->doc, 1);
2070 crm_trace(
"Adding %s at position %d", child->name, position);
2071 xmlAddPrevSibling(match_child, child);
2073 }
else if(match->last) {
2074 crm_trace(
"Adding %s at position %d (end)", child->name, position);
2075 xmlAddNextSibling(match->last, child);
2078 crm_trace(
"Adding %s at position %d (first)", child->name, position);
2080 xmlAddChild(match, child);
2082 crm_node_created(child);
2084 }
else if(strcmp(op,
"move") == 0) {
2088 if(position != __xml_offset(match)) {
2089 xmlNode *match_child = NULL;
2092 if(p > __xml_offset(match)) {
2097 match_child = match->parent->children;
2099 while(match_child && p != __xml_offset(match_child)) {
2100 match_child = match_child->next;
2103 crm_trace(
"Moving %s to position %d (was %d, prev %p, %s %p)",
2104 match->name, position, __xml_offset(match), match->prev,
2105 match_child?
"next":
"last", match_child?match_child:match->parent->last);
2108 xmlAddPrevSibling(match_child, match);
2112 xmlAddNextSibling(match->parent->last, match);
2116 crm_trace(
"%s is already in position %d", match->name, position);
2119 if(position != __xml_offset(match)) {
2120 crm_err(
"Moved %s.%d to position %d instead of %d (%p)",
2121 match->name,
ID(match), __xml_offset(match), position, match->prev);
2125 }
else if(strcmp(op,
"delete") == 0) {
2128 }
else if(strcmp(op,
"modify") == 0) {
2129 xmlAttr *pIter = crm_first_attr(match);
2136 while(pIter != NULL) {
2137 const char *name = (
const char *)pIter->name;
2139 pIter = pIter->next;
2143 for (pIter = crm_first_attr(attrs); pIter != NULL; pIter = pIter->next) {
2144 const char *name = (
const char *)pIter->name;
2151 crm_err(
"Unknown operation: %s", op);
2162 xmlNode *old = NULL;
2165 if(patchset == NULL) {
2173 rc = xml_patch_version_check(xml, patchset, format);
2187 rc = xml_apply_patchset_v1(xml, patchset);
2190 rc = xml_apply_patchset_v2(xml, patchset);
2193 crm_err(
"Unknown patch format: %d", format);
2199 static struct qb_log_callsite *digest_cs = NULL;
2201 char *new_digest = NULL;
2204 if (digest_cs == NULL) {
2206 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
2212 crm_info(
"v%d digest mis-match: expected %s, calculated %s", format, digest, new_digest);
2215 if (digest_cs && digest_cs->targets) {
2221 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
2225 crm_trace(
"v%d digest matched: expected %s, calculated %s", format, digest, new_digest);
2237 xmlNode *a_child = NULL;
2238 const char *name =
"NULL";
2241 name = crm_element_name(root);
2244 if (search_path == NULL) {
2245 crm_warn(
"Will never find <NULL>");
2249 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
2250 if (strcmp((
const char *)a_child->name, search_path) == 0) {
2257 crm_warn(
"Could not find %s in %s.", search_path, name);
2258 }
else if (root != NULL) {
2259 crm_trace(
"Could not find %s in %s.", search_path, name);
2261 crm_trace(
"Could not find %s in <NULL>.", search_path);
2270 xmlNode *a_child = NULL;
2272 for (a_child = __xml_first_child(parent); a_child != NULL; a_child = __xml_next(a_child)) {
2274 if (node_name == NULL || strcmp((
const char *)a_child->name, node_name) == 0) {
2275 const char *cid =
ID(a_child);
2276 if (
id == NULL || (cid != NULL && strcmp(
id, cid) == 0)) {
2282 crm_trace(
"node <%s id=%s> not found in %s.", node_name,
id, crm_element_name(parent));
2290 crm_warn(
"No node to copy properties from");
2292 }
else if (target == NULL) {
2293 crm_err(
"No node to copy properties into");
2296 xmlAttrPtr pIter = NULL;
2298 for (pIter = crm_first_attr(src); pIter != NULL; pIter = pIter->next) {
2299 const char *p_name = (
const char *)pIter->name;
2300 const char *p_value = crm_attr_value(pIter);
2313 xmlNode *child = NULL;
2314 xmlAttrPtr pIter = NULL;
2316 for (pIter = crm_first_attr(target); pIter != NULL; pIter = pIter->next) {
2317 const char *p_name = (
const char *)pIter->name;
2318 const char *p_value = crm_attr_value(pIter);
2322 for (child = __xml_first_child(target); child != NULL; child = __xml_next(child)) {
2335 const char *old_value = NULL;
2337 if (value == NULL || name == NULL) {
2343 if (old_value == NULL) {
2345 goto set_unexpanded;
2347 }
else if (strstr(value, name) != value) {
2348 goto set_unexpanded;
2351 name_len = strlen(name);
2352 value_len = strlen(value);
2353 if (value_len < (name_len + 2)
2354 || value[name_len] !=
'+' || (value[name_len + 1] !=
'+' && value[name_len + 1] !=
'=')) {
2355 goto set_unexpanded;
2361 if (old_value != value) {
2365 if (value[name_len + 1] !=
'+') {
2366 const char *offset_s = value + (name_len + 2);
2370 int_value += offset;
2380 if (old_value == value) {
2397 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2398 xmlDocSetRootElement(doc, node);
2399 xmlSetTreeDoc(node, doc);
2407 xmlNode *child = NULL;
2410 CRM_CHECK(src_node != NULL,
return NULL);
2412 child = xmlDocCopyNode(src_node, doc, 1);
2413 xmlAddChild(parent, child);
2414 crm_node_created(child);
2437 xmlNode *parent = xml;
2441 if(docp->acls == NULL) {
2442 crm_trace(
"Ordinary user %s cannot access the CIB without any defined ACLs", docp->user);
2447 offset = __get_prefix(NULL, xml, buffer, offset);
2449 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"[@%s]", name);
2459 xmlAttr *attr = xmlHasProp(xml, (
const xmlChar *)name);
2466 while(parent && parent->_private) {
2468 if(__xml_acl_mode_test(p->flags, mode)) {
2472 crm_trace(
"%x access denied to %s: parent", mode, buffer);
2476 parent = parent->parent;
2479 crm_trace(
"%x access denied to %s: default", mode, buffer);
2493 xmlAttr *attr = NULL;
2498 if (value == NULL) {
2501 #if XML_PARANOIA_CHECKS
2503 const char *old_value = NULL;
2508 CRM_CHECK(old_value != value,
crm_err(
"Cannot reset %s with crm_xml_add(%s)", name, value);
2513 if(TRACKING_CHANGES(node)) {
2516 if(old == NULL || value == NULL || strcmp(old, value) != 0) {
2521 if(dirty && __xml_acl_check(node, name,
xpf_acl_create) == FALSE) {
2522 crm_trace(
"Cannot add %s=%s to %s", name, value, node->name);
2526 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2528 crm_attr_dirty(attr);
2531 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2532 return (
char *)attr->children->content;
2539 xmlAttr *attr = NULL;
2540 const char *old_value = NULL;
2543 CRM_CHECK(name != NULL && name[0] != 0,
return NULL);
2548 CRM_CHECK(old_value != value,
return value);
2552 crm_trace(
"Cannot replace %s=%s to %s", name, value, node->name);
2555 }
else if (old_value != NULL && value == NULL) {
2559 }
else if (value == NULL) {
2563 if(TRACKING_CHANGES(node)) {
2564 if(old_value == NULL || value == NULL || strcmp(old_value, value) != 0) {
2569 attr = xmlSetProp(node, (
const xmlChar *)name, (
const xmlChar *)value);
2571 crm_attr_dirty(attr);
2573 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
2574 return (
char *)attr->children->content;
2581 const char *added =
crm_xml_add(node, name, number);
2591 xmlNode *node = NULL;
2593 if (name == NULL || name[0] == 0) {
2594 CRM_CHECK(name != NULL && name[0] == 0,
return NULL);
2598 if (parent == NULL) {
2599 doc = xmlNewDoc((
const xmlChar *)
"1.0");
2600 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2601 xmlDocSetRootElement(doc, node);
2605 node = xmlNewDocRawNode(doc, NULL, (
const xmlChar *)name, NULL);
2606 xmlAddChild(parent, node);
2608 crm_node_created(node);
2613 __get_prefix(
const char *prefix, xmlNode *xml,
char *buffer,
int offset)
2615 const char *
id =
ID(xml);
2617 if(offset == 0 && prefix == NULL && xml->parent) {
2618 offset = __get_prefix(NULL, xml->parent, buffer, offset);
2622 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s[@id='%s']", (
const char *)xml->name,
id);
2623 }
else if(xml->name) {
2624 offset += snprintf(buffer + offset,
XML_BUFFER_SIZE - offset,
"/%s", (
const char *)xml->name);
2636 if(__get_prefix(NULL, xml, buffer, offset) > 0) {
2637 return strdup(buffer);
2643 free_xml_with_position(xmlNode * child,
int position)
2645 if (child != NULL) {
2646 xmlNode *top = NULL;
2647 xmlDoc *doc = child->doc;
2651 top = xmlDocGetRootElement(doc);
2654 if (doc != NULL && top == child) {
2658 }
else if(__xml_acl_check(child, NULL,
xpf_acl_write) == FALSE) {
2662 __get_prefix(NULL, child, buffer, offset);
2663 crm_trace(
"Cannot remove %s %x", buffer, p->flags);
2667 if(doc && TRACKING_CHANGES(child) && is_not_set(p->flags,
xpf_created)) {
2671 if(__get_prefix(NULL, child, buffer, offset) > 0) {
2674 crm_trace(
"Deleting %s %p from %p", buffer, child, doc);
2676 deleted_obj->path = strdup(buffer);
2678 deleted_obj->position = -1;
2680 if (child->type == XML_COMMENT_NODE) {
2681 if (position >= 0) {
2682 deleted_obj->position = position;
2685 deleted_obj->position = __xml_offset(child);
2690 p->deleted_objs = g_list_append(p->deleted_objs, deleted_obj);
2698 xmlUnlinkNode(child);
2708 free_xml_with_position(child, -1);
2714 xmlDoc *doc = xmlNewDoc((
const xmlChar *)
"1.0");
2715 xmlNode *copy = xmlDocCopyNode(src, doc, 1);
2717 xmlDocSetRootElement(doc, copy);
2718 xmlSetTreeDoc(copy, doc);
2723 crm_xml_err(
void *ctx,
const char *fmt, ...)
2724 G_GNUC_PRINTF(2, 3);
2727 crm_xml_err(
void *ctx, const
char *fmt, ...)
2730 static struct qb_log_callsite *xml_error_cs = NULL;
2732 if (xml_error_cs == NULL) {
2733 xml_error_cs = qb_log_callsite_get(
2738 if (xml_error_cs && xml_error_cs->targets) {
2740 crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__,
"xml library error",
2742 "XML Error: ", fmt, ap);
2752 xmlNode *xml = NULL;
2753 xmlDocPtr output = NULL;
2754 xmlParserCtxtPtr ctxt = NULL;
2755 xmlErrorPtr last_error = NULL;
2757 if (input == NULL) {
2758 crm_err(
"Can't parse NULL input");
2763 ctxt = xmlNewParserCtxt();
2768 xmlCtxtResetLastError(ctxt);
2769 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2772 xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL,
2773 XML_PARSE_NOBLANKS | XML_PARSE_RECOVER);
2775 xml = xmlDocGetRootElement(output);
2777 last_error = xmlCtxtGetLastError(ctxt);
2778 if (last_error && last_error->code != XML_ERR_OK) {
2784 crm_warn(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2785 last_error->domain, last_error->level, last_error->code, last_error->message);
2787 if (last_error->code == XML_ERR_DOCUMENT_EMPTY) {
2790 }
else if (last_error->code != XML_ERR_DOCUMENT_END) {
2791 crm_err(
"Couldn't%s parse %d chars: %s", xml ?
" fully" :
"", (
int)strlen(input),
2798 int len = strlen(input);
2802 crm_warn(
"Parse error[+%.3d]: %.80s", lpc, input+lpc);
2810 xmlFreeParserCtxt(ctxt);
2817 size_t data_length = 0;
2818 size_t read_chars = 0;
2820 char *xml_buffer = NULL;
2821 xmlNode *xml_obj = NULL;
2831 xml_buffer = realloc_safe(xml_buffer, next);
2832 read_chars = fread(xml_buffer + data_length, 1,
XML_BUFFER_SIZE, stdin);
2833 data_length += read_chars;
2834 }
while (read_chars > 0);
2836 if (data_length == 0) {
2837 crm_warn(
"No XML supplied on stdin");
2842 xml_buffer[data_length] =
'\0';
2852 decompress_file(
const char *filename)
2854 char *buffer = NULL;
2858 size_t length = 0, read_len = 0;
2860 BZFILE *bz_file = NULL;
2861 FILE *input = fopen(filename,
"r");
2863 if (input == NULL) {
2864 crm_perror(LOG_ERR,
"Could not open %s for reading", filename);
2868 bz_file = BZ2_bzReadOpen(&rc, input, 0, 0, NULL, 0);
2871 BZ2_bzReadClose(&rc, bz_file);
2876 while (rc == BZ_OK) {
2878 read_len = BZ2_bzRead(&rc, bz_file, buffer + length,
XML_BUFFER_SIZE);
2880 crm_trace(
"Read %ld bytes from file: %d", (
long)read_len, rc);
2882 if (rc == BZ_OK || rc == BZ_STREAM_END) {
2887 buffer[length] =
'\0';
2889 if (rc != BZ_STREAM_END) {
2890 crm_err(
"Couldn't read compressed xml from file");
2895 BZ2_bzReadClose(&rc, bz_file);
2899 crm_err(
"Cannot read compressed files:" " bzlib was not available at compile time");
2907 xmlNode *iter = xml->children;
2910 xmlNode *next = iter->next;
2912 switch (iter->type) {
2915 xmlUnlinkNode(iter);
2919 case XML_ELEMENT_NODE:
2936 xmlNode *xml = NULL;
2937 xmlDocPtr output = NULL;
2938 gboolean uncompressed = TRUE;
2939 xmlParserCtxtPtr ctxt = NULL;
2940 xmlErrorPtr last_error = NULL;
2941 static int xml_options = XML_PARSE_NOBLANKS | XML_PARSE_RECOVER;
2944 ctxt = xmlNewParserCtxt();
2949 xmlCtxtResetLastError(ctxt);
2950 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
2957 if (filename == NULL) {
2959 output = xmlCtxtReadFd(ctxt, STDIN_FILENO,
"unknown.xml", NULL, xml_options);
2961 }
else if (uncompressed) {
2962 output = xmlCtxtReadFile(ctxt, filename, NULL, xml_options);
2965 char *input = decompress_file(filename);
2967 output = xmlCtxtReadDoc(ctxt, (
const xmlChar *)input, NULL, NULL, xml_options);
2971 if (output && (xml = xmlDocGetRootElement(output))) {
2975 last_error = xmlCtxtGetLastError(ctxt);
2976 if (last_error && last_error->code != XML_ERR_OK) {
2982 crm_err(
"Parsing failed (domain=%d, level=%d, code=%d): %s",
2983 last_error->domain, last_error->level, last_error->code, last_error->message);
2985 if (last_error && last_error->code != XML_ERR_OK) {
2986 crm_err(
"Couldn't%s parse %s", xml ?
" fully" :
"", filename);
2993 xmlFreeParserCtxt(ctxt);
3008 time_t now = time(NULL);
3009 char *now_str = ctime(&now);
3025 for (c =
id; *c; ++c) {
3050 va_start(ap, format);
3051 len = vasprintf(&
id, format, ap);
3061 write_xml_stream(xmlNode * xml_node,
const char *filename, FILE * stream, gboolean compress)
3064 char *buffer = NULL;
3065 unsigned int out = 0;
3069 crm_trace(
"Writing XML out to %s", filename);
3070 if (xml_node == NULL) {
3071 crm_err(
"Cannot write NULL to %s", filename);
3086 unsigned int in = 0;
3087 BZFILE *bz_file = NULL;
3089 bz_file = BZ2_bzWriteOpen(&rc, stream, 5, 0, 30);
3091 crm_err(
"bzWriteOpen failed: %d", rc);
3093 BZ2_bzWrite(&rc, bz_file, buffer, strlen(buffer));
3095 crm_err(
"bzWrite() failed: %d", rc);
3100 BZ2_bzWriteClose(&rc, bz_file, 0, &in, &out);
3102 crm_err(
"bzWriteClose() failed: %d", rc);
3105 crm_trace(
"%s: In: %d, out: %d", filename, in, out);
3109 crm_err(
"Cannot write compressed files:" " bzlib was not available at compile time");
3114 res = fprintf(stream,
"%s", buffer);
3116 crm_perror(LOG_ERR,
"Cannot write output to %s", filename);
3123 if (fflush(stream) != 0) {
3124 crm_perror(LOG_ERR,
"fflush for %s failed", filename);
3129 if (fsync(fileno(stream)) < 0 && errno != EROFS && errno != EINVAL) {
3130 crm_perror(LOG_ERR,
"fsync for %s failed", filename);
3136 crm_trace(
"Saved %d bytes to the Cib as XML", res);
3143 write_xml_fd(xmlNode * xml_node,
const char *filename,
int fd, gboolean compress)
3145 FILE *stream = NULL;
3148 stream = fdopen(fd,
"w");
3149 return write_xml_stream(xml_node, filename, stream, compress);
3155 FILE *stream = NULL;
3157 stream = fopen(filename,
"w");
3159 return write_xml_stream(xml_node, filename, stream, compress);
3167 return __xml_first_child(tmp);
3180 crm_xml_escape_shuffle(
char *text,
int start,
int *length,
const char *replace)
3183 int offset = strlen(replace) - 1;
3186 text = realloc_safe(text, *length);
3188 for (lpc = (*length) - 1; lpc > (start + offset); lpc--) {
3189 text[lpc] = text[lpc - offset];
3192 memcpy(text + start, replace, offset + 1);
3201 int length = 1 + strlen(text);
3202 char *copy = strdup(text);
3219 for (index = 0; index < length; index++) {
3220 switch (copy[index]) {
3224 copy = crm_xml_escape_shuffle(copy, index, &length,
"<");
3228 copy = crm_xml_escape_shuffle(copy, index, &length,
">");
3232 copy = crm_xml_escape_shuffle(copy, index, &length,
""");
3236 copy = crm_xml_escape_shuffle(copy, index, &length,
"'");
3240 copy = crm_xml_escape_shuffle(copy, index, &length,
"&");
3245 copy = crm_xml_escape_shuffle(copy, index, &length,
" ");
3250 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\n");
3254 copy = crm_xml_escape_shuffle(copy, index, &length,
"\\r");
3264 if(copy[index] <
' ' || copy[index] >
'~') {
3268 copy = crm_xml_escape_shuffle(copy, index, &length, replace);
3282 dump_xml_attr(xmlAttrPtr attr,
int options,
char **buffer,
int *offset,
int *max)
3284 char *p_value = NULL;
3285 const char *p_name = NULL;
3289 if (attr == NULL || attr->children == NULL) {
3298 p_name = (
const char *)attr->name;
3300 buffer_print(*buffer, *max, *offset,
" %s=\"%s\"", p_name, p_value);
3305 __xml_log_element(
int log_level,
const char *file,
const char *
function,
int line,
3306 const char *prefix, xmlNode * data,
int depth,
int options)
3310 const char *name = NULL;
3311 const char *hidden = NULL;
3313 xmlNode *child = NULL;
3314 xmlAttrPtr pIter = NULL;
3320 name = crm_element_name(data);
3323 char *buffer = NULL;
3325 insert_prefix(options, &buffer, &offset, &max, depth);
3327 if (data->type == XML_COMMENT_NODE) {
3328 buffer_print(buffer, max, offset,
"<!--%s-->", data->content);
3334 for (pIter = crm_first_attr(data); pIter != NULL; pIter = pIter->next) {
3336 const char *p_name = (
const char *)pIter->name;
3337 const char *p_value = crm_attr_value(pIter);
3338 char *p_copy = NULL;
3347 }
else if (hidden != NULL && p_name[0] != 0 && strstr(hidden, p_name) != NULL) {
3348 p_copy = strdup(
"*****");
3354 buffer_print(buffer, max, offset,
" %s=\"%s\"", p_name, p_copy);
3369 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3373 if(data->type == XML_COMMENT_NODE) {
3383 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3389 char *buffer = NULL;
3391 insert_prefix(options, &buffer, &offset, &max, depth);
3394 do_crm_log_alias(log_level, file,
function, line,
"%s %s", prefix, buffer);
3400 __xml_log_change_element(
int log_level,
const char *file,
const char *
function,
int line,
3401 const char *prefix, xmlNode * data,
int depth,
int options)
3404 char *prefix_m = NULL;
3405 xmlNode *child = NULL;
3406 xmlAttrPtr pIter = NULL;
3414 prefix_m = strdup(prefix);
3419 __xml_log_element(log_level, file,
function, line,
3422 }
else if(is_set(p->flags,
xpf_dirty)) {
3423 char *spaces = calloc(80, 1);
3424 int s_count = 0, s_max = 80;
3425 char *prefix_del = NULL;
3426 char *prefix_moved = NULL;
3427 const char *
flags = prefix;
3429 insert_prefix(options, &spaces, &s_count, &s_max, depth);
3430 prefix_del = strdup(prefix);
3431 prefix_del[0] =
'-';
3432 prefix_del[1] =
'-';
3433 prefix_moved = strdup(prefix);
3434 prefix_moved[1] =
'~';
3437 flags = prefix_moved;
3442 __xml_log_element(log_level, file,
function, line,
3445 for (pIter = crm_first_attr(data); pIter != NULL; pIter = pIter->next) {
3446 const char *aname = (
const char*)pIter->name;
3448 p = pIter->_private;
3453 "%s %s @%s=%s", flags, spaces, aname, value);
3455 }
else if(is_set(p->flags,
xpf_dirty)) {
3464 }
else if(is_set(p->flags,
xpf_moved)) {
3465 flags = prefix_moved;
3471 "%s %s @%s=%s", flags, spaces, aname, value);
3478 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3479 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3482 __xml_log_element(log_level, file,
function, line,
3486 for (child = __xml_first_child(data); child != NULL; child = __xml_next(child)) {
3487 __xml_log_change_element(log_level, file,
function, line, prefix, child, depth + 1, options);
3497 const char *prefix, xmlNode * data,
int depth,
int options)
3499 xmlNode *a_child = NULL;
3501 char *prefix_m = NULL;
3503 if (prefix == NULL) {
3510 "No data to dump as XML");
3515 __xml_log_change_element(log_level, file,
function, line, prefix, data, depth, options);
3523 prefix_m = strdup(prefix);
3530 prefix_m = strdup(prefix);
3539 for (a_child = __xml_first_child(data); a_child != NULL; a_child = __xml_next(a_child)) {
3540 log_data_element(log_level, file,
function, line, prefix, a_child, depth + 1, options);
3543 __xml_log_element(log_level, file,
function, line, prefix, data, depth,
3550 dump_filtered_xml(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max)
3553 xmlAttrPtr xIter = NULL;
3554 static int filter_len =
DIMOF(filter);
3556 for (lpc = 0; options && lpc < filter_len; lpc++) {
3557 filter[lpc].found = FALSE;
3560 for (xIter = crm_first_attr(data); xIter != NULL; xIter = xIter->next) {
3562 const char *p_name = (
const char *)xIter->name;
3564 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
3565 if (filter[lpc].found == FALSE && strcmp(p_name, filter[lpc].
string) == 0) {
3566 filter[lpc].found = TRUE;
3572 if (skip == FALSE) {
3573 dump_xml_attr(xIter, options, buffer, offset, max);
3579 dump_xml_element(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3581 const char *name = NULL;
3592 if (*buffer == NULL) {
3597 name = crm_element_name(data);
3600 insert_prefix(options, buffer, offset, max, depth);
3604 dump_filtered_xml(data, options, buffer, offset, max);
3607 xmlAttrPtr xIter = NULL;
3609 for (xIter = crm_first_attr(data); xIter != NULL; xIter = xIter->next) {
3610 dump_xml_attr(xIter, options, buffer, offset, max);
3614 if (data->children == NULL) {
3625 if (data->children) {
3626 xmlNode *xChild = NULL;
3627 for(xChild = data->children; xChild != NULL; xChild = xChild->next) {
3628 crm_xml_dump(xChild, options, buffer, offset, max, depth + 1);
3631 insert_prefix(options, buffer, offset, max, depth);
3634 if (options & xml_log_option_formatted) {
3641 dump_xml_text(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3652 if (*buffer == NULL) {
3657 insert_prefix(options, buffer, offset, max, depth);
3659 buffer_print(*buffer, *max, *offset,
"%s", data->content);
3661 if (options & xml_log_option_formatted) {
3668 dump_xml_comment(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3679 if (*buffer == NULL) {
3684 insert_prefix(options, buffer, offset, max, depth);
3687 buffer_print(*buffer, *max, *offset,
"%s", data->content);
3690 if (options & xml_log_option_formatted) {
3696 crm_xml_dump(xmlNode * data,
int options,
char **buffer,
int *offset,
int *max,
int depth)
3704 if (is_not_set(options, xml_log_option_filtered)) {
3719 xmlBuffer *xml_buffer = NULL;
3727 xml_buffer = xmlBufferCreate();
3738 xmlBufferSetAllocationScheme(xml_buffer, XML_BUFFER_ALLOC_DOUBLEIT);
3740 *max = xmlNodeDump(xml_buffer, doc, data, 0, (options & xml_log_option_formatted));
3742 *buffer = strdup((
char *)xml_buffer->content);
3746 if ((now + 1) < next) {
3748 crm_err(
"xmlNodeDump() -> %dbytes took %ds", *max, next - now);
3751 xmlBufferFree(xml_buffer);
3756 switch(data->type) {
3757 case XML_ELEMENT_NODE:
3759 dump_xml_element(data, options, buffer, offset, max, depth);
3764 dump_xml_text(data, options, buffer, offset, max, depth);
3767 case XML_COMMENT_NODE:
3768 dump_xml_comment(data, options, buffer, offset, max, depth);
3771 crm_warn(
"Unhandled type: %d", data->type);
3807 char *buffer = NULL;
3808 int offset = 0, max = 0;
3817 char *buffer = NULL;
3818 int offset = 0, max = 0;
3820 crm_xml_dump(an_xml_node, xml_log_option_formatted, &buffer, &offset, &max, 0);
3827 char *buffer = NULL;
3828 int offset = 0, max = 0;
3830 crm_xml_dump(an_xml_node, 0, &buffer, &offset, &max, 0);
3837 if (xml_root != NULL && xml_root->children != NULL) {
3871 char *value_copy = NULL;
3874 if (value != NULL) {
3875 value_copy = strdup(value);
3884 crm_trace(
"Cannot remove %s from %s", name, obj->name);
3886 }
else if(TRACKING_CHANGES(obj)) {
3889 xmlAttr *attr = xmlHasProp(obj, (
const xmlChar *)name);
3897 xmlUnsetProp(obj, (
const xmlChar *)name);
3904 xmlNode *child = NULL;
3909 for (child = __xml_first_child(a_node); child != NULL; child = __xml_next(child)) {
3919 if (filename == NULL) {
3927 crm_info(
"Saving %s to %s", desc, filename);
3935 gboolean result = TRUE;
3936 int root_nodes_seen = 0;
3937 static struct qb_log_callsite *digest_cs = NULL;
3941 xmlNode *child_diff = NULL;
3943 xmlNode *removed =
find_xml_node(diff,
"diff-removed", FALSE);
3946 if (digest_cs == NULL) {
3948 qb_log_callsite_get(__func__, __FILE__,
"diff-digest",
LOG_TRACE, __LINE__,
3953 for (child_diff = __xml_first_child(removed); child_diff != NULL;
3954 child_diff = __xml_next(child_diff)) {
3955 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
3956 if (root_nodes_seen == 0) {
3962 if (root_nodes_seen == 0) {
3965 }
else if (root_nodes_seen > 1) {
3966 crm_err(
"(-) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
3970 root_nodes_seen = 0;
3973 xmlNode *child_diff = NULL;
3975 for (child_diff = __xml_first_child(added); child_diff != NULL;
3976 child_diff = __xml_next(child_diff)) {
3977 CRM_CHECK(root_nodes_seen == 0, result = FALSE);
3978 if (root_nodes_seen == 0) {
3985 if (root_nodes_seen > 1) {
3986 crm_err(
"(+) Diffs cannot contain more than one change set..." " saw %d", root_nodes_seen);
3989 }
else if (result && digest) {
3990 char *new_digest = NULL;
3995 crm_info(
"Digest mis-match: expected %s, calculated %s", digest, new_digest);
3998 crm_trace(
"%p %.6x", digest_cs, digest_cs ? digest_cs->targets : 0);
3999 if (digest_cs && digest_cs->targets) {
4006 crm_trace(
"Digest matched: expected %s, calculated %s", digest, new_digest);
4010 }
else if (result) {
4018 __xml_diff_object(xmlNode * old, xmlNode *
new)
4020 xmlNode *cIter = NULL;
4021 xmlAttr *pIter = NULL;
4025 crm_node_created(
new);
4026 __xml_acl_post_process(
new);
4039 for (pIter = crm_first_attr(
new); pIter != NULL; pIter = pIter->next) {
4046 for (pIter = crm_first_attr(old); pIter != NULL; ) {
4047 xmlAttr *prop = pIter;
4049 const char *name = (
const char *)pIter->name;
4051 xmlAttr *exists = xmlHasProp(
new, pIter->name);
4053 pIter = pIter->next;
4054 if(exists == NULL) {
4055 p =
new->doc->_private;
4059 exists = xmlSetProp(
new, (
const xmlChar *)name, (
const xmlChar *)old_value);
4062 p = exists->_private;
4065 crm_trace(
"Lost %s@%s=%s", old->name, name, old_value);
4069 int p_new = __xml_offset((xmlNode*)exists);
4070 int p_old = __xml_offset((xmlNode*)prop);
4073 p = exists->_private;
4076 if(strcmp(value, old_value) != 0) {
4082 crm_trace(
"Modified %s@%s %s->%s", old->name, name, old_value, vcopy);
4083 xmlSetProp(
new, prop->name, (
const xmlChar *)old_value);
4087 }
else if(p_old != p_new) {
4088 crm_info(
"Moved %s@%s (%d -> %d)", old->name, name, p_old, p_new);
4089 __xml_node_dirty(
new);
4097 p = exists->_private;
4104 for (pIter = crm_first_attr(
new); pIter != NULL; ) {
4105 xmlAttr *prop = pIter;
4108 pIter = pIter->next;
4110 char *name = strdup((
const char *)prop->name);
4113 crm_trace(
"Created %s@%s=%s", new->name, name, value);
4116 crm_attr_dirty(prop);
4118 xmlUnsetProp(
new, prop->name);
4126 for (cIter = __xml_first_child(old); cIter != NULL; ) {
4127 xmlNode *old_child = cIter;
4128 xmlNode *new_child = find_element(
new, cIter, TRUE);
4130 cIter = __xml_next(cIter);
4132 __xml_diff_object(old_child, new_child);
4137 xmlNode *top = xmlDocGetRootElement(candidate->doc);
4139 __xml_node_clean(candidate);
4140 __xml_acl_apply(top);
4142 free_xml_with_position(candidate, __xml_offset(old_child));
4144 if (find_element(
new, old_child, TRUE) == NULL) {
4152 for (cIter = __xml_first_child(
new); cIter != NULL; ) {
4153 xmlNode *new_child = cIter;
4154 xmlNode *old_child = find_element(old, cIter, TRUE);
4156 cIter = __xml_next(cIter);
4157 if(old_child == NULL) {
4160 __xml_diff_object(old_child, new_child);
4164 int p_new = __xml_offset(new_child);
4165 int p_old = __xml_offset(old_child);
4167 if(p_old != p_new) {
4170 crm_info(
"%s.%s moved from %d to %d",
4171 new_child->name,
ID(new_child), p_old, p_new);
4172 __xml_node_dirty(
new);
4176 p = old_child->_private;
4178 p = new_child->_private;
4196 __xml_diff_object(old,
new);
4202 xmlNode *tmp1 = NULL;
4219 if (added->children == NULL && removed->children == NULL) {
4230 xmlNode *cIter = NULL;
4231 xmlAttrPtr pIter = NULL;
4232 gboolean can_prune = TRUE;
4233 const char *name = crm_element_name(xml_node);
4242 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4243 const char *p_name = (
const char *)pIter->name;
4251 cIter = __xml_first_child(xml_node);
4253 xmlNode *child = cIter;
4255 cIter = __xml_next(cIter);
4267 xmlNode * xml_node, xmlNode * parent)
4270 xmlNode *child = NULL;
4271 xmlAttrPtr pIter = NULL;
4272 xmlNode *new_parent = parent;
4273 const char *name = crm_element_name(xml_node);
4275 CRM_CHECK(xml_node != NULL && name != NULL,
return);
4278 for (pIter = crm_first_attr(xml_node); pIter != NULL; pIter = pIter->next) {
4279 const char *p_name = (
const char *)pIter->name;
4280 const char *p_value = crm_attr_value(pIter);
4282 lower_bound = context;
4286 if (lower_bound >= 0 || upper_bound >= 0) {
4292 if (upper_bound >= 0) {
4301 for (child = __xml_first_child(us); child != NULL; child = __xml_next(child)) {
4313 if (xml_node->properties) {
4316 }
else if (depth < context) {
4317 xmlNode *child = NULL;
4319 for (child = __xml_first_child(xml_node); child != NULL; child = __xml_next(child)) {
4329 find_xml_comment(xmlNode * root, xmlNode * search_comment, gboolean exact)
4331 xmlNode *a_child = NULL;
4332 int search_offset = __xml_offset(search_comment);
4334 CRM_CHECK(search_comment->type == XML_COMMENT_NODE,
return NULL);
4336 for (a_child = __xml_first_child(root); a_child != NULL; a_child = __xml_next(a_child)) {
4338 int offset = __xml_offset(a_child);
4341 if (offset < search_offset) {
4344 }
else if (offset > search_offset) {
4353 if (a_child->type == XML_COMMENT_NODE
4354 &&
safe_str_eq((
const char *)a_child->content, (
const char *)search_comment->content)) {
4366 subtract_xml_comment(xmlNode * parent, xmlNode * left, xmlNode * right,
4370 CRM_CHECK(left->type == XML_COMMENT_NODE,
return NULL);
4373 ||
safe_str_neq((
const char *)left->content, (
const char *)right->content)) {
4374 xmlNode *deleted = NULL;
4387 gboolean full, gboolean * changed,
const char *marker)
4389 gboolean dummy = FALSE;
4390 gboolean skip = FALSE;
4391 xmlNode *diff = NULL;
4392 xmlNode *right_child = NULL;
4393 xmlNode *left_child = NULL;
4394 xmlAttrPtr xIter = NULL;
4396 const char *
id = NULL;
4397 const char *name = NULL;
4398 const char *value = NULL;
4399 const char *right_val = NULL;
4402 static int filter_len =
DIMOF(filter);
4404 if (changed == NULL) {
4412 if (left->type == XML_COMMENT_NODE) {
4413 return subtract_xml_comment(parent, left, right, changed);
4417 if (right == NULL) {
4418 xmlNode *deleted = NULL;
4420 crm_trace(
"Processing <%s id=%s> (complete copy)", crm_element_name(left),
id);
4428 name = crm_element_name(left);
4434 if (value != NULL && strcmp(value,
"removed:top") == 0) {
4435 crm_trace(
"We are the root of the deletion: %s.id=%s", name,
id);
4444 for (lpc = 0; lpc < filter_len; lpc++) {
4445 filter[lpc].found = FALSE;
4449 for (left_child = __xml_first_child(left); left_child != NULL;
4450 left_child = __xml_next(left_child)) {
4451 gboolean child_changed = FALSE;
4453 right_child = find_element(right, left_child, FALSE);
4455 if (child_changed) {
4460 if (*changed == FALSE) {
4464 xmlAttrPtr pIter = NULL;
4466 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4467 const char *p_name = (
const char *)pIter->name;
4468 const char *p_value = crm_attr_value(pIter);
4470 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4477 xmlSetProp(diff, (
const xmlChar *)
XML_ATTR_ID, (
const xmlChar *)
id);
4481 for (xIter = crm_first_attr(left); xIter != NULL; xIter = xIter->next) {
4482 const char *prop_name = (
const char *)xIter->name;
4483 xmlAttrPtr right_attr = NULL;
4491 for (lpc = 0; skip == FALSE && lpc < filter_len; lpc++) {
4492 if (filter[lpc].found == FALSE && strcmp(prop_name, filter[lpc].
string) == 0) {
4493 filter[lpc].found = TRUE;
4503 right_attr = xmlHasProp(right, (
const xmlChar *)prop_name);
4505 p = right_attr->_private;
4509 if (right_val == NULL || (p && is_set(p->flags,
xpf_deleted))) {
4513 xmlAttrPtr pIter = NULL;
4515 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4516 const char *p_name = (
const char *)pIter->name;
4517 const char *p_value = crm_attr_value(pIter);
4519 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4526 xmlSetProp(diff, (
const xmlChar *)prop_name, (
const xmlChar *)value);
4534 if (strcmp(left_value, right_val) == 0) {
4540 xmlAttrPtr pIter = NULL;
4542 crm_trace(
"Changes detected to %s in <%s id=%s>", prop_name,
4543 crm_element_name(left),
id);
4544 for (pIter = crm_first_attr(left); pIter != NULL; pIter = pIter->next) {
4545 const char *p_name = (
const char *)pIter->name;
4546 const char *p_value = crm_attr_value(pIter);
4548 xmlSetProp(diff, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4553 crm_trace(
"Changes detected to %s (%s -> %s) in <%s id=%s>",
4554 prop_name, left_value, right_val, crm_element_name(left),
id);
4561 if (*changed == FALSE) {
4565 }
else if (full == FALSE &&
id) {
4573 add_xml_comment(xmlNode * parent, xmlNode * target, xmlNode * update)
4576 CRM_CHECK(update->type == XML_COMMENT_NODE,
return 0);
4578 if (target == NULL) {
4579 target = find_xml_comment(parent, update, FALSE);
4582 if (target == NULL) {
4586 }
else if (
safe_str_neq((
const char *)target->content, (
const char *)update->content)) {
4587 xmlFree(target->content);
4588 target->content = xmlStrdup(update->content);
4595 add_xml_object(xmlNode * parent, xmlNode * target, xmlNode * update, gboolean as_diff)
4597 xmlNode *a_child = NULL;
4598 const char *object_id = NULL;
4599 const char *object_name = NULL;
4608 if (update->type == XML_COMMENT_NODE) {
4609 return add_xml_comment(parent, target, update);
4612 object_name = crm_element_name(update);
4613 object_id =
ID(update);
4615 CRM_CHECK(object_name != NULL,
return 0);
4617 if (target == NULL && object_id == NULL) {
4621 }
else if (target == NULL) {
4622 target =
find_entity(parent, object_name, object_id);
4625 if (target == NULL) {
4628 #if XML_PARSER_DEBUG
4630 object_id ?
" id=" :
"", object_id ? object_id :
"");
4633 crm_trace(
"Found node <%s%s%s/> to update",
4634 crm_str(object_name), object_id ?
" id=" :
"", object_id ? object_id :
"");
4640 if (as_diff == FALSE) {
4646 xmlAttrPtr pIter = NULL;
4648 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4649 const char *p_name = (
const char *)pIter->name;
4650 const char *p_value = crm_attr_value(pIter);
4653 xmlUnsetProp(target, (
const xmlChar *)p_name);
4654 xmlSetProp(target, (
const xmlChar *)p_name, (
const xmlChar *)p_value);
4658 for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
4659 #if XML_PARSER_DEBUG
4660 crm_trace(
"Updating child <%s id=%s>", crm_element_name(a_child),
ID(a_child));
4665 #if XML_PARSER_DEBUG
4674 gboolean can_update = TRUE;
4675 xmlNode *child_of_child = NULL;
4678 CRM_CHECK(to_update != NULL,
return FALSE);
4680 if (
safe_str_neq(crm_element_name(to_update), crm_element_name(child))) {
4686 }
else if (can_update) {
4687 #if XML_PARSER_DEBUG
4693 for (child_of_child = __xml_first_child(child); child_of_child != NULL;
4694 child_of_child = __xml_next(child_of_child)) {
4707 const char *tag,
const char *field,
const char *value, gboolean search_matches)
4709 int match_found = 0;
4712 CRM_CHECK(children != NULL,
return FALSE);
4714 if (tag != NULL &&
safe_str_neq(tag, crm_element_name(root))) {
4719 if (*children == NULL) {
4726 if (search_matches || match_found == 0) {
4727 xmlNode *child = NULL;
4729 for (child = __xml_first_child(root); child != NULL; child = __xml_next(child)) {
4730 match_found +=
find_xml_children(children, child, tag, field, value, search_matches);
4740 gboolean can_delete = FALSE;
4741 xmlNode *child_of_child = NULL;
4743 const char *up_id = NULL;
4744 const char *child_id = NULL;
4745 const char *right_val = NULL;
4748 CRM_CHECK(update != NULL,
return FALSE);
4751 child_id =
ID(child);
4753 if (up_id == NULL || (child_id && strcmp(child_id, up_id) == 0)) {
4756 if (
safe_str_neq(crm_element_name(update), crm_element_name(child))) {
4759 if (can_delete && delete_only) {
4760 xmlAttrPtr pIter = NULL;
4762 for (pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) {
4763 const char *p_name = (
const char *)pIter->name;
4764 const char *p_value = crm_attr_value(pIter);
4773 if (can_delete && parent != NULL) {
4775 if (delete_only || update == NULL) {
4780 xmlDoc *doc = tmp->doc;
4781 xmlNode *old = NULL;
4784 old = xmlReplaceNode(child, tmp);
4788 __xml_acl_apply(tmp);
4792 xmlDocSetRootElement(doc, old);
4798 }
else if (can_delete) {
4803 child_of_child = __xml_first_child(child);
4804 while (child_of_child) {
4805 xmlNode *next = __xml_next(child_of_child);
4811 child_of_child = NULL;
4813 child_of_child = next;
4847 const char *parent_id =
ID(parent);
4860 const char *name = key;
4861 const char *s_value = value;
4862 xmlNode *xml_node = user_data;
4865 crm_trace(
"dumped: name=%s value=%s", name, s_value);
4871 const char *name = key;
4872 const char *s_value = value;
4874 xmlNode *xml_node = user_data;
4876 if (isdigit(name[0])) {
4884 crm_trace(
"dumped: %s=%s", name, s_value);
4887 crm_trace(
"duplicate: %s=%s", name, s_value);
4894 const char *name = key;
4895 const char *s_value = value;
4897 xmlNode *xml_node = user_data;
4903 crm_trace(
"duplicate: %s=%s", name, s_value);
4910 char *crm_name = NULL;
4912 if (key == NULL || value == NULL) {
4919 for (crm_name = key; *crm_name; ++crm_name) {
4920 if ((*crm_name ==
'#') || (*crm_name ==
':')) {
4933 xmlNode *child = NULL;
4934 xmlAttrPtr pIter = NULL;
4935 xmlNode *nvpair_list = NULL;
4936 GHashTable *nvpair_hash = crm_str_table_new();
4938 CRM_CHECK(parent != NULL,
return nvpair_hash);
4941 if (nvpair_list == NULL) {
4942 crm_trace(
"No attributes in %s", crm_element_name(parent));
4948 for (pIter = crm_first_attr(nvpair_list); pIter != NULL; pIter = pIter->next) {
4949 const char *p_name = (
const char *)pIter->name;
4950 const char *p_value = crm_attr_value(pIter);
4952 crm_trace(
"Added %s=%s", p_name, p_value);
4954 g_hash_table_insert(nvpair_hash, strdup(p_name), strdup(p_value));
4957 for (child = __xml_first_child(nvpair_list); child != NULL; child = __xml_next(child)) {
4958 if (strcmp((
const char *)child->name,
XML_TAG_PARAM) == 0) {
4963 if (key != NULL && value != NULL) {
4964 g_hash_table_insert(nvpair_hash, strdup(key), strdup(value));
4972 typedef struct name_value_s {
4978 sort_pairs(gconstpointer a, gconstpointer b)
4990 rc = strcmp(pair_a->name, pair_b->name);
4993 }
else if (rc > 0) {
5000 dump_pair(gpointer data, gpointer user_data)
5003 xmlNode *parent = user_data;
5009 sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive)
5011 xmlNode *child = NULL;
5015 xmlNode *result = NULL;
5016 const char *name = NULL;
5017 xmlAttrPtr pIter = NULL;
5021 name = crm_element_name(input);
5026 for (pIter = crm_first_attr(input); pIter != NULL; pIter = pIter->next) {
5027 const char *p_name = (
const char *)pIter->name;
5028 const char *p_value = crm_attr_value(pIter);
5031 pair->name = p_name;
5032 pair->value = p_value;
5033 unsorted = g_list_prepend(unsorted, pair);
5037 sorted = g_list_sort(unsorted, sort_pairs);
5038 g_list_foreach(sorted, dump_pair, result);
5039 g_list_free_full(sorted, free);
5041 for (child = __xml_first_child(input); child != NULL; child = __xml_next(child)) {
5055 xmlNode *match = NULL;
5057 for (match = __xml_first_child(parent); match != NULL; match = __xml_next(match)) {
5063 if (name == NULL || strcmp((
const char *)match->name, name) == 0) {
5080 xmlNode *match = __xml_next(sibling);
5081 const char *name = crm_element_name(sibling);
5083 while (match != NULL) {
5084 if (!strcmp(crm_element_name(match), name)) {
5087 match = __xml_next(match);
5095 static bool init = TRUE;
5104 xmlSetBufferAllocationScheme(XML_BUFFER_ALLOC_DOUBLEIT);
5107 xmlDeregisterNodeDefault(pcmkDeregisterNode);
5108 xmlRegisterNodeDefault(pcmkRegisterNode);
5117 crm_info(
"Cleaning up memory from libxml2");
5122 #define XPATH_MAX 512
5127 const char *tag = NULL;
5128 const char *ref = NULL;
5129 xmlNode *result = input;
5130 char *xpath_string = NULL;
5132 if (result == NULL) {
5135 }
else if (top == NULL) {
5139 tag = crm_element_name(result);
5147 offset += snprintf(xpath_string + offset,
XPATH_MAX - offset,
"//%s[@id='%s']", tag, ref);
5151 if (result == NULL) {
5152 char *nodePath = (
char *)xmlGetNodePath(top);
5154 crm_err(
"No match for %s found in %s: Invalid configuration", xpath_string,
5167 xmlAttr *attr = NULL;
5170 crm_err(
"Couldn't find %s in NULL", name ? name :
"<null>");
5174 }
else if (name == NULL) {
5175 crm_err(
"Couldn't find NULL in %s", crm_element_name(data));
5179 attr = xmlHasProp(data, (
const xmlChar *)name);
5180 if (attr == NULL || attr->children == NULL) {
5183 return (
const char *)attr->children->content;
#define CRM_CHECK(expr, failure_action)
gboolean daemon_option_enabled(const char *daemon, const char *option)
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
#define XML_ATTR_UPDATE_ORIG
void crm_schema_init(void)
xmlNode * get_message_xml(xmlNode *msg, const char *field)
#define crm_notice(fmt, args...)
#define XML_ATTR_UPDATE_CLIENT
GHashTable * xml2list(xmlNode *parent)
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)
#define XML_ATTR_NUMUPDATES
void crm_buffer_add_char(char **buffer, int *offset, int *max, char c)
int crm_element_value_const_int(const xmlNode *data, const char *name, int *dest)
void xml_calculate_changes(xmlNode *old, xmlNode *new)
struct xml_acl_s xml_acl_t
void log_data_element(int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, gboolean formatted)
const char * __xml_acl_to_text(enum xml_private_flags flags)
void crm_xml_cleanup(void)
#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)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
#define buffer_print(buffer, max, offset, fmt, args...)
void crm_schema_cleanup(void)
bool xml_acl_denied(xmlNode *xml)
#define XML_ACL_TAG_WRITE
int write_xml_file(xmlNode *xml_node, const char *filename, gboolean compress)
char * crm_element_value_copy(xmlNode *data, const char *name)
#define XML_NVPAIR_ATTR_NAME
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.
#define clear_bit(word, bit)
void copy_in_properties(xmlNode *target, xmlNode *src)
void xml_accept_changes(xmlNode *xml)
xmlNode * filename2xml(const char *filename)
unsigned int crm_trace_nonlog
#define XML_CIB_TAG_NVPAIR
void purge_diff_markers(xmlNode *a_node)
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
char * crm_meta_name(const char *field)
#define CRM_XML_LOG_BASE(priority, dechunk, postemit, prefix, fmt, ap)
Base for directing lib{xml2,xslt} log into standard libqb backend.
xmlNode * string2xml(const char *input)
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
#define XML_ATTR_GENERATION
xmlDoc * getDocPtr(xmlNode *node)
bool xml_acl_enabled(xmlNode *xml)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
void expand_plus_plus(xmlNode *target, const char *name, const char *value)
bool xml_tracking_changes(xmlNode *xml)
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
xmlNode * copy_xml(xmlNode *src_node)
#define XML_ACL_ATTR_REFv1
#define XML_ACL_ATTR_KIND
#define pcmk_err_diff_failed
void hash2field(gpointer key, gpointer value, gpointer user_data)
#define pcmk_err_diff_resync
#define crm_warn(fmt, args...)
#define set_bit(word, bit)
bool pcmk_acl_required(const char *user)
xmlNode * stdin2xml(void)
void diff_filter_context(int context, int upper_bound, int lower_bound, xmlNode *xml_node, xmlNode *parent)
#define crm_debug(fmt, args...)
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
#define XML_ACL_ATTR_XPATH
gboolean update_xml_child(xmlNode *child, xmlNode *to_update)
#define XML_ACL_TAG_PERMISSION
#define crm_trace(fmt, args...)
#define crm_log_xml_explicit(xml, text)
#define XML_PRIVATE_MAGIC
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
const char * crm_element_value_const(const xmlNode *data, const char *name)
#define crm_log_xml_debug(xml, text)
struct name_value_s name_value_t
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
#define XML_ACL_TAG_USERv1
Wrappers for and extensions to libxml2.
bool xml_document_dirty(xmlNode *xml)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
int crm_element_value_int(xmlNode *data, const char *name, int *dest)
char * dump_xml_formatted(xmlNode *msg)
const char * crm_element_value(xmlNode *data, const char *name)
xmlNode * crm_next_same_xml(xmlNode *sibling)
Get next instance of same XML tag.
#define XML_ACL_ATTR_ATTRIBUTE
#define XML_DIFF_POSITION
#define XML_TAG_RESOURCE_REF
void xml_acl_disable(xmlNode *xml)
void void crm_destroy_xml(gpointer data)
xmlNode destructor which can be used in glib collections
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
gboolean crm_ends_with_ext(const char *s, const char *match)
xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
#define XML_ACL_ATTR_TAGv1
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
int find_xml_children(xmlNode **children, xmlNode *root, const char *tag, const char *field, const char *value, gboolean search_matches)
bool xml_patch_versions(xmlNode *patchset, int add[3], int del[3])
#define crm_config_warn(fmt...)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
void xml_log_changes(uint8_t level, const char *function, xmlNode *xml)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
#define crm_log_xml_err(xml, text)
gboolean apply_xml_diff(xmlNode *old, xmlNode *diff, xmlNode **new)
#define crm_perror(level, fmt, args...)
Log a system error message.
#define crm_err(fmt, args...)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#define XML_CIB_ATTR_WRITTEN
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
#define XML_ACL_TAG_ROLE_REFv1
int get_attr_value(const char *input, size_t offset, size_t max)
void xml_remove_prop(xmlNode *obj, const char *name)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
gboolean can_prune_leaf(xmlNode *xml_node)
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
int compare_version(const char *version1, const char *version2)
#define crm_log_xml_info(xml, text)
char * xml_get_path(xmlNode *xml)
char * dump_xml_unformatted(xmlNode *msg)
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
#define XML_ATTR_GENERATION_ADMIN
#define XML_NVPAIR_ATTR_VALUE
#define XML_ATTR_CRM_VERSION
void save_xml_to_file(xmlNode *xml, const char *desc, const char *filename)
void strip_text_nodes(xmlNode *xml)
xmlNode * diff_xml_object(xmlNode *left, xmlNode *right, gboolean suppress)
int add_node_nocopy(xmlNode *parent, const char *name, xmlNode *child)
int get_tag_name(const char *input, size_t offset, size_t max)
#define XML_CIB_TAG_OBJ_REF
#define crm_log_xml_trace(xml, text)
xmlNode * first_named_child(xmlNode *parent, const char *name)
#define XML_ACL_TAG_ROLE_REF
xmlNode * subtract_xml_object(xmlNode *parent, xmlNode *left, xmlNode *right, gboolean full, gboolean *changed, const char *marker)
#define XML_CIB_TAG_CONFIGURATION
char * crm_itoa(int an_int)
void xml_log_patchset(uint8_t level, const char *function, xmlNode *xml)
#define safe_str_eq(a, b)
int write_xml_fd(xmlNode *xml_node, const char *filename, int fd, gboolean compress)
int in_upper_context(int depth, int context, xmlNode *xml_node)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
char * crm_xml_escape(const char *text)
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
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
void fix_plus_plus_recursive(xmlNode *target)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version)
#define crm_info(fmt, args...)
const char * crm_xml_add_last_written(xmlNode *xml_node)
char * dump_xml_formatted_with_text(xmlNode *msg)
gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)
void crm_xml_dump(xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
struct xml_deleted_obj_s xml_deleted_obj_t