From 040ba55f3f7701b29f190d3a2475ac29676b2b60 Mon Sep 17 00:00:00 2001 From: Andrea Zoli Date: Fri, 6 Jun 2014 17:28:02 +0200 Subject: [PATCH] Fix loop on rblock idref/id resolution during xml parsing. --- src/XmlConfig.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/XmlConfig.cpp b/src/XmlConfig.cpp index ff3b4a9..8ad0ead 100644 --- a/src/XmlConfig.cpp +++ b/src/XmlConfig.cpp @@ -204,15 +204,47 @@ void XmlConfig::_writeRBlock(xml_node rblock, fstream& fs, xml_document& doc) fs << "0" << endl; else { +#ifdef DEBUG + cout << "rblock name='" << rblocks[i].attribute("name").value() << "' idref='" << rblocks[i].attribute("idref").value() << "' "; +#endif string query = string("//field[@id=\"")+idref.value()+"\"]"; xml_node numberofblocksid = doc.select_nodes(query.c_str())[0].node(); xml_node nodetmp = rblocks[i]; unsigned int level = 0; + while(nodetmp.parent() != numberofblocksid.parent()) { + // if the parent is a packet means that the id is not in the fixed part of the + // recursive rblocks nor the sourcedatafield. So test the datafieldheader + // and header, otherwise complain. + if(string(nodetmp.parent().name()).compare("packet") == 0) + { + string idparentnodename = numberofblocksid.parent().name(); + if(idparentnodename.compare("datafieldheader") == 0) + { + // we have already add 1 level because nodetmp in this case is + // the sourcedatafield node + } + else if(idparentnodename.compare("header") == 0) + { + // we add just one level for the same reason above + level++; + } + else + { + cerr << "Error on id association. Id '" << idref.value() << "' doesn't exists. "; + cerr << "idref defined by rblock '" << rblocks[i].attribute("name").value() << "'." << endl; + exit(0); + } + + break; + } level++; nodetmp = nodetmp.parent(); } +#ifdef DEBUG + cout << "levels=" << level << endl; +#endif fs << level << endl; fs << "-- for variable block, index of field of the header which rappresent the number of events (the number of blocks) of the packet" << endl; fs << _physicalIndex[numberofblocksid] << endl; @@ -407,6 +439,9 @@ std::string XmlConfig::convert(const std::string& filename) for(unsigned int i=0; i