| 1612 | } |
| 1613 | |
| 1614 | int |
| 1615 | add_xml_object(xmlNode *parent, xmlNode *target, xmlNode *update, gboolean as_diff) |
| 1616 | { |
| 1617 | xmlNode *a_child = NULL; |
| 1618 | const char *object_id = NULL; |
| 1619 | const char *object_name = NULL; |
| 1620 | |
| 1621 | #if XML_PARSE_DEBUG |
| 1622 | crm_log_xml_trace("update:", update); |
| 1623 | crm_log_xml_trace("target:", target); |
| 1624 | #endif |
| 1625 | |
| 1626 | CRM_CHECK(update != NULL, return 0); |
| 1627 | |
| 1628 | object_name = crm_element_name(update); |
| 1629 | object_id = ID(update); |
| 1630 | |
| 1631 | CRM_CHECK(object_name != NULL, return 0); |
| 1632 | |
| 1633 | if(target == NULL && object_id == NULL) { |
| 1634 | /* placeholder object */ |
| 1635 | target = find_xml_node(parent, object_name, FALSE); |
| 1636 | |
| 1637 | } else if(target == NULL) { |
| 1638 | target = find_entity(parent, object_name, object_id); |
| 1639 | } |
| 1640 | |
| 1641 | if(target == NULL) { |
| 1642 | target = create_xml_node(parent, object_name); |
| 1643 | CRM_CHECK(target != NULL, return 0); |
| 1644 | #if XML_PARSER_DEBUG |
| 1645 | crm_trace("Added <%s%s%s/>", crm_str(object_name), |
| 1646 | object_id?" id=":"", object_id?object_id:""); |
| 1647 | |
| 1648 | } else { |
| 1649 | crm_trace("Found node <%s%s%s/> to update", |
| 1650 | crm_str(object_name), |
| 1651 | object_id?" id=":"", object_id?object_id:""); |
| 1652 | #endif |
| 1653 | } |
| 1654 | |
| 1655 | if(as_diff == FALSE) { |
| 1656 | /* So that expand_plus_plus() gets called */ |
| 1657 | copy_in_properties(target, update); |
| 1658 | |
| 1659 | } else { |
| 1660 | /* No need for expand_plus_plus(), just raw speed */ |
| 1661 | xmlAttrPtr pIter = NULL; |
| 1662 | for(pIter = crm_first_attr(update); pIter != NULL; pIter = pIter->next) { |
| 1663 | const char *p_name = (const char *)pIter->name; |
| 1664 | const char *p_value = crm_attr_value(pIter); |
| 1665 | /* Remove it first so the ordering of the update is preserved */ |
| 1666 | xmlUnsetProp(target, (const xmlChar*)p_name); |
| 1667 | xmlSetProp(target, (const xmlChar*)p_name, (const xmlChar*)p_value); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | for(a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) { |
no test coverage detected