X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fidentityexportxml.cpp;h=aff7623d9d2d0e7066ac17f40559338833a83616;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=e8d9d0be3f402ee9a092094d3a8c329e0174e418;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git diff --git a/src/http/identityexportxml.cpp b/src/http/identityexportxml.cpp index e8d9d0b..aff7623 100644 --- a/src/http/identityexportxml.cpp +++ b/src/http/identityexportxml.cpp @@ -100,30 +100,50 @@ const bool IdentityExportXML::GetSingleUse(const long index) std::string IdentityExportXML::GetXML() { - TiXmlDocument td; - TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); - TiXmlElement *tid; - TiXmlPrinter tp; + Poco::AutoPtr doc=new Poco::XML::Document; + Poco::XML::Element *root=doc->createElement("IdentityExport"); + Poco::XML::Element *el=NULL; + //TiXmlDocument td; + //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); + //TiXmlElement *tid; + //TiXmlPrinter tp; - td.LinkEndChild(tdec); - tid=new TiXmlElement("IdentityExport"); - td.LinkEndChild(tid); + doc->appendChild(root); + //td.LinkEndChild(tdec); + //tid=new TiXmlElement("IdentityExport"); + //td.LinkEndChild(tid); for(std::vector::iterator i=m_identities.begin(); i!=m_identities.end(); i++) { - TiXmlElement *tr=new TiXmlElement("Identity"); - tid->LinkEndChild(tr); - tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name)); - tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey)); - tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey)); - tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse)); - tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist)); - tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist)); - tr->LinkEndChild(XMLCreateBooleanElement("PublishFreesite",(*i).m_publishfreesite)); + el=doc->createElement("Identity"); + //TiXmlElement *tr=new TiXmlElement("Identity"); + root->appendChild(el); + //tid->LinkEndChild(tr); + + el->appendChild(XMLCreateCDATAElement(doc,"Name",(*i).m_name)); + el->appendChild(XMLCreateTextElement(doc,"PublicKey",(*i).m_publickey)); + el->appendChild(XMLCreateTextElement(doc,"PrivateKey",(*i).m_privatekey)); + el->appendChild(XMLCreateBooleanElement(doc,"SingleUse",(*i).m_singleuse)); + el->appendChild(XMLCreateBooleanElement(doc,"PublishTrustList",(*i).m_publishtrustlist)); + el->appendChild(XMLCreateBooleanElement(doc,"PublishBoardList",(*i).m_publishboardlist)); + el->appendChild(XMLCreateBooleanElement(doc,"PublishFreesite",(*i).m_publishfreesite)); + + //tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name)); + //tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey)); + //tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey)); + //tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse)); + //tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist)); + //tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist)); + //tr->LinkEndChild(XMLCreateBooleanElement("PublishFreesite",(*i).m_publishfreesite)); } - td.Accept(&tp); - return std::string(tp.CStr()); + //td.Accept(&tp); + //return std::string(tp.CStr()); + + std::string xml; + xml=GenerateXML(doc); + + return xml; } void IdentityExportXML::Initialize() @@ -133,9 +153,78 @@ void IdentityExportXML::Initialize() const bool IdentityExportXML::ParseXML(const std::string &xml) { - TiXmlDocument td; - td.Parse(xml.c_str()); + bool parsed=false; + Poco::XML::DOMParser dp; + + Initialize(); + + try + { + Poco::AutoPtr doc=dp.parseString(FixCDATA(xml)); + Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityExport"); + Poco::XML::Element *node=XMLGetFirstChild(root,"Identity"); + + while(node) + { + std::string name=""; + std::string publickey=""; + std::string privatekey=""; + bool singleuse=false; + bool publishtrustlist=false; + bool publishboardlist=false; + bool publishfreesite=false; + + Poco::XML::Element *text=XMLGetFirstChild(node,"Name"); + if(text) + { + if(text->firstChild()) + { + std::string asdf=text->innerText(); + asdf=text->firstChild()->innerText(); + name=text->firstChild()->getNodeValue(); + } + } + text=XMLGetFirstChild(node,"PublicKey"); + if(text) + { + if(text->firstChild()) + { + publickey=text->firstChild()->getNodeValue(); + } + } + text=XMLGetFirstChild(node,"PrivateKey"); + if(text) + { + if(text->firstChild()) + { + privatekey=text->firstChild()->getNodeValue(); + } + } + + singleuse=XMLGetBooleanElement(node,"SingleUse"); + publishtrustlist=XMLGetBooleanElement(node,"PublishTrustList"); + publishboardlist=XMLGetBooleanElement(node,"PublishBoardList"); + publishfreesite=XMLGetBooleanElement(node,"PublishFreesite"); + + if(name!="" && publickey!="" && privatekey!="") + { + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite)); + } + + node=XMLGetNextSibling(node,"Identity"); + } + + parsed=true; + } + catch(...) + { + } + + return parsed; + //TiXmlDocument td; + //td.Parse(xml.c_str()); +/* if(!td.Error()) { std::string name; @@ -198,4 +287,5 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) { return false; } +*/ }