version 0.2.17
[fms.git] / src / freenet / messagelistinserter.cpp
index f598b51..833b556 100644 (file)
@@ -29,6 +29,12 @@ void MessageListInserter::CheckForNeededInsert()
                now.SetToGMTime();\r
                previous.SetToGMTime();\r
 \r
+               // reset the last inserted xml doc to nothing if the day has changed\r
+               if(m_lastchecked.GetDay()!=now.GetDay())\r
+               {\r
+                       m_lastinsertedxml.clear();\r
+               }\r
+\r
                previous.Add(0,0,0,-m_daysbackward);\r
 \r
                // 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)\r
@@ -60,19 +66,27 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message)
        long index;\r
 \r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
-       StringFunctions::Convert(idparts[1],localidentityid);\r
-       StringFunctions::Convert(idparts[2],index);\r
 \r
-       if(message["Fatal"]=="true" || message["Code"]=="9")\r
+       // non USK\r
+       if(idparts[0]==m_fcpuniquename)\r
        {\r
-               SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'false');");\r
-               st.Bind(0,localidentityid);\r
-               st.Bind(1,idparts[4]);\r
-               st.Bind(2,index);\r
-               st.Step();\r
-       }\r
+               StringFunctions::Convert(idparts[1],localidentityid);\r
+               StringFunctions::Convert(idparts[2],index);\r
 \r
-       RemoveFromInsertList(localidentityid);\r
+               if(message["Fatal"]=="true" || message["Code"]=="9")\r
+               {\r
+                       SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'false');");\r
+                       st.Bind(0,localidentityid);\r
+                       st.Bind(1,idparts[4]);\r
+                       st.Bind(2,index);\r
+                       st.Step();\r
+               }\r
+\r
+               RemoveFromInsertList(localidentityid);\r
+\r
+               // reset the last inserted xml doc to nothing so we will try to insert this one again\r
+               m_lastinsertedxml[localidentityid]="";\r
+       }\r
 \r
        return true;\r
 \r
@@ -86,29 +100,34 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message)
        long index;\r
 \r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
-       StringFunctions::Convert(idparts[1],localidentityid);\r
-       StringFunctions::Convert(idparts[2],index);\r
 \r
-       SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');");\r
-       st.Bind(0,localidentityid);\r
-       st.Bind(1,idparts[4]);\r
-       st.Bind(2,index);\r
-       st.Step();\r
+       // non USK\r
+       if(idparts[0]==m_fcpuniquename)\r
+       {\r
+               StringFunctions::Convert(idparts[1],localidentityid);\r
+               StringFunctions::Convert(idparts[2],index);\r
 \r
-       now.SetToGMTime();\r
-       st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;");\r
-       st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S"));\r
-       st.Bind(1,localidentityid);\r
-       st.Step();\r
+               SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageListInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');");\r
+               st.Bind(0,localidentityid);\r
+               st.Bind(1,idparts[4]);\r
+               st.Bind(2,index);\r
+               st.Step();\r
 \r
-       // delete any record from tmpMessageListInsert\r
-       st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
-       st.Bind(0,localidentityid);\r
-       st.Step();\r
+               now.SetToGMTime();\r
+               st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;");\r
+               st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S"));\r
+               st.Bind(1,localidentityid);\r
+               st.Step();\r
+\r
+               // delete any record from tmpMessageListInsert\r
+               st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
+               st.Bind(0,localidentityid);\r
+               st.Step();\r
 \r
-       RemoveFromInsertList(localidentityid);\r
+               RemoveFromInsertList(localidentityid);\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
+       }\r
 \r
        return true;\r
 }\r
@@ -230,23 +249,14 @@ const bool MessageListInserter::StartInsert(const long &localidentityid)
                m_fcp->SendMessage(message);\r
                m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size());\r
 \r
-               /*\r
-               // insert a USK redirect to the file we just inserted\r
-               targeturi=message["URI"];\r
                message.Reset();\r
-               message.SetName("ClientPut");\r
-               message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml";\r
-               message["Identifier"]=message["URI"];\r
-               message["UploadFrom"]="redirect";\r
-               message["TargetURI"]=targeturi;\r
-               m_fcp->SendMessage(message);\r
-               */\r
-               message.Reset();\r
-               message.SetName("ClientPut");\r
-               message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/MessageList.xml";\r
-               message["Identifier"]=message["URI"];\r
-               message["UploadFrom"]="direct";\r
-               message["DataLength"]=xmlsizestr;\r
+               message.SetName("ClientPutComplexDir");\r
+               message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/";\r
+               message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
+               message["DefaultName"]="MessageList.xml";\r
+               message["Files.0.Name"]="MessageList.xml";\r
+               message["Files.0.UploadFrom"]="direct";\r
+               message["Files.0.DataLength"]=xmlsizestr;\r
                m_fcp->SendMessage(message);\r
                m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size());\r
 \r