From 07319f767b4c4f0e06e9957f217d5107b196617b Mon Sep 17 00:00:00 2001 From: SomeDude Date: Fri, 18 Jul 2008 14:33:00 +0200 Subject: [PATCH] version 0.3.9 --- CMakeLists.txt | 1 + include/global.h | 2 +- src/charsetconverter.cpp | 2 +- src/dbsetup.cpp | 7 -- src/fmsapp.cpp | 8 ++ src/freenet/introductionpuzzleinserter.cpp | 115 +++++++++++++++-------------- src/freenet/siteinserter.cpp | 6 +- src/freenet/trustlistrequester.cpp | 45 +++++++++-- src/http/ipagehandler.cpp | 5 +- src/http/pages/homepage.cpp | 2 +- src/http/pages/optionspage.cpp | 2 +- 11 files changed, 119 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db5f4f4..ebd70aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,7 @@ FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s) IF(POCO_FOUNDATION_LIBRARY) TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY}) + ADD_DEFINITIONS(-DPOCO_HAVE_IPv6) IF(WIN32) ADD_DEFINITIONS(-DPOCO_STATIC) ENDIF(WIN32) diff --git a/include/global.h b/include/global.h index 8b4feab..de4e04b 100644 --- a/include/global.h +++ b/include/global.h @@ -7,7 +7,7 @@ #define VERSION_MAJOR "0" #define VERSION_MINOR "3" -#define VERSION_RELEASE "8" +#define VERSION_RELEASE "9" #define FMS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_RELEASE typedef Poco::ScopedLock Guard; diff --git a/src/charsetconverter.cpp b/src/charsetconverter.cpp index 9e4ff6f..f49213e 100644 --- a/src/charsetconverter.cpp +++ b/src/charsetconverter.cpp @@ -49,7 +49,7 @@ const bool CharsetConverter::Convert(const std::string &input, std::string &outp { std::vector invec(input.begin(),input.end()); std::vector outvec(invec.size()*4,0); -#if defined(_WIN32) //|| defined(__APPLE__) || defined(__DARWIN__) +#if defined(_WIN32) || defined(__FreeBSD__)//|| defined(__APPLE__) || defined(__DARWIN__) const char *inptr=&invec[0]; #else char *inptr=&invec[0]; diff --git a/src/dbsetup.cpp b/src/dbsetup.cpp index 68ee676..e6bdcf6 100644 --- a/src/dbsetup.cpp +++ b/src/dbsetup.cpp @@ -17,13 +17,6 @@ void SetupDB() db->Open("fms.db3"); db->SetBusyTimeout(20000); // set timeout to 20 seconds - tempval=""; - Option::Instance()->Get("VacuumOnStartup",tempval); - if(tempval=="true") - { - db->Execute("VACUUM;"); - } - db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ Major INTEGER,\ Minor INTEGER\ diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index ebebe4a..8a462e2 100644 --- a/src/fmsapp.cpp +++ b/src/fmsapp.cpp @@ -177,6 +177,14 @@ int FMSApp::main(const std::vector &args) { logger().information("FMS startup v"FMS_VERSION); + std::string tempval=""; + Option::Instance()->Get("VacuumOnStartup",tempval); + if(tempval=="true") + { + logger().information("VACUUMing database"); + SQLite3DB::DB::Instance()->Execute("VACUUM;"); + } + StartThreads(); if(isInteractive()==true) diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index 409a0f7..1fa13c0 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -173,70 +173,77 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) } StringFunctions::Convert(index,indexstr); - SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); - if(rs2.Empty()==false && rs2.GetField(0)!=NULL) + if(index<50) { - privatekey=rs2.GetField(0); - if(rs2.GetField(1)) + SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + if(rs2.Empty()==false && rs2.GetField(0)!=NULL) { - publickey=rs2.GetField(1); - } - if(publickey.size()>=50) - { - // remove - and ~ - keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + privatekey=rs2.GetField(0); + if(rs2.GetField(1)) + { + publickey=rs2.GetField(1); + } + if(publickey.size()>=50) + { + // remove - and ~ + keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + } } - } - Option::Instance()->Get("MessageBase",messagebase); + Option::Instance()->Get("MessageBase",messagebase); - GenerateCaptcha(encodedpuzzle,solutionstring); + GenerateCaptcha(encodedpuzzle,solutionstring); - try - { - uuid=uuidgen.createRandom(); + try + { + uuid=uuidgen.createRandom(); + } + catch(...) + { + m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID"); + } + + xml.SetType("captcha"); + std::string uuidstr=uuid.toString(); + StringFunctions::UpperCase(uuidstr,uuidstr); + xml.SetUUID(uuidstr+"@"+keypart); + xml.SetPuzzleData(encodedpuzzle); + xml.SetMimeType("image/bmp"); + + xmldata=xml.GetXML(); + StringFunctions::Convert(xmldata.size(),xmldatasizestr); + + message.SetName("ClientPut"); + message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml"; + message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"]; + message["UploadFrom"]="direct"; + message["DataLength"]=xmldatasizestr; + m_fcp->SendMessage(message); + m_fcp->SendRaw(xmldata.c_str(),xmldata.size()); + + // insert to USK + message.Reset(); + message.SetName("ClientPutComplexDir"); + message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/"; + message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"]; + message["DefaultName"]="IntroductionPuzzle.xml"; + message["Files.0.Name"]="IntroductionPuzzle.xml"; + message["Files.0.UplaodFrom"]="direct"; + message["Files.0.DataLength"]=xmldatasizestr; + m_fcp->SendMessage(message); + m_fcp->SendRaw(xmldata.c_str(),xmldata.size()); + + m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');"); + + m_inserting.push_back(localidentityid); + + m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring); } - catch(...) + else { - m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID"); + m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring); } - xml.SetType("captcha"); - std::string uuidstr=uuid.toString(); - StringFunctions::UpperCase(uuidstr,uuidstr); - xml.SetUUID(uuidstr+"@"+keypart); - xml.SetPuzzleData(encodedpuzzle); - xml.SetMimeType("image/bmp"); - - xmldata=xml.GetXML(); - StringFunctions::Convert(xmldata.size(),xmldatasizestr); - - message.SetName("ClientPut"); - message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml"; - message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"]; - message["UploadFrom"]="direct"; - message["DataLength"]=xmldatasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmldata.c_str(),xmldata.size()); - - // insert to USK - message.Reset(); - message.SetName("ClientPutComplexDir"); - message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/"; - message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"]; - message["DefaultName"]="IntroductionPuzzle.xml"; - message["Files.0.Name"]="IntroductionPuzzle.xml"; - message["Files.0.UplaodFrom"]="direct"; - message["Files.0.DataLength"]=xmldatasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmldata.c_str(),xmldata.size()); - - m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');"); - - m_inserting.push_back(localidentityid); - - m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring); - return true; } diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index 77da44a..02b5a73 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -166,10 +166,10 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey uskkey=key; filename=name+"-template.htm"; - FILE *infile=fopen(filename.c_str(),"r+b"); + FILE *infile=fopen(filename.c_str(),"rb"); if(!infile) { - infile=fopen("site-template.htm","r+b"); + infile=fopen("site-template.htm","rb"); } if(infile) { @@ -205,7 +205,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey // get extra files that the user wants to add to the Freesite filename=name+"-files.txt"; - infile=fopen(filename.c_str(),"r+b"); + infile=fopen(filename.c_str(),"rb"); if(infile) { std::vector files; diff --git a/src/freenet/trustlistrequester.cpp b/src/freenet/trustlistrequester.cpp index 668cdb9..d7dc27b 100644 --- a/src/freenet/trustlistrequester.cpp +++ b/src/freenet/trustlistrequester.cpp @@ -30,6 +30,8 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) TrustListXML xml; long identityid; long index; + int insertcount=0; + int dayinsertcount=0; StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(message["DataLength"],datalength); @@ -52,6 +54,22 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) data.resize(datalength); m_fcp->ReceiveRaw(&data[0],datalength); + // get count of identities added in last 24 hours + st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE DateAdded>=?;"); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); + st.Step(); + if(st.RowReturned()) + { + if(st.ResultNull(0)==false) + { + st.ResultInt(0,dayinsertcount); + } + } + else + { + m_log->error("TrustListRequester::HandleAllData couldn't get count of identities added in last 24 hours"); + } + // parse file into xml and update the database if(xml.ParseXML(std::string(data.begin(),data.end()))==true) { @@ -98,13 +116,17 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) st.Step(); if(st.RowReturned()==false) { - idinsert.Bind(0,identity); - idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); - idinsert.Bind(2,"trust list of "+publisherid); - idinsert.Step(true); - id=idinsert.GetLastInsertRowID(); - idinsert.Reset(); - // m_db->ExecuteInsert("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('"+identity+"','"+now.Format("%Y-%m-%d %H:%M:%S")+"');",(long &)id); + if(insertcount<50 && dayinsertcount<100) + { + idinsert.Bind(0,identity); + idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); + idinsert.Bind(2,"trust list of "+publisherid); + idinsert.Step(true); + id=idinsert.GetLastInsertRowID(); + idinsert.Reset(); + } + insertcount++; + dayinsertcount++; } else { @@ -151,6 +173,15 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) trustst.Finalize(); st.Finalize(); + if(insertcount>=50) + { + m_log->warning("TrustListRequester::HandleAllData TrustList contained more than 50 new identities : "+message["Identifier"]); + } + if(dayinsertcount>=100) + { + m_log->warning("TrustListRequester::HandleAllData TrustList would have inserted more than 100 new identities in the last 24 hours : "+message["Identifier"]); + } + st=m_db->Prepare("INSERT INTO tblTrustListRequests(IdentityID,Day,RequestIndex,Found) VALUES(?,?,?,'true');"); st.Bind(0,identityid); st.Bind(1,idparts[4]); diff --git a/src/http/ipagehandler.cpp b/src/http/ipagehandler.cpp index 53211b1..9048d98 100644 --- a/src/http/ipagehandler.cpp +++ b/src/http/ipagehandler.cpp @@ -102,7 +102,10 @@ void IPageHandler::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Ne CreateQueryVarMap(request,vars); - response.setChunkedTransferEncoding(true); + if(request.getVersion()==Poco::Net::HTTPRequest::HTTP_1_1) + { + response.setChunkedTransferEncoding(true); + } response.setContentType("text/html"); std::ostream &ostr = response.send(); diff --git a/src/http/pages/homepage.cpp b/src/http/pages/homepage.cpp index 2f41fac..fc60f78 100644 --- a/src/http/pages/homepage.cpp +++ b/src/http/pages/homepage.cpp @@ -59,7 +59,7 @@ const std::string HomePage::GeneratePage(const std::string &method, const std::m if(showgenericupdate) { - content+="Check for new versions at the FMS Freesite
"; + content+="Check for new versions at the FMS Freesite
"; } content+="Use these pages to administer your FMS installation."; diff --git a/src/http/pages/optionspage.cpp b/src/http/pages/optionspage.cpp index 4f7cc83..5a1d8e1 100644 --- a/src/http/pages/optionspage.cpp +++ b/src/http/pages/optionspage.cpp @@ -119,7 +119,7 @@ const std::string OptionsPage::GeneratePage(const std::string &method, const std st.Step(); count++; } -content+=""; + content+=""; content+="
"; content+=""; -- 2.7.4