diff --git a/include/ObjectXML.h b/include/ObjectXML.h index 8232bd644e..55ce85d61c 100644 --- a/include/ObjectXML.h +++ b/include/ObjectXML.h @@ -316,15 +316,21 @@ public: */ friend std::ostream& operator<<(std::ostream& os, ObjectXML& oxml) { - xmlChar * mem; - int size; + xmlNodePtr root_node = xmlDocGetRootElement(oxml.xml); - xmlDocDumpMemory(oxml.xml,&mem,&size); + if ( root_node == 0 ) + { + return os; + } - std::string str(reinterpret_cast(mem)); + xmlBufferPtr buffer = xmlBufferCreate(); + + xmlNodeDump(buffer, oxml.xml, root_node, 0, 0); + + std::string str(reinterpret_cast(buffer->content)); os << str; - xmlFree(mem); + xmlBufferFree(buffer); return os; }; diff --git a/src/vm/History.cc b/src/vm/History.cc index eb7eeb0d25..3cb8fd391f 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -380,23 +380,21 @@ int History::rebuild_attributes() // ------------------------------------------------------------------------- ObjectXML::get_nodes("/HISTORY/VM", content); - if (content.empty()) + if (!content.empty()) { - return -1; + ObjectXML vm_info_xml(content[0]); + + ostringstream oss; + + oss << vm_info_xml; + + vm_info = oss.str(); + + ObjectXML::free_nodes(content); + + content.clear(); } - ObjectXML vm_info_xml(content[0]); - - ostringstream oss; - - oss << vm_info_xml; - - vm_info = oss.str(); - - ObjectXML::free_nodes(content); - - content.clear(); - non_persistent_data(); if (rc != 0) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 0996ba1d9d..44ed421a48 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -505,10 +505,12 @@ int VirtualMachine::select(SqlDB * db) return rc; } - //Get History Records. Current history is built in from_xml() (if any). + //Get History Records. if( hasHistory() ) { - last_seq = history->seq - 1; + last_seq = history->seq; + + delete history_records[last_seq]; for (int i = last_seq; i >= 0; i--) { @@ -525,6 +527,10 @@ int VirtualMachine::select(SqlDB * db) history_records[i] = hp; if ( i == last_seq ) + { + history = hp; + } + else if ( i == last_seq - 1 ) { previous_history = hp; } @@ -2117,18 +2123,15 @@ int VirtualMachine::from_xml(const string &xml_str) // ------------------------------------------------------------------------- // Last history entry // ------------------------------------------------------------------------- - ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content); + int last_seq; - if (!content.empty()) + if ( xpath(last_seq,"/VM/HISTORY_RECORDS/HISTORY/SEQ", -1) == 0 && + last_seq != -1 ) { - history = new History(oid); - rc += history->from_xml_node(content[0]); + history = new History(oid, last_seq); history_records.resize(history->seq + 1); history_records[history->seq] = history; - - ObjectXML::free_nodes(content); - content.clear(); } // -------------------------------------------------------------------------