version 0.1.9
[fms.git] / src / freenet / identityintroductionxml.cpp
1 #include "../../include/freenet/identityintroductionxml.h"\r
2 #include "../../include/freenet/freenetssk.h"\r
3 \r
4 #ifdef XMEM\r
5         #include <xmem.h>\r
6 #endif\r
7 \r
8 IdentityIntroductionXML::IdentityIntroductionXML()\r
9 {\r
10         Initialize();\r
11 }\r
12 \r
13 std::string IdentityIntroductionXML::GetXML()\r
14 {\r
15         TiXmlDocument td;\r
16         TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");\r
17         TiXmlElement *tid;\r
18         TiXmlPrinter tp;\r
19 \r
20         td.LinkEndChild(tdec);\r
21         tid=new TiXmlElement("IdentityIntroduction");\r
22         td.LinkEndChild(tid);\r
23 \r
24         tid->LinkEndChild(XMLCreateCDATAElement("Identity",m_identity));\r
25 \r
26         td.Accept(&tp);\r
27         return std::string(tp.CStr());\r
28 }\r
29 \r
30 void IdentityIntroductionXML::Initialize()\r
31 {\r
32         m_identity="";\r
33 }\r
34 \r
35 const bool IdentityIntroductionXML::ParseXML(const std::string &xml)\r
36 {\r
37         FreenetSSK ssk;\r
38         TiXmlDocument td;\r
39         td.Parse(xml.c_str());\r
40 \r
41         if(!td.Error())\r
42         {\r
43                 TiXmlText *txt;\r
44                 TiXmlHandle hnd(&td);\r
45 \r
46                 Initialize();\r
47 \r
48                 txt=hnd.FirstChild("IdentityIntroduction").FirstChild("Identity").FirstChild().ToText();\r
49                 if(txt)\r
50                 {\r
51                         m_identity=txt->ValueStr();\r
52                 }\r
53                 ssk.SetPublicKey(m_identity);\r
54                 if(ssk.ValidPublicKey()==false)\r
55                 {\r
56                         return false;\r
57                 }\r
58 \r
59                 return true;\r
60 \r
61         }\r
62         else\r
63         {\r
64                 return false;\r
65         }\r
66 \r
67 }\r