X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fextensiontrust.cpp;h=eb0a765ba560e21d34fdc090abd6e9470ceed394;hb=3f6f19146f015fa8d2c89f1e72cd467dbc4115aa;hp=6e49a930ea630f5cc594489e27fefd33e822577c;hpb=7ddb1aeb0b3dc7384597e75f7b3557f2d8f6d14c;p=fms.git diff --git a/src/nntp/extensiontrust.cpp b/src/nntp/extensiontrust.cpp index 6e49a93..eb0a765 100644 --- a/src/nntp/extensiontrust.cpp +++ b/src/nntp/extensiontrust.cpp @@ -35,8 +35,7 @@ const int TrustExtension::GetIdentityID(const std::string &nntpname) if(keyparts.size()>1) { - publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-",""); - if(nameparts[0]+"@"+publickey==nntpname) + if(nameparts[0]+"@"+keyparts[1]==nntpname) { st.ResultInt(0,id); return id; @@ -88,17 +87,95 @@ const bool TrustExtension::GetMessageTrust(const std::string &nntpname, int &tru } } -const bool TrustExtension::GetTrustList(std::map > &trustlist) +const bool TrustExtension::GetPeerMessageTrust(const std::string &nntpname, int &trust) { if(m_localidentityid>=0) { - 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 <> '' ;"); + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT PeerMessageTrust FROM tblIdentity WHERE IdentityID=?;"); + st.Bind(0,id); + st.Step(); + + if(st.RowReturned()) + { + int tr=-1; + if(st.ResultNull(0)==false) + { + st.ResultInt(0,tr); + } + trust=tr; + } + else + { + trust=-1; + } + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +const bool TrustExtension::GetPeerTrustListTrust(const std::string &nntpname, int &trust) +{ + if(m_localidentityid>=0) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT PeerTrustListTrust FROM tblIdentity WHERE IdentityID=?;"); + st.Bind(0,id); + st.Step(); + + if(st.RowReturned()) + { + int tr=-1; + if(st.ResultNull(0)==false) + { + st.ResultInt(0,tr); + } + trust=tr; + } + else + { + trust=-1; + } + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +const bool TrustExtension::GetTrustList(std::map &trustlist) +{ + if(m_localidentityid>=0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.Name,tblIdentity.PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,tblIdentity.PeerMessageTrust,tblIdentity.PeerTrustListTrust 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 <> '' ;"); st.Bind(0,m_localidentityid); st.Step(); while(st.RowReturned()) { int messagetrust=-1; int trustlisttrust=-1; + int peermessagetrust=-1; + int peertrustlisttrust=-1; + std::string messagetrustcomment=""; + std::string trustlisttrustcomment=""; std::string name=""; std::string publickey=""; std::vector keyparts; @@ -114,15 +191,24 @@ const bool TrustExtension::GetTrustList(std::map } st.ResultText(2,name); st.ResultText(3,publickey); + st.ResultText(4,messagetrustcomment); + st.ResultText(5,trustlisttrustcomment); + if(st.ResultNull(6)==false) + { + st.ResultInt(6,peermessagetrust); + } + if(st.ResultNull(7)==false) + { + st.ResultInt(7,peertrustlisttrust); + } StringFunctions::SplitMultiple(publickey,"@,",keyparts); if(keyparts.size()>1) { - publickey=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"~",""),"-",""); - nntpname=name+"@"+publickey; + nntpname=name+"@"+keyparts[1]; } - trustlist[nntpname]=std::pair(messagetrust,trustlisttrust); + trustlist[nntpname]=trust(messagetrust,peermessagetrust,messagetrustcomment,trustlisttrust,peertrustlisttrust,trustlisttrustcomment); st.Step(); } @@ -205,6 +291,39 @@ const bool TrustExtension::SetMessageTrust(const std::string &nntpname, const in } } +const bool TrustExtension::SetMessageTrustComment(const std::string &nntpname, const std::string &comment) +{ + if(m_localidentityid>=0) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET MessageTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;"); + if(comment=="") + { + st.Bind(0); + } + else + { + st.Bind(0,comment); + } + st.Bind(1,m_localidentityid); + st.Bind(2,id); + st.Step(); + + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + const bool TrustExtension::SetTrustListTrust(const std::string &nntpname, const int trust) { if(m_localidentityid>=0 && trust>=-1 && trust<=100) @@ -237,3 +356,36 @@ const bool TrustExtension::SetTrustListTrust(const std::string &nntpname, const return false; } } + +const bool TrustExtension::SetTrustListTrustComment(const std::string &nntpname, const std::string &comment) +{ + if(m_localidentityid>=0) + { + int id=GetIdentityID(nntpname); + if(id>=0) + { + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblIdentityTrust SET TrustListTrustComment=? WHERE LocalIdentityID=? AND IdentityID=?;"); + if(comment=="") + { + st.Bind(0); + } + else + { + st.Bind(0,comment); + } + st.Bind(1,m_localidentityid); + st.Bind(2,id); + st.Step(); + + return true; + } + else + { + return false; + } + } + else + { + return false; + } +}