From f8c0410b12183ecb40aafbb44086fa146b25b528 Mon Sep 17 00:00:00 2001 From: SomeDude Date: Sat, 2 Aug 2008 13:16:00 +0200 Subject: [PATCH] version 0.3.15 --- CMakeLists.txt | 4 ++- include/bitmapvalidator.h | 8 +++++ include/documenttypevalidator.h | 2 ++ include/global.h | 2 +- src/bitmapvalidator.cpp | 20 +++++++++++- src/freenet/captcha/alternatecaptcha1.cpp | 2 ++ src/freenet/introductionpuzzlerequester.cpp | 3 +- src/http/httpthread.cpp | 47 ++++++++++++++++++----------- src/http/pages/announceidentitypage.cpp | 10 ++++-- 9 files changed, 73 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27de288..a97f5dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,8 @@ IF(ALTERNATE_CAPTCHA) src/freenet/captcha/alternatecaptcha1.cpp src/freenet/captcha/freeimage/bitmap.cpp src/freenet/captcha/freeimage/font.cpp) +ELSE(ALTERNATE_CAPTCHA) + MESSAGE(STATUS "You are using the old captcha generator. Add a -D ALTERNATE_CAPTCHA=ON to the command line to use the alternate captcha generator.") ENDIF(ALTERNATE_CAPTCHA) IF(NOT I_HAVE_READ_THE_README) @@ -169,7 +171,7 @@ FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s) IF(ALTERNATE_CAPTCHA) FIND_FILE(FREEIMAGE_LIBRARY NAMES libfreeimage.a PATHS /usr/lib/) IF(NOT FREEIMAGE_LIBRARY) - FIND_LIBRARY(FREEIMAGE_LIBRARY NAMES FreeImage libFreeImage libfreeimage) + FIND_LIBRARY(FREEIMAGE_LIBRARY NAMES FreeImage libFreeImage libfreeimage freeimage) ENDIF(NOT FREEIMAGE_LIBRARY) ENDIF(ALTERNATE_CAPTCHA) diff --git a/include/bitmapvalidator.h b/include/bitmapvalidator.h index 0a1ee65..20c452c 100644 --- a/include/bitmapvalidator.h +++ b/include/bitmapvalidator.h @@ -6,7 +6,15 @@ class BitmapValidator:public DocumentTypeValidator { public: + BitmapValidator(); + ~BitmapValidator(); + const bool Validate(const std::vector &data); + void SetMax(const int maxw, const int maxh) { m_maxwidth=maxw; m_maxheight=maxh; } + +private: + int m_maxwidth; + int m_maxheight; }; #endif // _bitmapvalidator_ diff --git a/include/documenttypevalidator.h b/include/documenttypevalidator.h index 8c99dd5..6cc7200 100644 --- a/include/documenttypevalidator.h +++ b/include/documenttypevalidator.h @@ -6,6 +6,8 @@ class DocumentTypeValidator { public: + DocumentTypeValidator() {} + virtual ~DocumentTypeValidator() {} virtual const bool Validate(const std::vector &data)=0; }; diff --git a/include/global.h b/include/global.h index 7104808..05d90fc 100644 --- a/include/global.h +++ b/include/global.h @@ -7,7 +7,7 @@ #define VERSION_MAJOR "0" #define VERSION_MINOR "3" -#define VERSION_RELEASE "14" +#define VERSION_RELEASE "15" #define FMS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_RELEASE typedef Poco::ScopedLock Guard; diff --git a/src/bitmapvalidator.cpp b/src/bitmapvalidator.cpp index 771b707..c2a4a3c 100644 --- a/src/bitmapvalidator.cpp +++ b/src/bitmapvalidator.cpp @@ -6,6 +6,16 @@ #include #include +BitmapValidator::BitmapValidator():m_maxwidth(-1),m_maxheight(-1) +{ + +} + +BitmapValidator::~BitmapValidator() +{ + +} + const bool BitmapValidator::Validate(const std::vector &data) { bool validated=false; @@ -20,7 +30,15 @@ const bool BitmapValidator::Validate(const std::vector &data) BMP temp; if(temp.ReadFromFile(tempname.c_str())) { - validated=true; + validated=true; + if(m_maxwidth!=-1 && temp.TellWidth()>m_maxwidth) + { + validated=false; + } + if(m_maxheight!=-1 && temp.TellHeight()>m_maxheight) + { + validated=false; + } } unlink(tempname.c_str()); diff --git a/src/freenet/captcha/alternatecaptcha1.cpp b/src/freenet/captcha/alternatecaptcha1.cpp index 07f4dde..e76a57c 100644 --- a/src/freenet/captcha/alternatecaptcha1.cpp +++ b/src/freenet/captcha/alternatecaptcha1.cpp @@ -88,6 +88,7 @@ void AlternateCaptcha1::Generate() } } + // make output a little wavy int offset=rand()%10000; for(int y=0; y &solution) void AlternateCaptcha1::LoadFonts() { + FreeImage::Bitmap bmp; Poco::Path path("fonts"); Poco::DirectoryIterator di(path); diff --git a/src/freenet/introductionpuzzlerequester.cpp b/src/freenet/introductionpuzzlerequester.cpp index f7d5317..66669b3 100644 --- a/src/freenet/introductionpuzzlerequester.cpp +++ b/src/freenet/introductionpuzzlerequester.cpp @@ -112,6 +112,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) // we can only validate bitmaps for now BitmapValidator val; + val.SetMax(200,200); std::vector puzzledata; Base64::Decode(xml.GetPuzzleData(),puzzledata); if(xml.GetMimeType()!="image/bmp" || val.Validate(puzzledata)==false) @@ -265,7 +266,7 @@ void IntroductionPuzzleRequester::PopulateIDList() st.Finalize(); // select identities that aren't single use, are publishing a trust list, and have been seen today ( order by trust DESC and limit to limitnum ) - st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";"); + st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND (LocalTrustListTrust IS NULL OR LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust')) AND LastSeen>='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";"); st.Step(); m_ids.clear(); diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index 89edc93..2ddfbcd 100644 --- a/src/http/httpthread.cpp +++ b/src/http/httpthread.cpp @@ -25,28 +25,39 @@ void HTTPThread::run() { m_log->debug("HTTPThread::run thread started."); - Poco::Net::ServerSocket sock(m_listenport); - Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams; - pParams->setMaxQueued(30); - pParams->setMaxThreads(5); - Poco::Net::HTTPServer srv(new FMSHTTPRequestHandlerFactory,sock,pParams); + try + { + Poco::Net::ServerSocket sock(m_listenport); + Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams; + pParams->setMaxQueued(30); + pParams->setMaxThreads(5); + Poco::Net::HTTPServer srv(new FMSHTTPRequestHandlerFactory,sock,pParams); + + srv.start(); + m_log->trace("Started HTTPServer"); - srv.start(); - m_log->trace("Started HTTPServer"); + do + { + Poco::Thread::sleep(1000); + }while(!IsCancelled()); - do + m_log->trace("Trying to stop HTTPServer"); + srv.stop(); + m_log->trace("Stopped HTTPServer"); + + m_log->trace("Waiting for current HTTP requests to finish"); + while(srv.currentConnections()>0) + { + Poco::Thread::sleep(500); + } + } + catch(Poco::Exception &e) { - Poco::Thread::sleep(1000); - }while(!IsCancelled()); - - m_log->trace("Trying to stop HTTPServer"); - srv.stop(); - m_log->trace("Stopped HTTPServer"); - - m_log->trace("Waiting for current HTTP requests to finish"); - while(srv.currentConnections()>0) + m_log->fatal("HTTPThread::run caught "+e.displayText()); + } + catch(...) { - Poco::Thread::sleep(500); + m_log->fatal("HTTPThread::run caught unknown exception"); } m_log->debug("HTTPThread::run thread exiting."); diff --git a/src/http/pages/announceidentitypage.cpp b/src/http/pages/announceidentitypage.cpp index 7858d88..f14b275 100644 --- a/src/http/pages/announceidentitypage.cpp +++ b/src/http/pages/announceidentitypage.cpp @@ -43,6 +43,8 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, std::string lastid=""; std::string thisid=""; std::string day=""; + std::string name=""; + std::string pubkey=""; int requestindex=0; bool willshow=false; @@ -87,11 +89,11 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, content+="
Select Identity : "; content+=CreateLocalIdentityDropDown("localidentityid",""); content+=""; - content+="
Type the answers of a few puzzles. The puzzles are case sensitive. Getting announced will take some time. DO NOT continuously solve captchas. Solve 30 at most, wait a day, and if your identity has not been announced, repeat until it is."; + content+="
Type the answers of a few of the following puzzles. You don't need to get them all correct, but remember that they are case sensitive. Getting announced will take some time. DO NOT continuously solve captchas. Solve 30 at most, wait a day, and if your identity has not been announced, repeat until it is."; content+=""; date-=Poco::Timespan(1,0,0,0,0); - SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID,RequestIndex FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,tblIdentity.IdentityID,RequestIndex,tblIdentity.Name,tblIdentity.PublicKey FROM tblIntroductionPuzzleRequests INNER JOIN tblIdentity ON tblIntroductionPuzzleRequests.IdentityID=tblIdentity.IdentityID WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND Found='true' ORDER BY tblIdentity.IdentityID, Day DESC, RequestIndex DESC;"); st.Step(); if(st.RowReturned()==false) @@ -105,6 +107,8 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, st.ResultText(1,day); st.ResultText(2,thisid); st.ResultInt(3,requestindex); + st.ResultText(4,name); + st.ResultText(5,pubkey); // if we are already inserting a solution for an identity - we shouldn't show any puzzles that are older than the one we are inserting // get the last index # we are inserting this day from this identity @@ -129,7 +133,7 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, { content+="\r\n"; } - content+=""; + content+=""; content+="
"; content+=""; content+=""; -- 2.7.4