version 0.3.29
[fms.git] / src / freenet / introductionpuzzleinserter.cpp
index 60f7bb6..000d973 100644 (file)
        #include <xmem.h>\r
 #endif\r
 \r
-IntroductionPuzzleInserter::IntroductionPuzzleInserter():IIndexInserter<long>()\r
+IntroductionPuzzleInserter::IntroductionPuzzleInserter(SQLite3DB::DB *db):IIndexInserter<long>(db)\r
 {\r
        Initialize();\r
 }\r
 \r
-IntroductionPuzzleInserter::IntroductionPuzzleInserter(FCPv2 *fcp):IIndexInserter<long>(fcp)\r
+IntroductionPuzzleInserter::IntroductionPuzzleInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexInserter<long>(db,fcp)\r
 {\r
        Initialize();\r
 }\r
@@ -87,8 +87,7 @@ void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::
        }\r
        m_log->trace("IntroductionPuzzleInserter::GenerateCaptcha using alternate captcha generator");\r
 #else\r
-       SimpleCaptcha captcha;\r
-       cap=&captcha;\r
+       cap=new SimpleCaptcha();\r
 #endif\r
        std::vector<unsigned char> puzzle;\r
        std::vector<unsigned char> puzzlesolution;\r
@@ -107,7 +106,7 @@ void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::
 \r
 }\r
 \r
-const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message)\r
+const bool IntroductionPuzzleInserter::HandlePutFailed(FCPv2::Message &message)\r
 {\r
        SQLite3DB::Statement st;\r
        std::vector<std::string> idparts;\r
@@ -133,7 +132,7 @@ const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message)
        return true;\r
 }\r
 \r
-const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message)\r
+const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPv2::Message &message)\r
 {\r
        Poco::DateTime now;\r
        SQLite3DB::Statement st;\r
@@ -179,18 +178,18 @@ void IntroductionPuzzleInserter::Initialize()
 const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)\r
 {\r
        Poco::DateTime now;\r
-       std::string idstring;\r
+       std::string idstring="";\r
        long index=0;\r
-       std::string indexstr;\r
+       std::string indexstr="";\r
        Poco::UUIDGenerator uuidgen;\r
        Poco::UUID uuid;\r
-       std::string messagebase;\r
+       std::string messagebase="";\r
        IntroductionPuzzleXML xml;\r
-       std::string encodedpuzzle;\r
-       std::string solutionstring;\r
-       FCPMessage message;\r
-       std::string xmldata;\r
-       std::string xmldatasizestr;\r
+       std::string encodedpuzzle="";\r
+       std::string solutionstring="";\r
+       FCPv2::Message message;\r
+       std::string xmldata="";\r
+       std::string xmldatasizestr="";\r
        std::string privatekey="";\r
        std::string publickey="";\r
        std::string keypart="";\r
@@ -225,9 +224,15 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
                        }\r
                }\r
 \r
-               Option::Instance()->Get("MessageBase",messagebase);\r
+               Option option(m_db);\r
+               option.Get("MessageBase",messagebase);\r
 \r
                GenerateCaptcha(encodedpuzzle,solutionstring);\r
+               if(encodedpuzzle.size()==0)\r
+               {\r
+                       m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create introduction puzzle");\r
+                       return false;\r
+               }\r
 \r
                try\r
                {\r
@@ -253,11 +258,11 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
                message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
                message["UploadFrom"]="direct";\r
                message["DataLength"]=xmldatasizestr;\r
-               m_fcp->SendMessage(message);\r
-               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+               m_fcp->Send(message);\r
+               m_fcp->Send(std::vector<char>(xmldata.begin(),xmldata.end()));\r
 \r
                // insert to USK\r
-               message.Reset();\r
+               message.Clear();\r
                message.SetName("ClientPutComplexDir");\r
                message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
                message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
@@ -265,8 +270,8 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
                message["Files.0.Name"]="IntroductionPuzzle.xml";\r
                message["Files.0.UplaodFrom"]="direct";\r
                message["Files.0.DataLength"]=xmldatasizestr;\r
-               m_fcp->SendMessage(message);\r
-               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+               m_fcp->Send(message);\r
+               m_fcp->Send(std::vector<char>(xmldata.begin(),xmldata.end()));\r
 \r
                m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
 \r