xmlNodePtr new_section = find_xml_node(command, XML_TAG_CIB); new_section = find_xml_node(new_section, section); if (new_section != NULL) {  xmlNodePtr tmpCib = copy_xml_node_recursive(get_the_CIB(), 1); xmlNodePtr old_section = find_xml_node(tmpCib, section); xmlReplaceNode(old_section, new_section); status = "ok"; if (activateCibXml(tmpCib) < 0) status = "update activation failed"; } else { status = "section replacement failed"; }
replace_section(section, tmpCib, command);
processCibRequest(xmlNodePtr command){	const char *status         = "failed";	const char *op             = NULL;	const char *verbose        = NULL;	const char *section        = NULL;	const char *output_section = NULL;	xmlNodePtr failed          = NULL;	xmlNodePtr cib_answer      = NULL;	xmlNodePtr cib_section     = NULL;	gboolean update_the_cib = FALSE;	int cib_update_operation = CIB_OP_NONE;	// sanity check	if (command == NULL) {		cl_log(LOG_INFO,		       "The (%s) received an empty message",		       CRM_SYSTEM_CIB);		FNRET(NULL);	} else if (strcmp(XML_REQ_TAG_CIB, command->name) != 0) {		cl_log(LOG_INFO,		       "The (%s) received an invalid message of type (%s)",		       CRM_SYSTEM_CIB, command->name);		FNRET(NULL);	}	op         = xmlGetProp(command, XML_CIB_ATTR_OP);	verbose    = xmlGetProp(command, XML_ATTR_VERBOSE);	section    = xmlGetProp(command, XML_CIB_ATTR_SECTION);	failed     = create_xml_node(NULL, XML_TAG_FAILED);	cib_answer = create_xml_node(NULL, XML_RESP_TAG_CIB);	if (strcmp("noop", op) == 0) ;	else if (strcmp("ping", op) == 0) {		CRM_DEBUG("Handling a ping");		status = "ok";		xmlAddChild(cib_answer,			    createPingAnswerFragment(CRM_SYSTEM_CIB,						     status));	} else if (strcmp("query", op) == 0) {		CRM_DEBUG2("Handling a query for section=%s of the cib",			   section);		/* force a pick-up of the relevant section before		 * returning		 */		verbose = "true"; 		status = "ok";			} else if (strcmp("erase", op) == 0) {		xmlNodePtr new_cib = createEmptyCib();		if (activateCibXml(new_cib) < 0)			status = "erase of CIB failed";		else			status = "ok";			} else if (strcmp("create", op) == 0) {		update_the_cib = TRUE;		cib_update_operation = CIB_OP_ADD;			} else if (strcmp("update", op) == 0) {		update_the_cib = TRUE;		cib_update_operation = CIB_OP_MODIFY;			} else if (strcmp("delete", op) == 0) {		update_the_cib = TRUE;		cib_update_operation = CIB_OP_DELETE;			} else if (strcmp("replace", op) == 0) {		CRM_DEBUG2("Replacing section=%s of the cib", section);		if (strcmp("all", section) == 0) {			xmlNodePtr new_cib =				find_xml_node(command, XML_TAG_CIB);			if (activateCibXml(new_cib) < 0)				status = "new activation failed";			else				status = "ok";		} else {			xmlNodePtr new_section =				find_xml_node(command, XML_TAG_CIB);			new_section = find_xml_node(new_section, section);			if (new_section != NULL) {				// make changes to a temp copy then activate				xmlNodePtr tmpCib =					copy_xml_node_recursive(get_the_CIB(), 1);				xmlNodePtr old_section =					find_xml_node(tmpCib, section);				xmlReplaceNode(old_section, new_section);				status = "ok";				if (activateCibXml(tmpCib) < 0)					status = "update activation failed";			} else {				status = "section replacement failed";			}		}	} else {		status = "not supported";		cl_log(LOG_ERR,		       "Action [%s] is not supported by the CIB",		       op);	}    	if (update_the_cib) {		cl_log(LOG_DEBUG, "Updating section=%s of the cib (op=%s)",		       section, op);		if (strcmp("all", section) == 0) {			// should we be doing this?			// do logging			// make changes to a temp copy then activate			xmlNodePtr tmpCib = copy_xml_node_recursive(get_the_CIB(), 1);			if (cib_update_operation == CIB_OP_ADD			    || cib_update_operation == CIB_OP_MODIFY) {				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_NODES);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_RESOURCES);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_CONSTRAINTS);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_STATUS);			} else {				// delete				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_STATUS);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_CONSTRAINTS);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_RESOURCES);				updateList(tmpCib, command, failed,					   cib_update_operation,					   XML_CIB_TAG_NODES);			}		} else {			// make changes to a temp copy then activate			CRM_DEBUG("Backing up CIB");			xmlNodePtr tmpCib = copy_xml_node_recursive(get_the_CIB(), 1);			CRM_DEBUG("Updating temporary CIB");			updateList(tmpCib, command, failed,				   cib_update_operation,				   section);			CRM_DEBUG("Activating temporary CIB");			if (activateCibXml(tmpCib) < 0)				status = "update activation failed";			else if (failed->children != NULL)				status = "some updates failed";			else				status = "ok";			CRM_DEBUG2("CIB update status: %s", status);		}	}	output_section = section;	CRM_DEBUG2("Playing with cib: %p", get_the_CIB());		/* dont de-allocate cib_section, its the real thing */	if (failed->children != NULL || strcmp("ok", status) != 0) {		output_section = "all";		cib_section = get_object_root(NULL, get_the_CIB());	} else if (strcmp("true", verbose) == 0) {		cib_section = get_object_root(output_section, get_the_CIB());	}	if(cib_section != NULL) {		xmlAddChild(cib_answer, createCibFragmentAnswer(output_section,								cib_section,								failed));	}    	set_xml_property_copy(cib_answer, XML_CIB_ATTR_SECTION, section);	set_xml_property_copy(cib_answer, XML_CIB_ATTR_RESULT, status);	free_xml(failed);	FNRET(cib_answer);}