version 0.2.7
[fms.git] / src / freenet / trustlistinserter.cpp
index 5f2fbb8..8962d5e 100644 (file)
@@ -136,21 +136,45 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
        int index;\r
        std::string indexstr;\r
        std::string localidentityidstr;\r
+       std::string messagetrustcomment="";\r
+       std::string trustlisttrustcomment="";\r
 \r
        now.SetToGMTime();\r
        date.SetToGMTime();\r
 \r
+       // insert all identities not in trust list already\r
+       m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);");\r
+\r
        // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities\r
        date.Add(0,0,0,-20);    // identities seen in last 20 days\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
+       //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
+       // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list.\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, tblIdentityTrust.LocalMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentityTrust.MessageTrustComment, tblIdentityTrust.TrustListTrustComment FROM tblIdentity INNER JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=? AND tblIdentityTrust.LocalIdentityID=? ORDER BY PublicKey;");\r
        st.Bind(0,date.Format("%Y-%m-%d"));\r
+       st.Bind(1,localidentityid);\r
        st.Step();\r
        while(st.RowReturned())\r
        {\r
                st.ResultText(0,publickey);\r
-               st.ResultInt(1,messagetrust);\r
-               st.ResultInt(2,trustlisttrust);\r
-               xml.AddTrust(publickey,messagetrust,trustlisttrust);\r
+               if(st.ResultNull(1)==false)\r
+               {\r
+                       st.ResultInt(1,messagetrust);\r
+               }\r
+               else\r
+               {\r
+                       messagetrust=-1;\r
+               }\r
+               if(st.ResultNull(2)==false)\r
+               {\r
+                       st.ResultInt(2,trustlisttrust);\r
+               }\r
+               else\r
+               {\r
+                       trustlisttrust=-1;\r
+               }\r
+               st.ResultText(3,messagetrustcomment);\r
+               st.ResultText(4,trustlisttrustcomment);\r
+               xml.AddTrust(publickey,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment);\r
                st.Step();\r
        }\r
 \r