version 0.0.1
[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                 TiXmlElement *el;\r
44                 TiXmlText *txt;\r
45                 TiXmlHandle hnd(&td);\r
46 \r
47                 Initialize();\r
48 \r
49                 txt=hnd.FirstChild("IdentityIntroduction").FirstChild("Identity").FirstChild().ToText();\r
50                 if(txt)\r
51                 {\r
52                         m_identity=txt->ValueStr();\r
53                 }\r
54                 ssk.SetPublicKey(m_identity);\r
55                 if(ssk.ValidPublicKey()==false)\r
56                 {\r
57                         return false;\r
58                 }\r
59 \r
60                 return true;\r
61 \r
62         }\r
63         else\r
64         {\r
65                 return false;\r
66         }\r
67 \r
68 }