X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fextensiontrust.cpp;h=e0a7ad496494949ea6198d3587ec43c7559a1b12;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=6e49a930ea630f5cc594489e27fefd33e822577c;hpb=7ddb1aeb0b3dc7384597e75f7b3557f2d8f6d14c;p=fms.git diff --git a/src/nntp/extensiontrust.cpp b/src/nntp/extensiontrust.cpp index 6e49a93..e0a7ad4 100644 --- a/src/nntp/extensiontrust.cpp +++ b/src/nntp/extensiontrust.cpp @@ -5,12 +5,12 @@ #include #endif -TrustExtension::TrustExtension() +TrustExtension::TrustExtension(SQLite3DB::DB *db):IDatabase(db) { m_localidentityid=-1; } -TrustExtension::TrustExtension(const int &localidentityid) +TrustExtension::TrustExtension(SQLite3DB::DB *db, const int &localidentityid):IDatabase(db) { m_localidentityid=localidentityid; } @@ -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; + } +}