X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistinserter.cpp;h=833b55610ee2295f5fff89192364733543c29761;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=e0d8957c3deafac5354e6e9a652c19fd9c4f0ea4;hpb=9a14c0d9f7f7c319e539583b93664953764e83b7;p=fms.git diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index e0d8957..833b556 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -29,13 +29,19 @@ void MessageListInserter::CheckForNeededInsert() now.SetToGMTime(); previous.SetToGMTime(); + // reset the last inserted xml doc to nothing if the day has changed + if(m_lastchecked.GetDay()!=now.GetDay()) + { + m_lastinsertedxml.clear(); + } + previous.Add(0,0,0,-m_daysbackward); // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert) sql="SELECT tblLocalIdentity.LocalIdentityID "; sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID "; sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) "; - sql+=";"; + sql+="GROUP BY tblLocalIdentity.LocalIdentityID;"; SQLite3DB::Statement st=m_db->Prepare(sql); st.Bind(0,previous.Format("%Y-%m-%d")); @@ -60,19 +66,27 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message) long index; StringFunctions::Split(message["Identifier"],"|",idparts); - StringFunctions::Convert(idparts[1],localidentityid); - StringFunctions::Convert(idparts[2],index); - if(message["Fatal"]=="true" || message["Code"]=="9") + // non USK + if(idparts[0]==m_fcpuniquename) { - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'false');"); - st.Bind(0,localidentityid); - st.Bind(1,idparts[4]); - st.Bind(2,index); - st.Step(); - } + StringFunctions::Convert(idparts[1],localidentityid); + StringFunctions::Convert(idparts[2],index); + + if(message["Fatal"]=="true" || message["Code"]=="9") + { + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'false');"); + st.Bind(0,localidentityid); + st.Bind(1,idparts[4]); + st.Bind(2,index); + st.Step(); + } - RemoveFromInsertList(localidentityid); + RemoveFromInsertList(localidentityid); + + // reset the last inserted xml doc to nothing so we will try to insert this one again + m_lastinsertedxml[localidentityid]=""; + } return true; @@ -86,29 +100,34 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) long index; StringFunctions::Split(message["Identifier"],"|",idparts); - StringFunctions::Convert(idparts[1],localidentityid); - StringFunctions::Convert(idparts[2],index); - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); - st.Bind(0,localidentityid); - st.Bind(1,idparts[4]); - st.Bind(2,index); - st.Step(); + // non USK + if(idparts[0]==m_fcpuniquename) + { + StringFunctions::Convert(idparts[1],localidentityid); + StringFunctions::Convert(idparts[2],index); - now.SetToGMTime(); - st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;"); - st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); - st.Bind(1,localidentityid); - st.Step(); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); + st.Bind(0,localidentityid); + st.Bind(1,idparts[4]); + st.Bind(2,index); + st.Step(); - // delete any record from tmpMessageListInsert - st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); - st.Bind(0,localidentityid); - st.Step(); + now.SetToGMTime(); + st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;"); + st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(1,localidentityid); + st.Step(); - RemoveFromInsertList(localidentityid); + // delete any record from tmpMessageListInsert + st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + RemoveFromInsertList(localidentityid); + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + } return true; } @@ -168,7 +187,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) st.Finalize(); - st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 100;"); + st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 200;"); SQLite3DB::Statement st2=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=?;"); st.Step(); while(st.RowReturned()) @@ -214,12 +233,12 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) } StringFunctions::Convert(index,indexstr); - // actually insert message xmlstr=mlxml.GetXML(); // only insert if the last message this identity inserted is different than this message if(m_lastinsertedxml[localidentityid]!=xmlstr) { + std::string targeturi=""; StringFunctions::Convert(xmlstr.size(),xmlsizestr); message.SetName("ClientPut"); @@ -230,9 +249,20 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) m_fcp->SendMessage(message); m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); - m_inserting.push_back(localidentityid); + message.Reset(); + message.SetName("ClientPutComplexDir"); + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/"; + message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"]; + message["DefaultName"]="MessageList.xml"; + message["Files.0.Name"]="MessageList.xml"; + message["Files.0.UploadFrom"]="direct"; + message["Files.0.DataLength"]=xmlsizestr; + m_fcp->SendMessage(message); + m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_inserting.push_back(localidentityid); m_lastinsertedxml[localidentityid]=xmlstr; + return true; } else