1 #include "../../include/freenet/trustlistxml.h"
\r
2 #include "../../include/stringfunctions.h"
\r
10 TrustListXML::TrustListXML()
\r
15 void TrustListXML::AddTrust(const std::string &identity, const long messagetrust, const long trustlisttrust, const std::string &messagetrustcomment, const std::string &trustlisttrustcomment)
\r
17 m_trust.push_back(trust(identity,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment));
\r
20 std::string TrustListXML::GetIdentity(const long index)
\r
22 if(index>=0 && index<m_trust.size())
\r
24 return m_trust[index].m_identity;
\r
32 long TrustListXML::GetMessageTrust(const long index)
\r
34 if(index>=0 && index<m_trust.size())
\r
36 return m_trust[index].m_messagetrust;
\r
44 std::string TrustListXML::GetMessageTrustComment(const long index)
\r
46 if(index>=0 && index<m_trust.size())
\r
48 return m_trust[index].m_messagetrustcomment;
\r
56 long TrustListXML::GetTrustListTrust(const long index)
\r
58 if(index>=0 && index<m_trust.size())
\r
60 return m_trust[index].m_trustlisttrust;
\r
68 std::string TrustListXML::GetTrustListTrustComment(const long index)
\r
70 if(index>=0 && index<m_trust.size())
\r
72 return m_trust[index].m_trustlisttrustcomment;
\r
80 std::string TrustListXML::GetXML()
\r
83 TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");
\r
87 td.LinkEndChild(tdec);
\r
88 tid=new TiXmlElement("TrustList");
\r
89 td.LinkEndChild(tid);
\r
91 for(std::vector<trust>::iterator i=m_trust.begin(); i!=m_trust.end(); i++)
\r
93 std::string messagetrust;
\r
94 std::string trustlisttrust;
\r
95 StringFunctions::Convert((*i).m_messagetrust,messagetrust);
\r
96 StringFunctions::Convert((*i).m_trustlisttrust,trustlisttrust);
\r
97 TiXmlElement *tr=new TiXmlElement("Trust");
\r
98 tid->LinkEndChild(tr);
\r
99 tr->LinkEndChild(XMLCreateCDATAElement("Identity",(*i).m_identity));
\r
100 if((*i).m_messagetrust>=0)
\r
102 tr->LinkEndChild(XMLCreateTextElement("MessageTrustLevel",messagetrust));
\r
104 if((*i).m_trustlisttrust>=0)
\r
106 tr->LinkEndChild(XMLCreateTextElement("TrustListTrustLevel",trustlisttrust));
\r
108 if((*i).m_messagetrustcomment!="")
\r
110 tr->LinkEndChild(XMLCreateCDATAElement("MessageTrustComment",(*i).m_messagetrustcomment));
\r
112 if((*i).m_trustlisttrustcomment!="")
\r
114 tr->LinkEndChild(XMLCreateCDATAElement("TrustListTrustComment",(*i).m_trustlisttrustcomment));
\r
119 return std::string(tp.CStr());
\r
122 void TrustListXML::Initialize()
\r
127 const bool TrustListXML::ParseXML(const std::string &xml)
\r
130 td.Parse(xml.c_str());
\r
134 std::string identity;
\r
135 std::string messagetruststr;
\r
136 std::string trustlisttruststr;
\r
137 std::string messagetrustcomment="";
\r
138 std::string trustlisttrustcomment="";
\r
140 long trustlisttrust;
\r
142 TiXmlHandle hnd(&td);
\r
144 std::vector<std::string> m_foundkeys;
\r
148 node=hnd.FirstChild("TrustList").FirstChild("Trust").ToElement();
\r
154 messagetrustcomment="";
\r
155 trustlisttrustcomment="";
\r
157 TiXmlHandle hnd2(node);
\r
158 txt=hnd2.FirstChild("Identity").FirstChild().ToText();
\r
161 identity=txt->ValueStr();
\r
163 txt=hnd2.FirstChild("MessageTrustLevel").FirstChild().ToText();
\r
166 messagetruststr=txt->ValueStr();
\r
167 if(messagetruststr!="")
\r
169 StringFunctions::Convert(messagetruststr,messagetrust);
\r
172 txt=hnd2.FirstChild("TrustListTrustLevel").FirstChild().ToText();
\r
175 trustlisttruststr=txt->ValueStr();
\r
176 if(trustlisttruststr!="")
\r
178 StringFunctions::Convert(trustlisttruststr,trustlisttrust);
\r
181 txt=hnd2.FirstChild("MessageTrustComment").FirstChild().ToText();
\r
184 messagetrustcomment=txt->ValueStr();
\r
186 txt=hnd2.FirstChild("TrustListTrustComment").FirstChild().ToText();
\r
189 trustlisttrustcomment=txt->ValueStr();
\r
192 if(identity!="" && messagetrust>=-1 && messagetrust<=100 && trustlisttrust>=-1 && trustlisttrust<=100)
\r
194 // check so we don't add the same identity multiple times from a trust list
\r
195 if(std::find(m_foundkeys.begin(),m_foundkeys.end(),identity)==m_foundkeys.end())
\r
197 m_foundkeys.push_back(identity);
\r
198 m_trust.push_back(trust(identity,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment));
\r
203 m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListXML::ParseXML malformed Trust in TrustList.xml");
\r
206 node=node->NextSibling("Trust");
\r