version 0.3.31
[fms.git] / src / freenet / messageinserter.cpp
index f3aab00..a378ee1 100644 (file)
@@ -51,23 +51,34 @@ const bool MessageInserter::HandlePutFailed(FCPv2::Message &message)
        int index;\r
        int localidentityid;\r
        std::vector<std::string> idparts;\r
-       StringFunctions::Split(message["Identifier"],"|",idparts);\r
-       StringFunctions::Convert(idparts[2],localidentityid);\r
-       StringFunctions::Convert(idparts[3],index);\r
 \r
-       // fatal put - or data exists - insert bogus index into database so we'll try to insert this message again\r
-       if(message["Fatal"]=="true" || message["Code"]=="9")\r
+       // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now\r
+       if(message["Identifier"].find(".xml")!=std::string::npos)\r
        {\r
-               SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');");\r
-               st.Bind(0,localidentityid);\r
-               st.Bind(1,idparts[6]);\r
-               st.Bind(2,index);\r
-               st.Step();\r
-       }\r
 \r
-       m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]);\r
+               StringFunctions::Split(message["Identifier"],"|",idparts);\r
+               StringFunctions::Convert(idparts[2],localidentityid);\r
+               StringFunctions::Convert(idparts[3],index);\r
 \r
-       RemoveFromInsertList(idparts[1]);\r
+               // fatal put - or data exists - insert bogus index into database so we'll try to insert this message again\r
+               if(message["Fatal"]=="true" || message["Code"]=="9")\r
+               {\r
+                       SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');");\r
+                       st.Bind(0,localidentityid);\r
+                       st.Bind(1,idparts[6]);\r
+                       st.Bind(2,index);\r
+                       st.Step();\r
+               }\r
+\r
+               m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]);\r
+\r
+               RemoveFromInsertList(idparts[1]);\r
+\r
+       }\r
+       else\r
+       {\r
+               m_log->trace("MessageInserter::HandlePutFailed for editioned SSK error code "+message["Code"]+ " id "+message["Identifier"]);\r
+       }\r
 \r
        return true;\r
 }\r
@@ -80,50 +91,60 @@ const bool MessageInserter::HandlePutSuccessful(FCPv2::Message &message)
        int index;\r
        std::vector<std::string> idparts;\r
 \r
-       StringFunctions::Split(message["Identifier"],"|",idparts);\r
-       StringFunctions::Convert(idparts[3],index);\r
-       StringFunctions::Convert(idparts[2],localidentityid);\r
+       // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now\r
+       if(message["Identifier"].find(".xml")!=std::string::npos)\r
+       {\r
 \r
-       SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;");\r
-       st.Bind(0,idparts[6]);\r
-       st.Bind(1,index);\r
-       st.Bind(2,idparts[1]);\r
-       st.Step();\r
+               StringFunctions::Split(message["Identifier"],"|",idparts);\r
+               StringFunctions::Convert(idparts[3],index);\r
+               StringFunctions::Convert(idparts[2],localidentityid);\r
 \r
-       // insert record into temp table so MessageList will be inserted ASAP\r
-       date=Poco::Timestamp();\r
-       st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);");\r
-       st.Bind(0,localidentityid);\r
-       st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
-       st.Step();\r
+               SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;");\r
+               st.Bind(0,idparts[6]);\r
+               st.Bind(1,index);\r
+               st.Bind(2,idparts[1]);\r
+               st.Step();\r
 \r
-       // update the messageuuid to the real messageuuid\r
-       st=m_db->Prepare("SELECT MessageXML FROM tblMessageInserts WHERE MessageUUID=?;");\r
-       st.Bind(0,idparts[1]);\r
-       st.Step();\r
-       if(st.RowReturned())\r
-       {\r
-               std::string xmldata="";\r
-               st.ResultText(0,xmldata);\r
-               xml.ParseXML(xmldata);\r
-               xml.SetMessageID(idparts[4]);\r
-\r
-               SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblMessageInserts SET MessageUUID=?, MessageXML=? WHERE MessageUUID=?;");\r
-               st2.Bind(0,idparts[4]);\r
-               st2.Bind(1,xml.GetXML());\r
-               st2.Bind(2,idparts[1]);\r
-               st2.Step();\r
-\r
-               //update file insert MessageUUID as well\r
-               st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;");\r
-               st2.Bind(0,idparts[4]);\r
-               st2.Bind(1,idparts[1]);\r
-               st2.Step();\r
-       }\r
+               // insert record into temp table so MessageList will be inserted ASAP\r
+               date=Poco::Timestamp();\r
+               st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);");\r
+               st.Bind(0,localidentityid);\r
+               st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
+               st.Step();\r
+\r
+               // update the messageuuid to the real messageuuid\r
+               st=m_db->Prepare("SELECT MessageXML FROM tblMessageInserts WHERE MessageUUID=?;");\r
+               st.Bind(0,idparts[1]);\r
+               st.Step();\r
+               if(st.RowReturned())\r
+               {\r
+                       std::string xmldata="";\r
+                       st.ResultText(0,xmldata);\r
+                       xml.ParseXML(xmldata);\r
+                       xml.SetMessageID(idparts[4]);\r
+\r
+                       SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblMessageInserts SET MessageUUID=?, MessageXML=? WHERE MessageUUID=?;");\r
+                       st2.Bind(0,idparts[4]);\r
+                       st2.Bind(1,xml.GetXML());\r
+                       st2.Bind(2,idparts[1]);\r
+                       st2.Step();\r
+\r
+                       //update file insert MessageUUID as well\r
+                       st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;");\r
+                       st2.Bind(0,idparts[4]);\r
+                       st2.Bind(1,idparts[1]);\r
+                       st2.Step();\r
+               }\r
+\r
+               RemoveFromInsertList(idparts[1]);\r
 \r
-       RemoveFromInsertList(idparts[1]);\r
+               m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]);\r
 \r
-       m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]);\r
+       }\r
+       else\r
+       {\r
+               m_log->debug("MessageInserter::HandlePutSuccessful for editioned SSK "+message["Identifier"]);\r
+       }\r
 \r
        return true;\r
 }\r
@@ -211,6 +232,16 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid)
                m_fcp->Send(message);\r
                m_fcp->Send(std::vector<char>(xml.begin(),xml.end()));\r
 \r
+               // test insert as editioned SSK\r
+               message.Clear();\r
+               message.SetName("ClientPut");\r
+               message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Message|-"+indexstr;\r
+               message["Identifier"]=m_fcpuniquename+"|"+message["URI"];\r
+               message["UploadFrom"]="direct";\r
+               message["DataLength"]=xmlsizestr;\r
+               m_fcp->Send(message);\r
+               m_fcp->Send(std::vector<char>(xml.begin(),xml.end()));\r
+\r
                m_inserting.push_back(messageuuid);\r
 \r
                m_log->debug("MessageInserter::StartInsert started message insert "+message["URI"]);\r