X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffreenet%2Ftrustlistxml.cpp;h=20fa730790d9c5fb1c2111a4f59e1b22272c769d;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=05208fa0fe83a363eb1d7ab2ffae8de20d6c27a6;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git diff --git a/src/freenet/trustlistxml.cpp b/src/freenet/trustlistxml.cpp index 05208fa..20fa730 100644 --- a/src/freenet/trustlistxml.cpp +++ b/src/freenet/trustlistxml.cpp @@ -79,14 +79,17 @@ 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; + //TiXmlDocument td; + //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); + Poco::XML::Element *root=doc->createElement("TrustList"); + //TiXmlElement *tid; + //TiXmlPrinter tp; - td.LinkEndChild(tdec); - tid=new TiXmlElement("TrustList"); - td.LinkEndChild(tid); + doc->appendChild(root); + //td.LinkEndChild(tdec); + //tid=new TiXmlElement("TrustList"); + //td.LinkEndChild(tid); for(std::vector::iterator i=m_trust.begin(); i!=m_trust.end(); i++) { @@ -94,29 +97,37 @@ 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::XML::Element *tr=doc->createElement("Trust"); + //TiXmlElement *tr=new TiXmlElement("Trust"); + root->appendChild(tr); + //tid->LinkEndChild(tr); + tr->appendChild(XMLCreateCDATAElement(doc,"Identity",(*i).m_identity)); + //tr->LinkEndChild(XMLCreateCDATAElement("Identity",(*i).m_identity)); if((*i).m_messagetrust>=0) { - tr->LinkEndChild(XMLCreateTextElement("MessageTrustLevel",messagetrust)); + tr->appendChild(XMLCreateTextElement(doc,"MessageTrustLevel",messagetrust)); + //tr->LinkEndChild(XMLCreateTextElement("MessageTrustLevel",messagetrust)); } if((*i).m_trustlisttrust>=0) { - tr->LinkEndChild(XMLCreateTextElement("TrustListTrustLevel",trustlisttrust)); + tr->appendChild(XMLCreateTextElement(doc,"TrustListTrustLevel",trustlisttrust)); + //tr->LinkEndChild(XMLCreateTextElement("TrustListTrustLevel",trustlisttrust)); } if((*i).m_messagetrustcomment!="") { - tr->LinkEndChild(XMLCreateCDATAElement("MessageTrustComment",(*i).m_messagetrustcomment)); + tr->appendChild(XMLCreateTextElement(doc,"MessageTrustComment",(*i).m_messagetrustcomment)); + //tr->LinkEndChild(XMLCreateCDATAElement("MessageTrustComment",(*i).m_messagetrustcomment)); } if((*i).m_trustlisttrustcomment!="") { - tr->LinkEndChild(XMLCreateCDATAElement("TrustListTrustComment",(*i).m_trustlisttrustcomment)); + tr->appendChild(XMLCreateTextElement(doc,"TrustListTrustComment",(*i).m_trustlisttrustcomment)); + //tr->LinkEndChild(XMLCreateCDATAElement("TrustListTrustComment",(*i).m_trustlisttrustcomment)); } } - td.Accept(&tp); - return std::string(tp.CStr()); + //td.Accept(&tp); + //return std::string(tp.CStr()); + return GenerateXML(doc); } void TrustListXML::Initialize() @@ -126,6 +137,99 @@ void TrustListXML::Initialize() const bool TrustListXML::ParseXML(const std::string &xml) { + + bool parsed=false; + Poco::XML::DOMParser dp; + + Initialize(); + + try + { + 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) + { + std::string identity=""; + int messagetrust=-1; + int trustlisttrust=-1; + std::string messagetrustcomment=""; + std::string trustlisttrustcomment=""; + + txt=XMLGetFirstChild(trustel,"Identity"); + if(txt) + { + if(txt->firstChild()) + { + identity=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + txt=XMLGetFirstChild(trustel,"MessageTrustLevel"); + if(txt) + { + if(txt->firstChild()) + { + std::string mtl=txt->firstChild()->getNodeValue(); + StringFunctions::Convert(mtl,messagetrust); + } + } + txt=XMLGetFirstChild(trustel,"TrustListTrustLevel"); + if(txt) + { + if(txt->firstChild()) + { + std::string tltl=txt->firstChild()->getNodeValue(); + StringFunctions::Convert(tltl,trustlisttrust); + } + } + txt=XMLGetFirstChild(trustel,"MessageTrustComment"); + if(txt) + { + if(txt->firstChild()) + { + messagetrustcomment=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + txt=XMLGetFirstChild(trustel,"TrustListTrustComment"); + if(txt) + { + 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(foundkeys.begin(),foundkeys.end(),identity)==foundkeys.end()) + { + foundkeys.push_back(identity); + m_trust.push_back(trust(identity,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment)); + } + } + else + { + m_log->error("TrustListXML::ParseXML malformed Trust in TrustList.xml"); + } + + trustel=XMLGetNextSibling(root,"Trust"); + } + + parsed=true; + } + catch(...) + { + } + + return parsed; + + /* TiXmlDocument td; td.Parse(xml.c_str()); @@ -212,4 +316,5 @@ const bool TrustListXML::ParseXML(const std::string &xml) { return false; } + */ }