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, const bool publishfreesite)
\r
14 m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));
\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::GetPublishFreesite(const long index)
\r
67 if(index>=0 && index<GetCount())
\r
69 return m_identities[index].m_publishfreesite;
\r
77 const bool IdentityExportXML::GetPublishTrustList(const long index)
\r
79 if(index>=0 && index<GetCount())
\r
81 return m_identities[index].m_publishtrustlist;
\r
89 const bool IdentityExportXML::GetSingleUse(const long index)
\r
91 if(index>=0 && index<GetCount())
\r
93 return m_identities[index].m_singleuse;
\r
101 std::string IdentityExportXML::GetXML()
\r
103 Poco::AutoPtr<Poco::XML::Document> doc=new Poco::XML::Document;
\r
104 Poco::XML::Element *root=doc->createElement("IdentityExport");
\r
105 Poco::XML::Element *el=NULL;
\r
106 //TiXmlDocument td;
\r
107 //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");
\r
108 //TiXmlElement *tid;
\r
111 doc->appendChild(root);
\r
112 //td.LinkEndChild(tdec);
\r
113 //tid=new TiXmlElement("IdentityExport");
\r
114 //td.LinkEndChild(tid);
\r
116 for(std::vector<identity>::iterator i=m_identities.begin(); i!=m_identities.end(); i++)
\r
118 el=doc->createElement("Identity");
\r
119 //TiXmlElement *tr=new TiXmlElement("Identity");
\r
120 root->appendChild(el);
\r
121 //tid->LinkEndChild(tr);
\r
123 el->appendChild(XMLCreateCDATAElement(doc,"Name",(*i).m_name));
\r
124 el->appendChild(XMLCreateTextElement(doc,"PublicKey",(*i).m_publickey));
\r
125 el->appendChild(XMLCreateTextElement(doc,"PrivateKey",(*i).m_privatekey));
\r
126 el->appendChild(XMLCreateBooleanElement(doc,"SingleUse",(*i).m_singleuse));
\r
127 el->appendChild(XMLCreateBooleanElement(doc,"PublishTrustList",(*i).m_publishtrustlist));
\r
128 el->appendChild(XMLCreateBooleanElement(doc,"PublishBoardList",(*i).m_publishboardlist));
\r
129 el->appendChild(XMLCreateBooleanElement(doc,"PublishFreesite",(*i).m_publishfreesite));
\r
131 //tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));
\r
132 //tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey));
\r
133 //tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey));
\r
134 //tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse));
\r
135 //tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist));
\r
136 //tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist));
\r
137 //tr->LinkEndChild(XMLCreateBooleanElement("PublishFreesite",(*i).m_publishfreesite));
\r
141 //return std::string(tp.CStr());
\r
144 xml=GenerateXML(doc);
\r
149 void IdentityExportXML::Initialize()
\r
151 m_identities.clear();
\r
154 const bool IdentityExportXML::ParseXML(const std::string &xml)
\r
157 Poco::XML::DOMParser dp;
\r
163 Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
\r
164 Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityExport");
\r
165 Poco::XML::Element *node=XMLGetFirstChild(root,"Identity");
\r
169 std::string name="";
\r
170 std::string publickey="";
\r
171 std::string privatekey="";
\r
172 bool singleuse=false;
\r
173 bool publishtrustlist=false;
\r
174 bool publishboardlist=false;
\r
175 bool publishfreesite=false;
\r
177 Poco::XML::Element *text=XMLGetFirstChild(node,"Name");
\r
180 if(text->firstChild())
\r
182 std::string asdf=text->innerText();
\r
183 asdf=text->firstChild()->innerText();
\r
184 name=text->firstChild()->getNodeValue();
\r
187 text=XMLGetFirstChild(node,"PublicKey");
\r
190 if(text->firstChild())
\r
192 publickey=text->firstChild()->getNodeValue();
\r
195 text=XMLGetFirstChild(node,"PrivateKey");
\r
198 if(text->firstChild())
\r
200 privatekey=text->firstChild()->getNodeValue();
\r
204 singleuse=XMLGetBooleanElement(node,"SingleUse");
\r
205 publishtrustlist=XMLGetBooleanElement(node,"PublishTrustList");
\r
206 publishboardlist=XMLGetBooleanElement(node,"PublishBoardList");
\r
207 publishfreesite=XMLGetBooleanElement(node,"PublishFreesite");
\r
209 if(name!="" && publickey!="" && privatekey!="")
\r
211 m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));
\r
214 node=XMLGetNextSibling(node,"Identity");
\r
225 //TiXmlDocument td;
\r
226 //td.Parse(xml.c_str());
\r
231 std::string publickey;
\r
232 std::string privatekey;
\r
233 bool singleuse=false;
\r
234 bool publishtrustlist=false;
\r
235 bool publishboardlist=false;
\r
236 bool publishfreesite=false;
\r
238 TiXmlHandle hnd(&td);
\r
243 node=hnd.FirstChild("IdentityExport").FirstChild("Identity").ToElement();
\r
250 publishtrustlist=false;
\r
251 publishboardlist=false;
\r
252 publishfreesite=false;
\r
254 TiXmlHandle hnd2(node);
\r
255 txt=hnd2.FirstChild("Name").FirstChild().ToText();
\r
258 name=txt->ValueStr();
\r
260 txt=hnd2.FirstChild("PublicKey").FirstChild().ToText();
\r
263 publickey=txt->ValueStr();
\r
265 txt=hnd2.FirstChild("PrivateKey").FirstChild().ToText();
\r
268 privatekey=txt->ValueStr();
\r
271 singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse");
\r
272 publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList");
\r
273 publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList");
\r
274 publishfreesite=XMLGetBooleanElement(node->ToElement(),"PublishFreesite");
\r
276 if(name!="" && publickey!="" && privatekey!="")
\r
278 m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));
\r
281 node=node->NextSibling("Identity");
\r