X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fmessageinserter.cpp;h=b4e1ce45a4bf076efd61f1585e113d8f63f15740;hp=3d5af9aa8e4a8ceab2ad6e93c058e84b8e530b47;hb=63376b2a82c3f6cdf2df56b1f134bd7df0aaab3a;hpb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0 diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index 3d5af9a..b4e1ce4 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -13,17 +13,29 @@ MessageInserter::MessageInserter(FCPv2 *fcp):IIndexInserter(fcp) void MessageInserter::CheckForNeededInsert() { + bool didinsert=false; // only do 1 insert at a time if(m_inserting.size()==0) { SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false';"); st.Step(); - if(st.RowReturned()) + while(st.RowReturned() && m_inserting.size()==0) { - std::string messageuuid; + std::string messageuuid=""; st.ResultText(0,messageuuid); - StartInsert(messageuuid); + + // make sure there are no uninserted files attached to this message + SQLite3DB::Statement st2=m_db->Prepare("SELECT FileInsertID FROM tblFileInserts WHERE Key IS NULL AND MessageUUID=?;"); + st2.Bind(0,messageuuid); + st2.Step(); + + if(st2.RowReturned()==false) + { + StartInsert(messageuuid); + } + + st.Step(); } } } @@ -59,6 +71,7 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) int localidentityid; int index; std::vector idparts; + StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[3],index); StringFunctions::Convert(idparts[2],localidentityid); @@ -92,6 +105,12 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) st2.Bind(1,xml.GetXML()); st2.Bind(2,idparts[1]); st2.Step(); + + //update file insert MessageUUID as well + st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;"); + st2.Bind(0,idparts[4]); + st2.Bind(1,idparts[1]); + st2.Step(); } RemoveFromInsertList(idparts[1]); @@ -145,9 +164,27 @@ void MessageInserter::StartInsert(const std::string &messageuuid) } StringFunctions::Convert(index,indexstr); + xmlfile.ParseXML(xml); + + // add file attachments to xml - must do this before we change UUID + st=m_db->Prepare("SELECT Key, Size FROM tblFileInserts WHERE MessageUUID=?;"); + st.Bind(0,xmlfile.GetMessageID()); + st.Step(); + while(st.RowReturned()) + { + std::string key=""; + int size; + + st.ResultText(0,key); + st.ResultInt(1,size); + + xmlfile.AddFileAttachment(key,size); + + st.Step(); + } + // recreate messageuuid in xml - UUID of message will not match entry in MessageInserts table until we successfully insert it // see HandlePutSuccessful - xmlfile.ParseXML(xml); // if we don't already have an @sskpart - add it if(xmlfile.GetMessageID().find("@")==std::string::npos) {