X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistinserter.cpp;h=833b55610ee2295f5fff89192364733543c29761;hp=f598b513660d66593b69cb2bd4d00937429b759d;hb=6836fbb5db8464f56e682989996b2210b14231d0;hpb=7ddb1aeb0b3dc7384597e75f7b3557f2d8f6d14c diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index f598b51..833b556 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -29,6 +29,12 @@ 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) @@ -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); - RemoveFromInsertList(localidentityid); + 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); + + // 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(); + + // delete any record from tmpMessageListInsert + st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); - RemoveFromInsertList(localidentityid); + RemoveFromInsertList(localidentityid); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + } return true; } @@ -230,23 +249,14 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) m_fcp->SendMessage(message); m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); - /* - // insert a USK redirect to the file we just inserted - targeturi=message["URI"]; message.Reset(); - message.SetName("ClientPut"); - message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml"; - message["Identifier"]=message["URI"]; - message["UploadFrom"]="redirect"; - message["TargetURI"]=targeturi; - m_fcp->SendMessage(message); - */ - message.Reset(); - message.SetName("ClientPut"); - message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml"; - message["Identifier"]=message["URI"]; - message["UploadFrom"]="direct"; - message["DataLength"]=xmlsizestr; + 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());