X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fidentityexportxml.cpp;fp=src%2Fhttp%2Fidentityexportxml.cpp;h=b2609bf38d8fa144198cb903095d6c822832e0f0;hb=f60495a029c54358f82956482fe203fe2b7b5b23;hp=0000000000000000000000000000000000000000;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/src/http/identityexportxml.cpp b/src/http/identityexportxml.cpp new file mode 100644 index 0000000..b2609bf --- /dev/null +++ b/src/http/identityexportxml.cpp @@ -0,0 +1,185 @@ +#include "../../include/http/identityexportxml.h" + +#ifdef XMEM + #include +#endif + +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) +{ + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); +} + +const std::string IdentityExportXML::GetName(const long index) +{ + if(index>=0 && index=0 && index=0 && index=0 && index=0 && index=0 && index::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)); + } + + td.Accept(&tp); + return std::string(tp.CStr()); +} + +void IdentityExportXML::Initialize() +{ + m_identities.clear(); +} + +const bool IdentityExportXML::ParseXML(const std::string &xml) +{ + TiXmlDocument td; + td.Parse(xml.c_str()); + + if(!td.Error()) + { + std::string name; + std::string publickey; + std::string privatekey; + bool singleuse=false; + bool publishtrustlist=false; + bool publishboardlist=false; + TiXmlText *txt; + TiXmlHandle hnd(&td); + TiXmlNode *node; + + Initialize(); + + node=hnd.FirstChild("IdentityExport").FirstChild("Identity").ToElement(); + while(node) + { + name=""; + publickey=""; + privatekey=""; + singleuse=false; + publishtrustlist=false; + publishboardlist=false; + + TiXmlHandle hnd2(node); + txt=hnd2.FirstChild("Name").FirstChild().ToText(); + if(txt) + { + name=txt->ValueStr(); + } + txt=hnd2.FirstChild("PublicKey").FirstChild().ToText(); + if(txt) + { + publickey=txt->ValueStr(); + } + txt=hnd2.FirstChild("PrivateKey").FirstChild().ToText(); + if(txt) + { + privatekey=txt->ValueStr(); + } + + singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse"); + publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList"); + publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList"); + + if(name!="" && publickey!="" && privatekey!="") + { + m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist)); + } + + node=node->NextSibling("Identity"); + } + return true; + + } + else + { + return false; + } +} \ No newline at end of file