1 #include "../../include/nntp/extensiontrust.h"
\r
2 #include "../../include/stringfunctions.h"
\r
8 TrustExtension::TrustExtension()
\r
10 m_localidentityid=-1;
\r
13 TrustExtension::TrustExtension(const int &localidentityid)
\r
15 m_localidentityid=localidentityid;
\r
18 const int TrustExtension::GetIdentityID(const std::string &nntpname)
\r
20 std::vector<std::string> nameparts;
\r
21 StringFunctions::Split(nntpname,"@",nameparts);
\r
23 SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID, PublicKey FROM tblIdentity WHERE Name=? AND PublicKey IS NOT NULL AND PublicKey <> '' ;");
\r
24 st.Bind(0,nameparts[0]);
\r
27 while(st.RowReturned())
\r
30 std::vector<std::string> keyparts;
\r
31 std::string publickey="";
\r
33 st.ResultText(1,publickey);
\r
34 StringFunctions::SplitMultiple(publickey,"@,",keyparts);
\r
36 if(keyparts.size()>1)
\r
38 publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-","");
\r
39 if(nameparts[0]+"@"+publickey==nntpname)
\r
53 const bool TrustExtension::GetMessageTrust(const std::string &nntpname, int &trust)
\r
55 if(m_localidentityid>=0)
\r
57 int id=GetIdentityID(nntpname);
\r
60 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalMessageTrust FROM tblIdentityTrust WHERE LocalIdentityID=? AND IdentityID=?;");
\r
61 st.Bind(0,m_localidentityid);
\r
65 if(st.RowReturned())
\r
68 if(st.ResultNull(0)==false)
\r
91 const bool TrustExtension::GetTrustList(std::map<std::string,std::pair<int,int> > &trustlist)
\r
93 if(m_localidentityid>=0)
\r
95 SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.Name,tblIdentity.PublicKey FROM tblIdentityTrust INNER JOIN tblIdentity ON tblIdentityTrust.IdentityID=tblIdentity.IdentityID WHERE tblIdentityTrust.LocalIdentityID=? AND tblIdentity.Name IS NOT NULL AND tblIdentity.PublicKey IS NOT NULL AND tblIdentity.PublicKey <> '' ;");
\r
96 st.Bind(0,m_localidentityid);
\r
98 while(st.RowReturned())
\r
100 int messagetrust=-1;
\r
101 int trustlisttrust=-1;
\r
102 std::string name="";
\r
103 std::string publickey="";
\r
104 std::vector<std::string> keyparts;
\r
105 std::string nntpname="";
\r
107 if(st.ResultNull(0)==false)
\r
109 st.ResultInt(0,messagetrust);
\r
111 if(st.ResultNull(1)==false)
\r
113 st.ResultInt(1,trustlisttrust);
\r
115 st.ResultText(2,name);
\r
116 st.ResultText(3,publickey);
\r
118 StringFunctions::SplitMultiple(publickey,"@,",keyparts);
\r
119 if(keyparts.size()>1)
\r
121 publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-","");
\r
122 nntpname=name+"@"+publickey;
\r
125 trustlist[nntpname]=std::pair<int,int>(messagetrust,trustlisttrust);
\r
137 const bool TrustExtension::GetTrustListTrust(const std::string &nntpname, int &trust)
\r
139 if(m_localidentityid>=0)
\r
141 int id=GetIdentityID(nntpname);
\r
144 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalTrustListTrust FROM tblIdentityTrust WHERE LocalIdentityID=? AND IdentityID=?;");
\r
145 st.Bind(0,m_localidentityid);
\r
149 if(st.RowReturned())
\r
152 if(st.ResultNull(0)==false)
\r
154 st.ResultInt(0,tr);
\r
175 const bool TrustExtension::SetMessageTrust(const std::string &nntpname, const int trust)
\r
177 if(m_localidentityid>=0 && trust>=-1 && trust<=100)
\r
179 int id=GetIdentityID(nntpname);
\r
182 SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET LocalMessageTrust=? WHERE LocalIdentityID=? AND IdentityID=?;");
\r
191 st.Bind(1,m_localidentityid);
\r
208 const bool TrustExtension::SetTrustListTrust(const std::string &nntpname, const int trust)
\r
210 if(m_localidentityid>=0 && trust>=-1 && trust<=100)
\r
212 int id=GetIdentityID(nntpname);
\r
215 SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET LocalTrustListTrust=? WHERE LocalIdentityID=? AND IdentityID=?;");
\r
224 st.Bind(1,m_localidentityid);
\r