X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityxml.cpp;h=a44057368ff3a4728ee4dc7a42e7dca56ddcdaa8;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=f4e8c542723617b2105b8885e9a9599e3a6b51c9;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/src/freenet/identityxml.cpp b/src/freenet/identityxml.cpp index f4e8c54..a440573 100644 --- a/src/freenet/identityxml.cpp +++ b/src/freenet/identityxml.cpp @@ -11,26 +11,41 @@ IdentityXML::IdentityXML() std::string IdentityXML::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("Identity"); + //TiXmlElement *tid; + //TiXmlPrinter tp; + + doc->appendChild(root); + //td.LinkEndChild(tdec); + //tid=new TiXmlElement("Identity"); + //td.LinkEndChild(tid); - td.LinkEndChild(tdec); - tid=new TiXmlElement("Identity"); - td.LinkEndChild(tid); + root->appendChild(XMLCreateCDATAElement(doc,"Name",m_name)); + //tid->LinkEndChild(XMLCreateCDATAElement("Name",m_name)); - tid->LinkEndChild(XMLCreateCDATAElement("Name",m_name)); + root->appendChild(XMLCreateBooleanElement(doc,"SingleUse",m_singleuse)); + //tid->LinkEndChild(XMLCreateBooleanElement("SingleUse",m_singleuse)); - tid->LinkEndChild(XMLCreateBooleanElement("SingleUse",m_singleuse)); + root->appendChild(XMLCreateBooleanElement(doc,"PublishTrustList",m_publishtrustlist)); + //tid->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",m_publishtrustlist)); - tid->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",m_publishtrustlist)); + root->appendChild(XMLCreateBooleanElement(doc,"PublishBoardList",m_publishboardlist)); + //tid->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",m_publishboardlist)); - tid->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",m_publishboardlist)); + // freesite edition will be -1 if identity isn't publishing a freesite + if(m_freesiteedition>=0) + { + root->appendChild(XMLCreateTextElement(doc,"FreesiteEdition",m_freesiteedition)); + //tid->LinkEndChild(XMLCreateTextElement("FreesiteEdition",m_freesiteedition)); + } - td.Accept(&tp); - return std::string(tp.CStr()); + //td.Accept(&tp); + //return std::string(tp.CStr()); + return GenerateXML(doc); } void IdentityXML::Initialize() @@ -39,10 +54,60 @@ void IdentityXML::Initialize() m_publishtrustlist=false; m_publishboardlist=false; m_singleuse=false; + m_freesiteedition=-1; } const bool IdentityXML::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,"Identity"); + Poco::XML::Element *txt=NULL; + + txt=XMLGetFirstChild(root,"Name"); + if(txt) + { + if(txt->firstChild()) + { + m_name=txt->firstChild()->getNodeValue(); + if(m_name.size()>40) + { + m_name.erase(40); + } + } + } + + m_singleuse=XMLGetBooleanElement(root,"SingleUse"); + m_publishtrustlist=XMLGetBooleanElement(root,"PublishTrustList"); + m_publishboardlist=XMLGetBooleanElement(root,"PublishBoardList"); + + txt=XMLGetFirstChild(root,"FreesiteEdition"); + if(txt) + { + if(txt->firstChild()) + { + std::string editionstr=txt->firstChild()->getNodeValue(); + StringFunctions::Convert(editionstr,m_freesiteedition); + } + } + + parsed=true; + + } + catch(...) + { + } + + return parsed; + + /* TiXmlDocument td; td.Parse(xml.c_str()); @@ -59,12 +124,24 @@ const bool IdentityXML::ParseXML(const std::string &xml) m_name=txt->ValueStr(); } + if(m_name.size()>40) + { + m_name.erase(40); + } + m_singleuse=XMLGetBooleanElement(hnd.FirstChild("Identity").ToElement(),"SingleUse"); m_publishtrustlist=XMLGetBooleanElement(hnd.FirstChild("Identity").ToElement(),"PublishTrustList"); m_publishboardlist=XMLGetBooleanElement(hnd.FirstChild("Identity").ToElement(),"PublishBoardList"); + txt=hnd.FirstChild("Identity").FirstChild("FreesiteEdition").FirstChild().ToText(); + if(txt) + { + std::string editionstr=SanitizeSingleString(txt->ValueStr()); + StringFunctions::Convert(editionstr,m_freesiteedition); + } + return true; } @@ -72,5 +149,5 @@ const bool IdentityXML::ParseXML(const std::string &xml) { return false; } - +*/ }