version 0.3.0
[fms.git] / src / http / identityexportxml.cpp
index b2609bf..aff7623 100644 (file)
@@ -9,9 +9,9 @@ IdentityExportXML::IdentityExportXML()
        Initialize();\r
 }\r
 \r
-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
+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
 {\r
-       m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));\r
+       m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));\r
 }\r
 \r
 const std::string IdentityExportXML::GetName(const long index)\r
@@ -62,6 +62,18 @@ const bool IdentityExportXML::GetPublishBoardList(const long index)
        }\r
 }\r
 \r
+const bool IdentityExportXML::GetPublishFreesite(const long index)\r
+{\r
+       if(index>=0 && index<GetCount())\r
+       {\r
+               return m_identities[index].m_publishfreesite;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
 const bool IdentityExportXML::GetPublishTrustList(const long index)\r
 {\r
        if(index>=0 && index<GetCount())\r
@@ -88,29 +100,50 @@ const bool IdentityExportXML::GetSingleUse(const long index)
 \r
 std::string IdentityExportXML::GetXML()\r
 {\r
-       TiXmlDocument td;\r
-       TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");\r
-       TiXmlElement *tid;\r
-       TiXmlPrinter tp;\r
+       Poco::AutoPtr<Poco::XML::Document> doc=new Poco::XML::Document;\r
+       Poco::XML::Element *root=doc->createElement("IdentityExport");\r
+       Poco::XML::Element *el=NULL;\r
+       //TiXmlDocument td;\r
+       //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");\r
+       //TiXmlElement *tid;\r
+       //TiXmlPrinter tp;\r
 \r
-       td.LinkEndChild(tdec);\r
-       tid=new TiXmlElement("IdentityExport");\r
-       td.LinkEndChild(tid);\r
+       doc->appendChild(root);\r
+       //td.LinkEndChild(tdec);\r
+       //tid=new TiXmlElement("IdentityExport");\r
+       //td.LinkEndChild(tid);\r
 \r
        for(std::vector<identity>::iterator i=m_identities.begin(); i!=m_identities.end(); i++)\r
        {\r
-               TiXmlElement *tr=new TiXmlElement("Identity");\r
-               tid->LinkEndChild(tr);\r
-               tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));\r
-               tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey));\r
-               tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey));\r
-               tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse));\r
-               tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist));\r
-               tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist));\r
+               el=doc->createElement("Identity");\r
+               //TiXmlElement *tr=new TiXmlElement("Identity");\r
+               root->appendChild(el);\r
+               //tid->LinkEndChild(tr);\r
+\r
+               el->appendChild(XMLCreateCDATAElement(doc,"Name",(*i).m_name));\r
+               el->appendChild(XMLCreateTextElement(doc,"PublicKey",(*i).m_publickey));\r
+               el->appendChild(XMLCreateTextElement(doc,"PrivateKey",(*i).m_privatekey));\r
+               el->appendChild(XMLCreateBooleanElement(doc,"SingleUse",(*i).m_singleuse));\r
+               el->appendChild(XMLCreateBooleanElement(doc,"PublishTrustList",(*i).m_publishtrustlist));\r
+               el->appendChild(XMLCreateBooleanElement(doc,"PublishBoardList",(*i).m_publishboardlist));\r
+               el->appendChild(XMLCreateBooleanElement(doc,"PublishFreesite",(*i).m_publishfreesite));\r
+\r
+               //tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));\r
+               //tr->LinkEndChild(XMLCreateTextElement("PublicKey",(*i).m_publickey));\r
+               //tr->LinkEndChild(XMLCreateTextElement("PrivateKey",(*i).m_privatekey));\r
+               //tr->LinkEndChild(XMLCreateBooleanElement("SingleUse",(*i).m_singleuse));\r
+               //tr->LinkEndChild(XMLCreateBooleanElement("PublishTrustList",(*i).m_publishtrustlist));\r
+               //tr->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",(*i).m_publishboardlist));\r
+               //tr->LinkEndChild(XMLCreateBooleanElement("PublishFreesite",(*i).m_publishfreesite));\r
        }\r
 \r
-       td.Accept(&tp);\r
-       return std::string(tp.CStr());\r
+       //td.Accept(&tp);\r
+       //return std::string(tp.CStr());\r
+\r
+       std::string xml;\r
+       xml=GenerateXML(doc);\r
+\r
+       return xml;\r
 }\r
 \r
 void IdentityExportXML::Initialize()\r
@@ -120,9 +153,78 @@ void IdentityExportXML::Initialize()
 \r
 const bool IdentityExportXML::ParseXML(const std::string &xml)\r
 {\r
-       TiXmlDocument td;\r
-       td.Parse(xml.c_str());\r
+       bool parsed=false;\r
+       Poco::XML::DOMParser dp;\r
+\r
+       Initialize();\r
+\r
+       try\r
+       {\r
+               Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));\r
+               Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityExport");\r
+               Poco::XML::Element *node=XMLGetFirstChild(root,"Identity");\r
+\r
+               while(node)\r
+               {\r
+                       std::string name="";\r
+                       std::string publickey="";\r
+                       std::string privatekey="";\r
+                       bool singleuse=false;\r
+                       bool publishtrustlist=false;\r
+                       bool publishboardlist=false;\r
+                       bool publishfreesite=false;     \r
 \r
+                       Poco::XML::Element *text=XMLGetFirstChild(node,"Name");\r
+                       if(text)\r
+                       {\r
+                               if(text->firstChild())\r
+                               {\r
+                                       std::string asdf=text->innerText();\r
+                                       asdf=text->firstChild()->innerText();\r
+                                       name=text->firstChild()->getNodeValue();\r
+                               }\r
+                       }\r
+                       text=XMLGetFirstChild(node,"PublicKey");\r
+                       if(text)\r
+                       {\r
+                               if(text->firstChild())\r
+                               {\r
+                                       publickey=text->firstChild()->getNodeValue();\r
+                               }\r
+                       }\r
+                       text=XMLGetFirstChild(node,"PrivateKey");\r
+                       if(text)\r
+                       {\r
+                               if(text->firstChild())\r
+                               {\r
+                                       privatekey=text->firstChild()->getNodeValue();\r
+                               }\r
+                       }\r
+\r
+                       singleuse=XMLGetBooleanElement(node,"SingleUse");\r
+                       publishtrustlist=XMLGetBooleanElement(node,"PublishTrustList");\r
+                       publishboardlist=XMLGetBooleanElement(node,"PublishBoardList");\r
+                       publishfreesite=XMLGetBooleanElement(node,"PublishFreesite");\r
+\r
+                       if(name!="" && publickey!="" && privatekey!="")\r
+                       {\r
+                               m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));\r
+                       }\r
+\r
+                       node=XMLGetNextSibling(node,"Identity");\r
+               }\r
+\r
+               parsed=true;\r
+       }\r
+       catch(...)\r
+       {\r
+       }\r
+\r
+       return parsed;\r
+\r
+       //TiXmlDocument td;\r
+       //td.Parse(xml.c_str());\r
+/*\r
        if(!td.Error())\r
        {\r
                std::string name;\r
@@ -131,6 +233,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml)
                bool singleuse=false;\r
                bool publishtrustlist=false;\r
                bool publishboardlist=false;\r
+               bool publishfreesite=false;\r
                TiXmlText *txt;\r
                TiXmlHandle hnd(&td);\r
                TiXmlNode *node;\r
@@ -146,6 +249,7 @@ const bool IdentityExportXML::ParseXML(const std::string &xml)
                        singleuse=false;\r
                        publishtrustlist=false;\r
                        publishboardlist=false;\r
+                       publishfreesite=false;\r
 \r
                        TiXmlHandle hnd2(node);\r
                        txt=hnd2.FirstChild("Name").FirstChild().ToText();\r
@@ -167,10 +271,11 @@ const bool IdentityExportXML::ParseXML(const std::string &xml)
                        singleuse=XMLGetBooleanElement(node->ToElement(),"SingleUse");\r
                        publishtrustlist=XMLGetBooleanElement(node->ToElement(),"PublishTrustList");\r
                        publishboardlist=XMLGetBooleanElement(node->ToElement(),"PublishBoardList");\r
+                       publishfreesite=XMLGetBooleanElement(node->ToElement(),"PublishFreesite");\r
 \r
                        if(name!="" && publickey!="" && privatekey!="")\r
                        {\r
-                               m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist));\r
+                               m_identities.push_back(identity(name,publickey,privatekey,singleuse,publishtrustlist,publishboardlist,publishfreesite));\r
                        }\r
                        \r
                        node=node->NextSibling("Identity");\r
@@ -182,4 +287,5 @@ const bool IdentityExportXML::ParseXML(const std::string &xml)
        {\r
                return false;\r
        }\r
-}
\ No newline at end of file
+*/\r
+}\r