void MessageListInserter::CheckForNeededInsert()\r
{\r
\r
- // more than 10 minutes trying to insert - restart\r
- if(m_inserting.size()>0 && (m_laststartedinsert+Poco::Timespan(0,0,10,0,0)<=Poco::DateTime()))\r
+ // more than 15 minutes trying to insert - restart\r
+ if(m_inserting.size()>0 && (m_laststartedinsert+Poco::Timespan(0,0,15,0,0)<=Poco::DateTime()))\r
{\r
- m_log->error("MessageListInserter::CheckForNeededInsert more than 10 minutes have passed without success/failure. Clearing inserts.");\r
+ m_log->error("MessageListInserter::CheckForNeededInsert more than 15 minutes have passed without success/failure. Clearing inserts.");\r
+ m_lastinsertedxml[m_inserting[0]]="";\r
m_inserting.clear();\r
}\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
sql="SELECT tblLocalIdentity.LocalIdentityID ";\r
sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID ";\r
- sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) ";\r
+ sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) AND tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' ";\r
sql+="GROUP BY tblLocalIdentity.LocalIdentityID ";\r
sql+="ORDER BY tblLocalIdentity.LastInsertedMessageList;";\r
\r
const bool MessageListInserter::HandlePutFailed(FCPv2::Message &message)\r
{\r
std::vector<std::string> idparts;\r
- long localidentityid;\r
- long index;\r
+ //std::vector<std::string> uriparts;\r
+ long localidentityid=0;\r
+ long index=0;\r
\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
+ //StringFunctions::Split(message["URI"],"/",uriparts);\r
+\r
+ StringFunctions::Convert(idparts[1],localidentityid);\r
+ //StringFunctions::Convert(uriparts[2],index); - URI won't be set for USKs\r
\r
- // non USK\r
- if(idparts[0]==m_fcpuniquename)\r
+ if(message["Fatal"]=="true" || message["Code"]=="9")\r
{\r
- StringFunctions::Convert(idparts[1],localidentityid);\r
- StringFunctions::Convert(idparts[2],index);\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[2]);\r
+ st.Bind(2,index);\r
+ st.Step();\r
+ }\r
\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
+ RemoveFromInsertList(localidentityid);\r
\r
- RemoveFromInsertList(localidentityid);\r
+ // reset the last inserted xml doc to nothing so we will try to insert this one again\r
+ m_lastinsertedxml[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
- else\r
- {\r
- m_log->debug("MessageListInserter::HandlePutFailed "+message["Identifier"]);\r
- }\r
+ m_log->trace("MessageListInserter::HandlePutFailed insert failed for "+message["Identifier"]);\r
\r
return true;\r
\r
{\r
Poco::DateTime now;\r
std::vector<std::string> idparts;\r
+ std::vector<std::string> uriparts;\r
long localidentityid;\r
long index;\r
\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
+ StringFunctions::Split(message["URI"],"/",uriparts);\r
\r
- // non USK\r
- if(idparts[0]==m_fcpuniquename)\r
- {\r
- StringFunctions::Convert(idparts[1],localidentityid);\r
- StringFunctions::Convert(idparts[2],index);\r
+ StringFunctions::Convert(idparts[1],localidentityid);\r
+ StringFunctions::Convert(uriparts[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
+ 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[2]);\r
+ st.Bind(2,index);\r
+ st.Step();\r
\r
- now=Poco::Timestamp();\r
- st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;");\r
- st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
- st.Bind(1,localidentityid);\r
- st.Step();\r
+ now=Poco::Timestamp();\r
+ st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;");\r
+ st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
+ st.Bind(1,localidentityid);\r
+ st.Step();\r
\r
- // delete only a single record from tmpMessageListInsert\r
- st=m_db->Prepare("SELECT MessageListInsertID FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
- st.Bind(0,localidentityid);\r
- st.Step();\r
- if(st.RowReturned())\r
- {\r
- int id=-1;\r
- st.ResultInt(0,id);\r
+ // delete only a single record from tmpMessageListInsert\r
+ st=m_db->Prepare("SELECT MessageListInsertID FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
+ st.Bind(0,localidentityid);\r
+ st.Step();\r
+ if(st.RowReturned())\r
+ {\r
+ int id=-1;\r
+ st.ResultInt(0,id);\r
\r
- st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE MessageListInsertID=?;");\r
- st.Bind(0,id);\r
- st.Step();\r
- }\r
+ st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE MessageListInsertID=?;");\r
+ st.Bind(0,id);\r
+ st.Step();\r
+ }\r
\r
- RemoveFromInsertList(localidentityid);\r
+ RemoveFromInsertList(localidentityid);\r
\r
- m_log->debug("MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
- }\r
- else\r
- {\r
- m_log->debug("MessageListInserter::HandlePutSuccessful inserted USK MessageList "+message["Identifier"]);\r
- }\r
+ m_log->debug("MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
\r
return true;\r
}\r
// only insert if the last message this identity inserted is different than this message\r
if(m_lastinsertedxml[localidentityid]!=xmlstr)\r
{\r
- std::string targeturi="";\r
StringFunctions::Convert(xmlstr.size(),xmlsizestr);\r
\r
+ /*\r
message.SetName("ClientPut");\r
message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|MessageList|"+indexstr+".xml";\r
message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"];\r
message["DataLength"]=xmlsizestr;\r
m_fcp->Send(message);\r
m_fcp->Send(std::vector<char>(xmlstr.begin(),xmlstr.end()));\r
-\r
message.Clear();\r
+ */\r
+\r
message.SetName("ClientPutComplexDir");\r
message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|MessageList/0/";\r
- message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
+ message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|"+message["URI"];\r
message["DefaultName"]="MessageList.xml";\r
message["Files.0.Name"]="MessageList.xml";\r
message["Files.0.UploadFrom"]="direct";\r
\r
m_laststartedinsert=Poco::DateTime();\r
\r
+ m_log->trace("MessageListInserter::StartInsert started insert of "+message["Identifier"]);\r
+\r
return true;\r
}\r
else\r