X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistxml.cpp;h=95d3c5e1e74b82efe15566f2b2bf94e826b66bd8;hb=76805933f794915a72b7f0a21b12af6654759f4f;hp=05208fa0fe83a363eb1d7ab2ffae8de20d6c27a6;hpb=1230cc420c955e75051d011d964bc68f061ba08c;p=fms.git diff --git a/src/freenet/trustlistxml.cpp b/src/freenet/trustlistxml.cpp index 05208fa..95d3c5e 100644 --- a/src/freenet/trustlistxml.cpp +++ b/src/freenet/trustlistxml.cpp @@ -79,14 +79,10 @@ std::string TrustListXML::GetTrustListTrustComment(const long index) std::string TrustListXML::GetXML() { - TiXmlDocument td; - TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); - TiXmlElement *tid; - TiXmlPrinter tp; + Poco::AutoPtr doc=new Poco::XML::Document; + Poco::AutoPtr root=doc->createElement("TrustList"); - td.LinkEndChild(tdec); - tid=new TiXmlElement("TrustList"); - td.LinkEndChild(tid); + doc->appendChild(root); for(std::vector::iterator i=m_trust.begin(); i!=m_trust.end(); i++) { @@ -94,29 +90,28 @@ std::string TrustListXML::GetXML() std::string trustlisttrust; StringFunctions::Convert((*i).m_messagetrust,messagetrust); StringFunctions::Convert((*i).m_trustlisttrust,trustlisttrust); - TiXmlElement *tr=new TiXmlElement("Trust"); - tid->LinkEndChild(tr); - tr->LinkEndChild(XMLCreateCDATAElement("Identity",(*i).m_identity)); + Poco::AutoPtr tr=doc->createElement("Trust"); + root->appendChild(tr); + tr->appendChild(XMLCreateCDATAElement(doc,"Identity",(*i).m_identity)); if((*i).m_messagetrust>=0) { - tr->LinkEndChild(XMLCreateTextElement("MessageTrustLevel",messagetrust)); + tr->appendChild(XMLCreateTextElement(doc,"MessageTrustLevel",messagetrust)); } if((*i).m_trustlisttrust>=0) { - tr->LinkEndChild(XMLCreateTextElement("TrustListTrustLevel",trustlisttrust)); + tr->appendChild(XMLCreateTextElement(doc,"TrustListTrustLevel",trustlisttrust)); } if((*i).m_messagetrustcomment!="") { - tr->LinkEndChild(XMLCreateCDATAElement("MessageTrustComment",(*i).m_messagetrustcomment)); + tr->appendChild(XMLCreateTextElement(doc,"MessageTrustComment",(*i).m_messagetrustcomment)); } if((*i).m_trustlisttrustcomment!="") { - tr->LinkEndChild(XMLCreateCDATAElement("TrustListTrustComment",(*i).m_trustlisttrustcomment)); + tr->appendChild(XMLCreateTextElement(doc,"TrustListTrustComment",(*i).m_trustlisttrustcomment)); } } - td.Accept(&tp); - return std::string(tp.CStr()); + return GenerateXML(doc); } void TrustListXML::Initialize() @@ -126,90 +121,95 @@ void TrustListXML::Initialize() const bool TrustListXML::ParseXML(const std::string &xml) { - TiXmlDocument td; - td.Parse(xml.c_str()); - if(!td.Error()) + bool parsed=false; + Poco::XML::DOMParser dp; + + Initialize(); + + try { - std::string identity; - std::string messagetruststr; - std::string trustlisttruststr; - std::string messagetrustcomment=""; - std::string trustlisttrustcomment=""; - long messagetrust; - long trustlisttrust; - TiXmlText *txt; - TiXmlHandle hnd(&td); - TiXmlNode *node; - std::vector m_foundkeys; - - Initialize(); - - node=hnd.FirstChild("TrustList").FirstChild("Trust").ToElement(); - while(node) + Poco::AutoPtr doc=dp.parseString(FixCDATA(xml)); + Poco::XML::Element *root=XMLGetFirstChild(doc,"TrustList"); + Poco::XML::Element *trustel=NULL; + Poco::XML::Element *txt=NULL; + + std::vector foundkeys; + + trustel=XMLGetFirstChild(root,"Trust"); + while(trustel) { - identity=""; - messagetrust=-1; - trustlisttrust=-1; - messagetrustcomment=""; - trustlisttrustcomment=""; - - TiXmlHandle hnd2(node); - txt=hnd2.FirstChild("Identity").FirstChild().ToText(); + std::string identity=""; + int messagetrust=-1; + int trustlisttrust=-1; + std::string messagetrustcomment=""; + std::string trustlisttrustcomment=""; + + txt=XMLGetFirstChild(trustel,"Identity"); if(txt) { - identity=SanitizeSingleString(txt->ValueStr()); + if(txt->firstChild()) + { + identity=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - txt=hnd2.FirstChild("MessageTrustLevel").FirstChild().ToText(); + txt=XMLGetFirstChild(trustel,"MessageTrustLevel"); if(txt) { - messagetruststr=SanitizeSingleString(txt->ValueStr()); - if(messagetruststr!="") + if(txt->firstChild()) { - StringFunctions::Convert(messagetruststr,messagetrust); + std::string mtl=txt->firstChild()->getNodeValue(); + StringFunctions::Convert(mtl,messagetrust); } } - txt=hnd2.FirstChild("TrustListTrustLevel").FirstChild().ToText(); + txt=XMLGetFirstChild(trustel,"TrustListTrustLevel"); if(txt) { - trustlisttruststr=SanitizeSingleString(txt->ValueStr()); - if(trustlisttruststr!="") + if(txt->firstChild()) { - StringFunctions::Convert(trustlisttruststr,trustlisttrust); + std::string tltl=txt->firstChild()->getNodeValue(); + StringFunctions::Convert(tltl,trustlisttrust); } } - txt=hnd2.FirstChild("MessageTrustComment").FirstChild().ToText(); + txt=XMLGetFirstChild(trustel,"MessageTrustComment"); if(txt) { - messagetrustcomment=txt->ValueStr(); + if(txt->firstChild()) + { + messagetrustcomment=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - txt=hnd2.FirstChild("TrustListTrustComment").FirstChild().ToText(); + txt=XMLGetFirstChild(trustel,"TrustListTrustComment"); if(txt) { - trustlisttrustcomment=txt->ValueStr(); + if(txt->firstChild()) + { + trustlisttrustcomment=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } if(identity!="" && messagetrust>=-1 && messagetrust<=100 && trustlisttrust>=-1 && trustlisttrust<=100) { // check so we don't add the same identity multiple times from a trust list - if(std::find(m_foundkeys.begin(),m_foundkeys.end(),identity)==m_foundkeys.end()) + if(std::find(foundkeys.begin(),foundkeys.end(),identity)==foundkeys.end()) { - m_foundkeys.push_back(identity); + foundkeys.push_back(identity); m_trust.push_back(trust(identity,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment)); } } else { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListXML::ParseXML malformed Trust in TrustList.xml"); + m_log->error("TrustListXML::ParseXML malformed Trust in TrustList.xml"); } - - node=node->NextSibling("Trust"); + + trustel=XMLGetNextSibling(trustel,"Trust"); } - return true; + parsed=true; } - else + catch(...) { - return false; } + + return parsed; }