version 0.3.2
[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         Poco::AutoPtr<Poco::XML::Document> doc=new Poco::XML::Document;\r
16         Poco::AutoPtr<Poco::XML::Element> root=doc->createElement("IdentityIntroduction");\r
17 \r
18         doc->appendChild(root);\r
19 \r
20         root->appendChild(XMLCreateCDATAElement(doc,"Identity",m_identity));\r
21 \r
22         return GenerateXML(doc);\r
23 }\r
24 \r
25 void IdentityIntroductionXML::Initialize()\r
26 {\r
27         m_identity="";\r
28 }\r
29 \r
30 const bool IdentityIntroductionXML::ParseXML(const std::string &xml)\r
31 {\r
32         FreenetSSK ssk;\r
33         bool parsed=false;\r
34         Poco::XML::DOMParser dp;\r
35 \r
36         Initialize();\r
37 \r
38         try\r
39         {\r
40                 Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));\r
41                 Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityIntroduction");\r
42                 Poco::XML::Element *txt=NULL;\r
43 \r
44                 txt=XMLGetFirstChild(root,"Identity");\r
45                 if(txt)\r
46                 {\r
47                         if(txt->firstChild())\r
48                         {\r
49                                 m_identity=SanitizeSingleString(txt->firstChild()->getNodeValue());\r
50                         }\r
51                 }\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                 parsed=true;\r
60         }\r
61         catch(...)\r
62         {\r
63         }\r
64 \r
65         return parsed;\r
66 }\r