--- /dev/null
+#include "../../include/http/identityexportxml.h"\r
+\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
+IdentityExportXML::IdentityExportXML()\r
+{\r
+ Initialize();\r
+}\r
+\r
+void IdentityExportXML::AddIdentity(const std::string &name, const std::string &publickey, const std::string &privatekey, const bool singleuse, const bool publishtrustlist, const bool publishboardlist)\r
+{\r
+ m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));\r
+}\r
+\r
+const std::string IdentityExportXML::GetName(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_name;\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+}\r
+\r
+const std::string IdentityExportXML::GetPrivateKey(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_privatekey;\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+}\r
+\r
+const std::string IdentityExportXML::GetPublicKey(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_publickey;\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+}\r
+\r
+const bool IdentityExportXML::GetPublishBoardList(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_publishboardlist;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
+\r
+const bool IdentityExportXML::GetPublishTrustList(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_publishtrustlist;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
+\r
+const bool IdentityExportXML::GetSingleUse(const long index)\r
+{\r
+ if(index>=0 && index<GetCount())\r
+ {\r
+ return m_identities[index].m_singleuse;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
+\r
+std::string IdentityExportXML::GetXML()\r
+{\r
+ TiXmlDocument td;\r
+ TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");\r
+ TiXmlElement *tid;\r
+ TiXmlPrinter tp;\r
+\r
+ td.LinkEndChild(tdec);\r
+ tid=new TiXmlElement("IdentityExport");\r
+ td.LinkEndChild(tid);\r
+\r
+ for(std::vector<identity>::iterator i=m_identities.begin(); i!=m_identities.end(); i++)\r
+ {\r
+ TiXmlElement *tr=new TiXmlElement("Identity");\r
+ tid->LinkEndChild(tr);\r
+ tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));\r
+ tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey));\r
+ tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey));\r
+ tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse));\r
+ tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist));\r
+ tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist));\r
+ }\r
+\r
+ td.Accept(&tp);\r
+ return std::string(tp.CStr());\r
+}\r
+\r
+void IdentityExportXML::Initialize()\r
+{\r
+ m_identities.clear();\r
+}\r
+\r
+const bool IdentityExportXML::ParseXML(const std::string &xml)\r
+{\r
+ TiXmlDocument td;\r
+ td.Parse(xml.c_str());\r
+\r
+ if(!td.Error())\r
+ {\r
+ std::string name;\r
+ std::string publickey;\r
+ std::string privatekey;\r
+ bool singleuse=false;\r
+ bool publishtrustlist=false;\r
+ bool publishboardlist=false;\r
+ TiXmlText *txt;\r
+ TiXmlHandle hnd(&td);\r
+ TiXmlNode *node;\r
+\r
+ Initialize();\r
+\r
+ node=hnd.FirstChild("IdentityExport").FirstChild("Identity").ToElement();\r
+ while(node)\r
+ {\r
+ name="";\r
+ publickey="";\r
+ privatekey="";\r
+ singleuse=false;\r
+ publishtrustlist=false;\r
+ publishboardlist=false;\r
+\r
+ TiXmlHandle hnd2(node);\r
+ txt=hnd2.FirstChild("Name").FirstChild().ToText();\r
+ if(txt)\r
+ {\r
+ name=txt->ValueStr();\r
+ }\r
+ txt=hnd2.FirstChild("PublicKey").FirstChild().ToText();\r
+ if(txt)\r
+ {\r
+ publickey=txt->ValueStr();\r
+ }\r
+ txt=hnd2.FirstChild("PrivateKey").FirstChild().ToText();\r
+ if(txt)\r
+ {\r
+ privatekey=txt->ValueStr();\r
+ }\r
+\r
+ singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse");\r
+ publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList");\r
+ publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList");\r
+\r
+ if(name!="" && publickey!="" && privatekey!="")\r
+ {\r
+ m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));\r
+ }\r
+ \r
+ node=node->NextSibling("Identity");\r
+ }\r
+ return true;\r
+\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}
\ No newline at end of file