X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fidentityexportxml.cpp;h=aff7623d9d2d0e7066ac17f40559338833a83616;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=1f87e856650c4debe729727d62a785d7ac04559b;hpb=df316253862dc50e8e5a790d9634ef90be37badb;p=fms.git diff --git a/src/http/identityexportxml.cpp b/src/http/identityexportxml.cpp index 1f87e85..aff7623 100644 --- a/src/http/identityexportxml.cpp +++ b/src/http/identityexportxml.cpp @@ -9,9 +9,9 @@ IdentityExportXML::IdentityExportXML() Initialize(); } -void IdentityExportXML::AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist) +void IdentityExportXML::AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist, const bool publishfreesite) { - m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite)); } const std::string IdentityExportXML::GetName(const long index) @@ -62,6 +62,18 @@ const bool IdentityExportXML::GetPublishBoardList(const long index) } } +const bool IdentityExportXML::GetPublishFreesite(const long index) +{ + if(index>=0 && index=0 && index 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)); + 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() @@ -120,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; @@ -131,6 +233,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) bool singleuse=false; bool publishtrustlist=false; bool publishboardlist=false; + bool publishfreesite=false; TiXmlText *txt; TiXmlHandle hnd(&td); TiXmlNode *node; @@ -146,6 +249,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) singleuse=false; publishtrustlist=false; publishboardlist=false; + publishfreesite=false; TiXmlHandle hnd2(node); txt=hnd2.FirstChild("Name").FirstChild().ToText(); @@ -167,10 +271,11 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse"); publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList"); publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList"); + publishfreesite=XMLGetBooleanElement(node->ToElement(),"PublishFreesite"); if(name!="" && publickey!="" && privatekey!="") { - m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite)); } node=node->NextSibling("Identity"); @@ -182,4 +287,5 @@ const bool IdentityExportXML::ParseXML(const std::string &xml) { return false; } +*/ }