1 #include "../../include/http/identityexportxml.h"
\r
7 IdentityExportXML::IdentityExportXML()
\r
12 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
14 m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));
\r
17 const std::string IdentityExportXML::GetName(const long index)
\r
19 if(index>=0 && index<GetCount())
\r
21 return m_identities[index].m_name;
\r
29 const std::string IdentityExportXML::GetPrivateKey(const long index)
\r
31 if(index>=0 && index<GetCount())
\r
33 return m_identities[index].m_privatekey;
\r
41 const std::string IdentityExportXML::GetPublicKey(const long index)
\r
43 if(index>=0 && index<GetCount())
\r
45 return m_identities[index].m_publickey;
\r
53 const bool IdentityExportXML::GetPublishBoardList(const long index)
\r
55 if(index>=0 && index<GetCount())
\r
57 return m_identities[index].m_publishboardlist;
\r
65 const bool IdentityExportXML::GetPublishTrustList(const long index)
\r
67 if(index>=0 && index<GetCount())
\r
69 return m_identities[index].m_publishtrustlist;
\r
77 const bool IdentityExportXML::GetSingleUse(const long index)
\r
79 if(index>=0 && index<GetCount())
\r
81 return m_identities[index].m_singleuse;
\r
89 std::string IdentityExportXML::GetXML()
\r
92 TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");
\r
96 td.LinkEndChild(tdec);
\r
97 tid=new TiXmlElement("IdentityExport");
\r
98 td.LinkEndChild(tid);
\r
100 for(std::vector<identity>::iterator i=m_identities.begin(); i!=m_identities.end(); i++)
\r
102 TiXmlElement *tr=new TiXmlElement("Identity");
\r
103 tid->LinkEndChild(tr);
\r
104 tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));
\r
105 tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey));
\r
106 tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey));
\r
107 tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse));
\r
108 tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist));
\r
109 tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist));
\r
113 return std::string(tp.CStr());
\r
116 void IdentityExportXML::Initialize()
\r
118 m_identities.clear();
\r
121 const bool IdentityExportXML::ParseXML(const std::string &xml)
\r
124 td.Parse(xml.c_str());
\r
129 std::string publickey;
\r
130 std::string privatekey;
\r
131 bool singleuse=false;
\r
132 bool publishtrustlist=false;
\r
133 bool publishboardlist=false;
\r
135 TiXmlHandle hnd(&td);
\r
140 node=hnd.FirstChild("IdentityExport").FirstChild("Identity").ToElement();
\r
147 publishtrustlist=false;
\r
148 publishboardlist=false;
\r
150 TiXmlHandle hnd2(node);
\r
151 txt=hnd2.FirstChild("Name").FirstChild().ToText();
\r
154 name=txt->ValueStr();
\r
156 txt=hnd2.FirstChild("PublicKey").FirstChild().ToText();
\r
159 publickey=txt->ValueStr();
\r
161 txt=hnd2.FirstChild("PrivateKey").FirstChild().ToText();
\r
164 privatekey=txt->ValueStr();
\r
167 singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse");
\r
168 publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList");
\r
169 publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList");
\r
171 if(name!="" && publickey!="" && privatekey!="")
\r
173 m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));
\r
176 node=node->NextSibling("Identity");
\r