#include <xmem.h>\r
#endif\r
\r
-IdentityInserter::IdentityInserter()\r
+IdentityInserter::IdentityInserter(SQLite3DB::DB *db):IDatabase(db)\r
{\r
Initialize();\r
}\r
\r
-IdentityInserter::IdentityInserter(FCPv2 *fcp):IFCPConnected(fcp)\r
+IdentityInserter::IdentityInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp)\r
{\r
Initialize();\r
}\r
\r
}\r
\r
-const bool IdentityInserter::HandleMessage(FCPMessage &message)\r
+const bool IdentityInserter::HandleMessage(FCPv2::Message &message)\r
{\r
\r
if(message["Identifier"].find("IdentityInserter")==0)\r
\r
if(message.GetName()=="PutSuccessful")\r
{\r
- // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity.\r
- // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
- Poco::DateTime lastdate;\r
- int tzdiff=0;\r
- Poco::DateTimeParser::tryParse("%Y-%m-%d",idparts[4],lastdate,tzdiff);\r
-\r
- if(lastdate.day()==now.day())\r
+ \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
- m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+ // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity.\r
+ // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
+ Poco::DateTime lastdate;\r
+ int tzdiff=0;\r
+ Poco::DateTimeParser::tryParse("%Y-%m-%d",idparts[4],lastdate,tzdiff);\r
+ if(lastdate.day()==now.day())\r
+ {\r
+ m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+ }\r
+ else\r
+ {\r
+ m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+ }\r
+ m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+ m_log->debug("IdentityInserter::HandleMessage inserted Identity xml");\r
}\r
else\r
{\r
- m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+ m_log->trace("IdentityInserter::HandleMessage inserted editioned Identity xml");\r
}\r
- m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
- m_log->debug("IdentityInserter::HandleMessage inserted Identity xml");\r
return true;\r
}\r
\r
if(message.GetName()=="PutFailed")\r
{\r
- m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
- m_log->debug("IdentityInserter::HandleMessage failure inserting Identity xml. Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
- \r
- // if code 9 (collision), then insert index into inserted table\r
- if(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
- m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+ m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+ m_log->debug("IdentityInserter::HandleMessage failure inserting Identity xml. Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
+ \r
+ // if code 9 (collision), then insert index into inserted table\r
+ if(message["Code"]=="9")\r
+ {\r
+ m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ m_log->trace("IdentityInserter::HandleMessage PutFailed for editioned SSK error code "+message["Code"]+ " id "+message["Identifier"]);\r
}\r
\r
return true;\r
if(rs.Empty()==false)\r
{\r
IdentityXML idxml;\r
- FCPMessage mess;\r
+ FCPv2::Message mess;\r
Poco::DateTime now;\r
std::string messagebase;\r
std::string data;\r
}\r
StringFunctions::Convert(index,indexstr);\r
\r
- Option::Instance()->Get("MessageBase",messagebase);\r
+ Option option(m_db);\r
+ option.Get("MessageBase",messagebase);\r
\r
if(rs.GetField(0))\r
{\r
mess["Identifier"]="IdentityInserter|"+idstring+"|"+indexstr+"|"+mess["URI"];\r
mess["UploadFrom"]="direct";\r
mess["DataLength"]=datasizestr;\r
- m_fcp->SendMessage(mess);\r
- m_fcp->SendRaw(data.c_str(),data.size());\r
+ m_fcp->Send(mess);\r
+ m_fcp->Send(std::vector<char>(data.begin(),data.end()));\r
+\r
+ // test insert as editioned SSK\r
+ mess.Clear();\r
+ mess.SetName("ClientPut");\r
+ mess["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Identity-"+indexstr;\r
+ mess["Identifier"]="IdentityInserter|"+mess["URI"];\r
+ mess["UploadFrom"]="direct";\r
+ mess["DataLength"]=datasizestr;\r
+ m_fcp->Send(mess);\r
+ m_fcp->Send(std::vector<char>(data.begin(),data.end()));\r
\r
m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='true' WHERE LocalIdentityID="+idstring+";");\r
\r