From: SomeDude Date: Sat, 28 Jun 2008 16:35:00 +0000 (+0200) Subject: version 0.3.0 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dec33c63afafabf83c3039e916725cac6faef9b3;p=fms.git version 0.3.0 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f5dd453..56d8174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,26 +17,33 @@ src/base64.cpp src/bitmapvalidator.cpp src/board.cpp src/boardlist.cpp -src/commandthread.cpp -src/datetime.cpp +src/db +src/dbconversions.cpp +src/dbmaintenancethread.cpp +src/dbsetup.cpp +src/fmsapp.cpp +src/freenet src/global.cpp src/hex.cpp +src/http +src/ipaddressacl.cpp src/localidentity.cpp -src/logfile.cpp src/main.cpp src/message.cpp src/messagelist.cpp +src/nntp src/option.cpp +src/optionssetup.cpp src/socketdefines.cpp src/stringfunctions.cpp -src/threadcontroller.cpp -src/uuidgenerator.cpp +src/threadwrapper src/db/sqlite3db.cpp src/db/sqlite3recordset.cpp src/db/sqlite3statement.cpp src/freenet/boardlistinserter.cpp src/freenet/boardlistrequester.cpp src/freenet/boardlistxml.cpp +src/freenet/captcha src/freenet/fcpv2.cpp src/freenet/fileinserter.cpp src/freenet/freenetmasterthread.cpp @@ -56,19 +63,22 @@ src/freenet/messagelistrequester.cpp src/freenet/messagelistxml.cpp src/freenet/messagerequester.cpp src/freenet/messagexml.cpp -src/freenet/periodicdbmaintenance.cpp src/freenet/siteinserter.cpp src/freenet/trustlistinserter.cpp src/freenet/trustlistrequester.cpp src/freenet/trustlistxml.cpp src/freenet/unkeyedidcreator.cpp +src/freenet/captcha/easybmp src/freenet/captcha/simplecaptcha.cpp src/freenet/captcha/easybmp/EasyBMP.cpp src/freenet/captcha/easybmp/EasyBMP_Font.cpp src/freenet/captcha/easybmp/EasyBMP_Geometry.cpp +src/http/fmshttprequesthandlerfactory.cpp src/http/httpthread.cpp src/http/identityexportxml.cpp src/http/ipagehandler.cpp +src/http/multipartparser.cpp +src/http/pages src/http/pages/addpeerpage.cpp src/http/pages/announceidentitypage.cpp src/http/pages/boardspage.cpp @@ -85,6 +95,7 @@ src/http/pages/peermaintenancepage.cpp src/http/pages/peertrustpage.cpp src/http/pages/showcaptchapage.cpp src/nntp/extensiontrust.cpp +src/nntp/mime src/nntp/nntpconnection.cpp src/nntp/nntplistener.cpp src/nntp/uwildmat.cpp @@ -92,36 +103,19 @@ src/nntp/mime/Mime.cpp src/nntp/mime/MimeChar.cpp src/nntp/mime/MimeCode.cpp src/nntp/mime/MimeType.cpp -src/pthreadwrapper/guard.cpp -src/pthreadwrapper/mutex.cpp -src/pthreadwrapper/runnable.cpp -src/pthreadwrapper/thread.cpp -src/pthreadwrapper/threadedexecutor.cpp -src/xyssl/sha1.c +src/threadwrapper/threadedexector.cpp ) +SET(FMS_PLATFORM_SRC ) + IF(DO_CHARSET_CONVERSION) SET(FMS_SRC ${FMS_SRC} src/charsetconverter.cpp) ENDIF(DO_CHARSET_CONVERSION) -IF(WIN32) - SET(FMS_PLATFORM_SRC src/fmsservice.cpp) -ELSE(WIN32) - SET(FMS_PLATFORM_SRC src/fmsdaemon.cpp) -ENDIF(WIN32) - IF(NOT I_HAVE_READ_THE_README) MESSAGE(FATAL_ERROR "You must fully read the readme.txt before continuing.") ENDIF(NOT I_HAVE_READ_THE_README) -ADD_DEFINITIONS(-DTIXML_USE_STL) - -# was for ZThreads -#IF(CMAKE_COMPILER_IS_GNUCXX) -# #ADD_DEFINITIONS(-fpermissive) -# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") -#ENDIF(CMAKE_COMPILER_IS_GNUCXX) - ADD_EXECUTABLE(fms ${FMS_SRC} ${FMS_PLATFORM_SRC}) # link dl - For SQLite3 and shttpd - not for FreeBSD @@ -139,9 +133,10 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") -# link ws2_32 for Windows +# link ws2_32 and iphlpapi for Windows IF(WIN32) TARGET_LINK_LIBRARIES(fms ws2_32) + TARGET_LINK_LIBRARIES(fms iphlpapi) ENDIF(WIN32) # add -lxnet and -lsocket on solaris @@ -153,11 +148,45 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") IF(NOT USE_BUNDLED_SQLITE) FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s) ENDIF(NOT USE_BUNDLED_SQLITE) -FIND_LIBRARY(TINYXML_LIBRARY NAMES tinyxml tinyxml_s) +FIND_LIBRARY(POCO_FOUNDATION_LIBRARY NAMES PocoFoundation PocoFoundationmt) +FIND_LIBRARY(POCO_NET_LIBRARY NAMES PocoNet PocoNetmt) +FIND_LIBRARY(POCO_UTIL_LIBRARY NAMES PocoUtil PocoUtilmt) +FIND_LIBRARY(POCO_XML_LIBRARY NAMES PocoXML PocoXMLmt) FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2) -FIND_LIBRARY(SHTTPD_LIBRARY NAMES shttpd shttpd_s) FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s) +IF(POCO_FOUNDATION_LIBRARY) + TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY}) + IF(WIN32) + ADD_DEFINITIONS(-DPOCO_STATIC) + ENDIF(WIN32) + IF(POCO_UTIL_LIBRARY) + TARGET_LINK_LIBRARIES(fms ${POCO_UTIL_LIBRARY}) + ELSE(POCO_UTIL_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find system Poco Util library. You must set the location manually.") + ENDIF(POCO_UTIL_LIBRARY) + IF(POCO_NET_LIBRARY) + TARGET_LINK_LIBRARIES(fms ${POCO_NET_LIBRARY}) + ELSE(POCO_NET_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find system Poco Net library. You must set the location manually.") + ENDIF(POCO_NET_LIBRARY) + IF(POCO_XML_LIBRARY) + TARGET_LINK_LIBRARIES(fms ${POCO_XML_LIBRARY}) + ELSE(POCO_XML_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find system Poco XML library. You must set the location manually.") + ENDIF(POCO_XML_LIBRARY) +ELSE(POCO_FOUNDATION_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find system Poco Foundation library. You must set the location manually.") +ENDIF(POCO_FOUNDATION_LIBRARY) + +IF(NOT WIN32) + IF(PTHREADS_LIBRARY) + TARGET_LINK_LIBRARIES(fms ${PTHREADS_LIBRARY}) + ELSE(PTHREADS_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find system pthread library. You must set the location manually.") + ENDIF(PTHREADS_LIBRARY) +ENDIF(NOT WIN32) + IF(SQLITE3_LIBRARY) TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY}) ELSE(SQLITE3_LIBRARY) @@ -169,37 +198,6 @@ ELSE(SQLITE3_LIBRARY) INCLUDE_DIRECTORIES(libs/sqlite3) ENDIF(SQLITE3_LIBRARY) -IF(TINYXML_LIBRARY) - TARGET_LINK_LIBRARIES(fms ${TINYXML_LIBRARY}) -ELSE(TINYXML_LIBRARY) - MESSAGE(STATUS "Could not find system TinyXML library. Will compile from included source.") - ADD_LIBRARY(tinyxml libs/tinyxml/tinystr.cpp libs/tinyxml/tinyxml.cpp libs/tinyxml/tinyxmlerror.cpp libs/tinyxml/tinyxmlparser.cpp) - TARGET_LINK_LIBRARIES(fms tinyxml) - INCLUDE_DIRECTORIES(libs/tinyxml) -ENDIF(TINYXML_LIBRARY) - -IF(PTHREADS_LIBRARY) - TARGET_LINK_LIBRARIES(fms ${PTHREADS_LIBRARY}) -ELSE(PTHREADS_LIBRARY) - MESSAGE(FATAL_ERROR "Could not find pthreads library. You must set the location manually.") -ENDIF(PTHREADS_LIBRARY) - -IF(SHTTPD_LIBRARY) - TARGET_LINK_LIBRARIES(fms ${SHTTPD_LIBRARY}) -ELSE(SHTTPD_LIBRARY) - MESSAGE(STATUS "Could not find shttpd library. Will compile from included source.") - ADD_DEFINITIONS(-DEMBEDDED) - INCLUDE_DIRECTORIES(libs/shttpd/include) - IF(WIN32) - ADD_DEFINITIONS(-DNO_GUI) - SET(SHTTPD_PLATFORM_SRC libs/shttpd/compat_win32.c) - ELSE(WIN32) - SET(SHTTPD_PLATFORM_SRC libs/shttpd/compat_unix.c) - ENDIF(WIN32) - ADD_LIBRARY(shttpd ${SHTTPD_PLATFORM_SRC} libs/shttpd/auth.c libs/shttpd/cgi.c libs/shttpd/config.c libs/shttpd/io_cgi.c libs/shttpd/io_dir.c libs/shttpd/io_emb.c libs/shttpd/io_file.c libs/shttpd/io_socket.c libs/shttpd/io_ssi.c libs/shttpd/io_ssl.c libs/shttpd/log.c libs/shttpd/md5.c libs/shttpd/shttpd.c libs/shttpd/string.c) - TARGET_LINK_LIBRARIES(fms shttpd) -ENDIF(SHTTPD_LIBRARY) - IF(DO_CHARSET_CONVERSION) ADD_DEFINITIONS(-DDO_CHARSET_CONVERSION) IF(ICONV_LIBRARY) diff --git a/include/board.h b/include/board.h index bdc5852..f70e4f8 100644 --- a/include/board.h +++ b/include/board.h @@ -1,11 +1,11 @@ #ifndef _board_ #define _board_ -#include "datetime.h" #include "ilogger.h" #include "idatabase.h" #include +#include class Board:public ILogger,public IDatabase { @@ -21,7 +21,7 @@ public: const long GetBoardID() const { return m_boardid; } std::string GetBoardName() const { return m_boardname; } std::string GetBoardDescription() const { return m_boarddescription; } - DateTime GetDateCreated() const { return m_datecreated; } + Poco::DateTime GetDateCreated() const { return m_datecreated; } const long GetLowMessageID() const { return m_lowmessageid; } const long GetHighMessageID() const { return m_highmessageid; } const long GetMessageCount() const { return m_messagecount; } @@ -34,7 +34,7 @@ private: long m_boardid; std::string m_boardname; std::string m_boarddescription; - DateTime m_datecreated; + Poco::DateTime m_datecreated; long m_lowmessageid; // lowest id of all message currently in this board long m_highmessageid; // highest id of all message currently in this board long m_messagecount; // number of messages in this board diff --git a/include/commandthread.h b/include/commandthread.h deleted file mode 100644 index 166482c..0000000 --- a/include/commandthread.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _commandthread_ -#define _commandthread_ - -#include "ilogger.h" -#include "idatabase.h" - -//#include -#include "pthreadwrapper/runnable.h" - -class CommandThread:public PThread::Runnable,public ILogger, public IDatabase -{ -public: - - void Run(); - -private: - - void HandleInput(const std::string &input); - - // methods to handle commands - void HandleHelpCommand(); - void HandleQuit(); - - bool m_running; - -}; - -#endif // _commandthread_ diff --git a/include/datetime.h b/include/datetime.h deleted file mode 100644 index cd6df2c..0000000 --- a/include/datetime.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _date_time_ -#define _date_time_ - -#include -#include - -/* - Year actual year - Month 1=Jan,2=Feb,etc - Day 1 to last day of month - Hour 0 to 23 - Minute 0 to 59 - Second 0 to 59 - - WeekDay 0=Sunday,1=Monday,etc - YearDay 1=Jan 1st, 2=Jan 2nd, etc - -*/ - -class DateTime -{ -public: - DateTime(); - DateTime(const time_t &timet); - DateTime(const struct tm *stm); - ~DateTime() {} - - void Add(const int seconds=0, const int minutes=0, const int hours=0, const int days=0, const int months=0, const int years=0); - - void Set(const int year=1970, const int month=1, const int day=1, const int hour=0, const int minute=0, const int second=0); - void SetT(const time_t &timet); - void Set(const struct tm *stm); - void Set(const std::string &datestring); // method only will work with a select few basic input formats - - void SetToLocalTime(); - void SetToGMTime(); - - const int GetYear() const { return m_tm.tm_year+1900; } - void SetYear(const int year) { m_tm.tm_year=year-1900; } - const int GetMonth() const { return m_tm.tm_mon+1; } - void SetMonth(const int month) { m_tm.tm_mon=month-1; } - const int GetDay() const { return m_tm.tm_mday; } - void SetDay(const int day) { m_tm.tm_mday=day; } - const int GetWeekDay() const { return m_tm.tm_wday; } - void SetWeekDay(const int weekday) { m_tm.tm_wday=weekday; } - const int GetYearDay() const { return m_tm.tm_yday+1; } - void SetYearDay(const int yearday) { m_tm.tm_yday=yearday-1; } - const int GetHour() const { return m_tm.tm_hour; } - void SetHour(const int hour) { m_tm.tm_hour=hour; } - const int GetMinute() const { return m_tm.tm_min; } - void SetMinute(const int minute) { m_tm.tm_min=minute; } - const int GetSecond() const { return m_tm.tm_sec; } - void SetSecond(const int second) { m_tm.tm_sec=second; } - const int GetIsDaylightTime() const { return m_tm.tm_isdst; } - void SetIsDaylightTime(const int daylighttime) { m_tm.tm_isdst=daylighttime; } - - void Normalize(); // normalizes any date changes that were made - - std::string Format(const std::string &formatstring) const; - - DateTime operator+(const double &rhs); - DateTime operator+(const DateTime &rhs); - DateTime &operator+=(const double &rhs); - DateTime &operator+=(const DateTime &rhs); - DateTime operator-(const double &rhs); - DateTime operator-(const DateTime &rhs); - DateTime &operator-=(const double &rhs); - DateTime &operator-=(const DateTime &rhs); - - const bool operator==(const DateTime &rhs) const { return *this==rhs.m_tm; } - const bool operator==(const time_t &rhs) const { return m_timet==rhs; } - const bool operator==(const struct tm &rhs) const; - - const bool operator<(const DateTime &rhs) const { return (*this(const DateTime &rhs) const { return !(*this<=rhs.m_tm); } - const bool operator>(const time_t &rhs) const { return (m_timet>rhs); } - - const bool operator>=(const DateTime &rhs) const { return !(*this=(const time_t &rhs) const { return (m_timet>=rhs); } - -private: - const time_t TimeGM(struct tm *gmtimein); - - time_t m_timet; // don't use timet for any comparisons - struct tm m_tm; -}; - -#endif // _date_time_ diff --git a/include/db/sqlite3db/sqlite3db.h b/include/db/sqlite3db/sqlite3db.h index b41f3b8..470ba85 100644 --- a/include/db/sqlite3db/sqlite3db.h +++ b/include/db/sqlite3db/sqlite3db.h @@ -1,14 +1,11 @@ #ifndef _sqlite3db_ #define _sqlite3db_ -//#include -//#include +#include #include #include -#include "../../pthreadwrapper/mutex.h" #include "../sqlite3db.h" - -#include "../../pthreadwrapper/singleton.h" +#include "../../threadwrapper/singleton.h" #if SQLITE_VERSION_NUMBER<3005000 #error "Your version of SQLite is too old! 3.5.0 or later is required." @@ -17,7 +14,7 @@ namespace SQLite3DB { -class DB:public PThread::Singleton +class DB:public Singleton { public: DB(); @@ -41,7 +38,7 @@ public: sqlite3 *GetDB() { return m_db; } - PThread::Mutex m_mutex; // public so that recordset and statment can lock this mutex themselves + Poco::FastMutex m_mutex; // public so that recordset and statment can lock this mutex themselves private: void Initialize(); diff --git a/include/dbconversions.h b/include/dbconversions.h new file mode 100644 index 0000000..e850f58 --- /dev/null +++ b/include/dbconversions.h @@ -0,0 +1,19 @@ +#ifndef _dbconversions_ +#define _dbconversions_ + +void ConvertDB0100To0101(); +void ConvertDB0101To0103(); +void ConvertDB0103To0104(); +void ConvertDB0104To0105(); +void ConvertDB0105To0106(); +void ConvertDB0106To0107(); +void ConvertDB0107To0108(); +void ConvertDB0108To0109(); +void ConvertDB0109To0110(); +void ConvertDB0110To0111(); +void ConvertDB0111To0112(); + +// TODO remove sometime after 0.1.17 +void FixCapitalBoardNames(); + +#endif // _dbconversions_ diff --git a/include/dbmaintenancethread.h b/include/dbmaintenancethread.h new file mode 100644 index 0000000..156186e --- /dev/null +++ b/include/dbmaintenancethread.h @@ -0,0 +1,35 @@ +#ifndef _dbmaintenancethread_ +#define _dbmaintenancethread_ + +#include "threadwrapper/cancelablerunnable.h" +#include "ilogger.h" +#include "idatabase.h" + +#include + +class DBMaintenanceThread:public CancelableRunnable,public ILogger,public IDatabase +{ +public: + DBMaintenanceThread(); + + void run(); + +private: + + void Do10MinuteMaintenance(); + void Do30MinuteMaintenance(); + void Do1HourMaintenance(); + void Do6HourMaintenance(); + void Do1DayMaintenance(); + + Poco::DateTime m_last10minute; + Poco::DateTime m_last30minute; + Poco::DateTime m_last1hour; + Poco::DateTime m_last6hour; + Poco::DateTime m_last1day; + + long m_deletemessagesolderthan; + +}; + +#endif // _dbmaintenancethread_ diff --git a/include/dbsetup.h b/include/dbsetup.h new file mode 100644 index 0000000..e3618d6 --- /dev/null +++ b/include/dbsetup.h @@ -0,0 +1,7 @@ +#ifndef _dbsetup_ +#define _dbsetup_ + +// opens database and creates tables and initial inserts if necessary +void SetupDB(); + +#endif // _dbsetup_ diff --git a/include/fmsapp.h b/include/fmsapp.h new file mode 100644 index 0000000..a816d9a --- /dev/null +++ b/include/fmsapp.h @@ -0,0 +1,33 @@ +#ifndef _fmsapp_ +#define _fmsapp_ + +#include "threadwrapper/threadedexecutor.h" + +#include + +// main FMS application class +class FMSApp:public Poco::Util::ServerApplication +{ +public: + FMSApp(); + + static void Terminate() { ((FMSApp *)&FMSApp::instance())->terminate(); } + +private: + void initialize(Poco::Util::Application &self); + void initializeLogger(); + void defineOptions(Poco::Util::OptionSet &options); + int main(const std::vector &args); + + void StartThreads(); + + void handleHelp(const std::string &name, const std::string &value); + void displayHelp(); + + bool m_displayhelp; + + ThreadedExecutor m_threads; + +}; + +#endif // _fmsapp_ diff --git a/include/fmsdaemon.h b/include/fmsdaemon.h deleted file mode 100644 index 50ff86c..0000000 --- a/include/fmsdaemon.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _fmsdaemon_ -#define _fmsdaemon_ - -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 - -void Daemonize(); - -#endif // _fmsdaemon_ diff --git a/include/fmsservice.h b/include/fmsservice.h deleted file mode 100644 index 5a08fbb..0000000 --- a/include/fmsservice.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _fmsservice_ -#define _fmsservice_ - -#ifdef _WIN32 - -#include - -#define FMS_SERVICE_NAME "FMS - Freenet Message System" - -extern SERVICE_STATUS ServiceStatus; -extern SERVICE_STATUS_HANDLE hStatus; - -BOOL ServiceIsInstalled(); -BOOL ServiceInstall(); -BOOL ServiceUninstall(); -BOOL ServiceStart(); -void ServiceMain(int argc, char** argv); -void ControlHandler(DWORD request); - -#endif - -#endif // _fmsservice_ diff --git a/include/freenet/freenetmasterthread.h b/include/freenet/freenetmasterthread.h index e1f2453..6b2fc0b 100644 --- a/include/freenet/freenetmasterthread.h +++ b/include/freenet/freenetmasterthread.h @@ -7,13 +7,12 @@ #include "ifcpconnected.h" #include "iperiodicprocessor.h" -//#include -#include "../pthreadwrapper/runnable.h" +#include "../threadwrapper/cancelablerunnable.h" // forward declaration class IFreenetRegistrable; -class FreenetMasterThread:public PThread::Runnable,public ILogger, public IFCPMessageHandler +class FreenetMasterThread:public CancelableRunnable,public ILogger, public IFCPMessageHandler { public: FreenetMasterThread(); @@ -21,7 +20,7 @@ public: const bool HandleMessage(FCPMessage &message); - void Run(); + void run(); // registration methods for children objects void RegisterPeriodicProcessor(IPeriodicProcessor *obj); diff --git a/include/freenet/identityinserter.h b/include/freenet/identityinserter.h index 9c5e328..e0e974d 100644 --- a/include/freenet/identityinserter.h +++ b/include/freenet/identityinserter.h @@ -3,12 +3,13 @@ #include "../idatabase.h" #include "../ilogger.h" -#include "../datetime.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + class IdentityInserter:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: @@ -29,7 +30,7 @@ private: void CheckForNeededInsert(); void StartInsert(const long localidentityid); - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; }; diff --git a/include/freenet/identityintroductioninserter.h b/include/freenet/identityintroductioninserter.h index d975104..17c3728 100644 --- a/include/freenet/identityintroductioninserter.h +++ b/include/freenet/identityintroductioninserter.h @@ -2,13 +2,14 @@ #define _identityintroductioninserter_ #include "../idatabase.h" -#include "../datetime.h" #include "../ilogger.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + class IdentityIntroductionInserter:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: @@ -30,7 +31,7 @@ private: void StartInsert(const long localidentityid, const std::string &day, const std::string &UUID, const std::string &solution); std::string m_messagebase; - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; bool m_inserting; }; diff --git a/include/freenet/identityintroductionrequester.h b/include/freenet/identityintroductionrequester.h index a7b236f..6b3c18a 100644 --- a/include/freenet/identityintroductionrequester.h +++ b/include/freenet/identityintroductionrequester.h @@ -3,12 +3,13 @@ #include "../idatabase.h" #include "../ilogger.h" -#include "../datetime.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + class IdentityIntroductionRequester:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: @@ -32,7 +33,7 @@ private: const bool HandleGetFailed(FCPMessage &message); const bool HandleAllData(FCPMessage &message); - DateTime m_tempdate; + Poco::DateTime m_tempdate; std::map m_ids; std::vector m_requesting; std::string m_messagebase; diff --git a/include/freenet/iindexinserter.h b/include/freenet/iindexinserter.h index edcc86b..bb0e9e7 100644 --- a/include/freenet/iindexinserter.h +++ b/include/freenet/iindexinserter.h @@ -4,13 +4,16 @@ #include "../idatabase.h" #include "../ilogger.h" #include "../option.h" -#include "../datetime.h" #include "../stringfunctions.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include +#include +#include + #ifdef XMEM #include #endif @@ -42,7 +45,7 @@ protected: std::vector m_inserting; // list of ids we are inserting std::string m_messagebase; - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; // these MUST be populated by child class std::string m_fcpuniquename; @@ -66,11 +69,11 @@ void IIndexInserter::FCPConnected() // make sure variables have been initialized by the derived class if(m_fcpuniquename=="") { - m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexInserter::FCPConnected fcpuniquename not initialized correctly!"); + m_log->fatal("IIndexInserter::FCPConnected fcpuniquename not initialized correctly!"); } if(m_fcpuniquename.find("|")!=std::string::npos) { - m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexInserter::FCPConnected fcpuniquename contains | character! This is not a valid character!"); + m_log->fatal("IIndexInserter::FCPConnected fcpuniquename contains | character! This is not a valid character!"); } m_inserting.clear(); @@ -111,7 +114,7 @@ const bool IIndexInserter::HandleMessage(FCPMessage &message) StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[1],id); RemoveFromInsertList(id); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IIndexInserter::HandleMessage IdentifierCollision for "+m_fcpuniquename+" "+message["Identifier"]); + m_log->debug("IIndexInserter::HandleMessage IdentifierCollision for "+m_fcpuniquename+" "+message["Identifier"]); return true; } } @@ -124,16 +127,15 @@ void IIndexInserter::InitializeIIndexInserter() { m_fcpuniquename=""; Option::Instance()->Get("MessageBase",m_messagebase); - m_lastchecked.SetToGMTime(); + m_lastchecked=Poco::Timestamp(); } template void IIndexInserter::Process() { - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; - if(m_lastchecked<(now-(1.0/1440.0))) + if(m_lastchecked<(now-Poco::Timespan(0,0,1,0,0))) { CheckForNeededInsert(); m_lastchecked=now; diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 8744dfd..b74e69a 100644 --- a/include/freenet/iindexrequester.h +++ b/include/freenet/iindexrequester.h @@ -3,7 +3,6 @@ #include "../idatabase.h" #include "../ilogger.h" -#include "../datetime.h" #include "../option.h" #include "../stringfunctions.h" #include "ifreenetregistrable.h" @@ -11,6 +10,10 @@ #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include +#include +#include + #ifdef XMEM #include #endif @@ -40,9 +43,9 @@ protected: virtual const bool HandleGetFailed(FCPMessage &message)=0; virtual void RemoveFromRequestList(const IDTYPE id); - DateTime m_tempdate; - DateTime m_lastreceived; - DateTime m_lastpopulated; + Poco::DateTime m_tempdate; + Poco::DateTime m_lastreceived; + Poco::DateTime m_lastpopulated; std::string m_messagebase; std::map m_ids; // map of all ids we know and whether we have requested file from them yet std::vector m_requesting; // list of ids we are currently requesting from @@ -71,21 +74,21 @@ void IIndexRequester::FCPConnected() // make sure variables have been initialized by the derived class if(m_maxrequests==-1) { - m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester::FCPConnected maxrequests not initialized correctly!"); + m_log->fatal("IIndexRequester::FCPConnected maxrequests not initialized correctly!"); } if(m_fcpuniquename=="") { - m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester::FCPConnected fcpuniquename not initialized correctly!"); + m_log->fatal("IIndexRequester::FCPConnected fcpuniquename not initialized correctly!"); } if(m_fcpuniquename.find("|")!=std::string::npos) { - m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester::FCPConnected fcpuniquename contains | character! This is not a valid character!"); + m_log->fatal("IIndexRequester::FCPConnected fcpuniquename contains | character! This is not a valid character!"); } - m_lastreceived.SetToGMTime(); + m_lastreceived=Poco::Timestamp(); m_requesting.clear(); PopulateIDList(); - m_lastpopulated.SetToGMTime(); + m_lastpopulated=Poco::Timestamp(); } template @@ -101,7 +104,7 @@ const bool IIndexRequester::HandleMessage(FCPMessage &message) if(message["Identifier"].find(m_fcpuniquename)==0) { - m_lastreceived.SetToGMTime(); + m_lastreceived=Poco::Timestamp(); if(message.GetName()=="DataFound") { @@ -140,17 +143,16 @@ void IIndexRequester::InitializeIIndexRequester() m_fcpuniquename=""; Option::Instance()->Get("MessageBase",m_messagebase); - m_tempdate.SetToGMTime(); - m_lastreceived.SetToGMTime(); - m_lastpopulated.SetToGMTime(); - m_lastpopulated.Add(0,-10); + m_tempdate=Poco::Timestamp(); + m_lastreceived=Poco::Timestamp(); + m_lastpopulated=Poco::Timestamp(); + m_lastpopulated-=Poco::Timespan(0,0,10,0,0); } template void IIndexRequester::Process() { - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; // max is the smaller of the config value or the total number of ids we will request from typename std::map::size_type max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests; @@ -172,24 +174,24 @@ void IIndexRequester::Process() else { // we requested from all ids in the list, repopulate the list (only every 10 minutes) - if(m_lastpopulated<(now-1.0/144.0)) + if(m_lastpopulated<(now-Poco::Timespan(0,0,10,0,0))) { PopulateIDList(); - m_lastpopulated.SetToGMTime(); + m_lastpopulated=Poco::Timestamp(); } } } // special case - if there were 0 ids on the list when we started then we will never get a chance to repopulate the list // this will recheck for ids every minute - if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0))) + if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0))) { PopulateIDList(); m_tempdate=now; } // if we haven't received any messages to this object in 10 minutes, clear the requests and repopulate id list - if(m_ids.size()>0 && m_lastreceived<(now-(1.0/144.0))) + if(m_ids.size()>0 && m_lastreceived<(now-Poco::Timespan(0,0,10,0,0))) { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes. Restarting requests."); + m_log->error("IIndexRequester::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes. Restarting requests."); FCPConnected(); } diff --git a/include/freenet/introductionpuzzleinserter.h b/include/freenet/introductionpuzzleinserter.h index c83cb9f..3ac8d83 100644 --- a/include/freenet/introductionpuzzleinserter.h +++ b/include/freenet/introductionpuzzleinserter.h @@ -3,7 +3,8 @@ #include "iindexinserter.h" -//class IntroductionPuzzleInserter:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger +#include + class IntroductionPuzzleInserter:public IIndexInserter { public: @@ -18,7 +19,7 @@ private: const bool HandlePutSuccessful(FCPMessage &message); const bool HandlePutFailed(FCPMessage &message); - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; }; diff --git a/include/freenet/introductionpuzzlerequester.h b/include/freenet/introductionpuzzlerequester.h index 9d7e3ab..8dcec3f 100644 --- a/include/freenet/introductionpuzzlerequester.h +++ b/include/freenet/introductionpuzzlerequester.h @@ -3,12 +3,13 @@ #include "../idatabase.h" #include "../ilogger.h" -#include "../datetime.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + class IntroductionPuzzleRequester:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: @@ -32,7 +33,7 @@ private: const bool HandleAllData(FCPMessage &message); const bool HandleGetFailed(FCPMessage &message); - DateTime m_tempdate; + Poco::DateTime m_tempdate; std::string m_messagebase; long m_maxrequests; std::vector m_requesting; // list of ids we are currently requesting from diff --git a/include/freenet/periodicdbmaintenance.h b/include/freenet/periodicdbmaintenance.h deleted file mode 100644 index 575cef4..0000000 --- a/include/freenet/periodicdbmaintenance.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _periodicdbmaintenance_ -#define _periodicdbmaintenance_ - -#include "../idatabase.h" -#include "../ilogger.h" -#include "../datetime.h" -#include "ifreenetregistrable.h" -#include "iperiodicprocessor.h" - -class PeriodicDBMaintenance:public IFreenetRegistrable,public IPeriodicProcessor,public IDatabase,public ILogger -{ -public: - PeriodicDBMaintenance(); - - void Process(); - - void RegisterWithThread(FreenetMasterThread *thread); - -private: - void Do10MinuteMaintenance(); - void Do30MinuteMaintenance(); - void Do1HourMaintenance(); - void Do6HourMaintenance(); - void Do1DayMaintenance(); - - DateTime m_check10mins; - DateTime m_check30mins; - DateTime m_check1hour; - DateTime m_check6hours; - DateTime m_check1day; - - long m_deletemessagesolderthan; - -}; - -#endif // _periodicdbmaintenance_ diff --git a/include/freenet/trustlistinserter.h b/include/freenet/trustlistinserter.h index ca599dd..6c5003a 100644 --- a/include/freenet/trustlistinserter.h +++ b/include/freenet/trustlistinserter.h @@ -3,12 +3,13 @@ #include "../idatabase.h" #include "../ilogger.h" -#include "../datetime.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + class TrustListInserter:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: @@ -30,7 +31,7 @@ private: void StartInsert(const long localidentityid, const std::string &privatekey); std::string m_messagebase; - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; }; diff --git a/include/freenet/unkeyedidcreator.h b/include/freenet/unkeyedidcreator.h index 7f9fb15..d0db037 100644 --- a/include/freenet/unkeyedidcreator.h +++ b/include/freenet/unkeyedidcreator.h @@ -2,13 +2,14 @@ #define _unkeyedidcreatorr_ #include "../ilogger.h" -#include "../datetime.h" #include "../idatabase.h" #include "ifreenetregistrable.h" #include "ifcpconnected.h" #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#include + /** \brief Looks for any unkeyed Local Identities and requests SSK keys for them @@ -33,7 +34,7 @@ private: void CheckForUnkeyedID(); void SaveKeys(const long localidentityid, const std::string &publickey, const std::string &privatekey); - DateTime m_lastchecked; + Poco::DateTime m_lastchecked; bool m_waiting; }; diff --git a/include/global.h b/include/global.h index fa9f487..1576e55 100644 --- a/include/global.h +++ b/include/global.h @@ -2,44 +2,13 @@ #define _global_ #include -#include -#include "pthreadwrapper/thread.h" +#include +#include -#define FMS_VERSION "0.2.23" +#define FMS_VERSION "0.3.0" -// opens database and creates tables and initial inserts if necessary -void SetupDB(); -void ConvertDB0100To0101(); -void ConvertDB0101To0103(); -void ConvertDB0103To0104(); -void ConvertDB0104To0105(); -void ConvertDB0105To0106(); -void ConvertDB0106To0107(); -void ConvertDB0107To0108(); -void ConvertDB0108To0109(); -void ConvertDB0109To0110(); -void ConvertDB0110To0111(); -void ConvertDB0111To0112(); -// inserts default options into the database -void SetupDefaultOptions(); -// opens logfile and sets it up -void SetupLogFile(); +typedef Poco::ScopedLock Guard; std::string CreateShortIdentityName(const std::string &name, const std::string &publickey); -// TODO remove sometime after 0.1.17 -void FixCapitalBoardNames(); - -void SigHandler(int signum); - -void MainFunction(); -void Shutdown(); - -// needed for Windows to setup network -void SetupNetwork(); -// cleanup network on Windows -void ShutdownNetwork(); - -extern volatile bool wantshutdown; - #endif // _global_ diff --git a/include/http/fmshttprequesthandlerfactory.h b/include/http/fmshttprequesthandlerfactory.h new file mode 100644 index 0000000..3e42513 --- /dev/null +++ b/include/http/fmshttprequesthandlerfactory.h @@ -0,0 +1,25 @@ +#ifndef _fmshttprequesthandlerfactory_ +#define _fmshttprequesthandlerfactory_ + +#include "ipagehandler.h" +#include "../ipaddressacl.h" +#include "../ilogger.h" + +#include +#include + +class FMSHTTPRequestHandlerFactory:public Poco::Net::HTTPRequestHandlerFactory,public ILogger +{ +public: + FMSHTTPRequestHandlerFactory(); + ~FMSHTTPRequestHandlerFactory(); + + Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request); + +private: + std::vector m_pagehandlers; + IPAddressACL m_acl; + +}; + +#endif // _fmshttprequesthandlerfactory_ diff --git a/include/http/httpdefs.h b/include/http/httpdefs.h deleted file mode 100644 index 8dcd77f..0000000 --- a/include/http/httpdefs.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _httpdefs_ -#define _httpdefs_ - -struct httpstate -{ - char *m_indata; - long m_indatalen; - long m_indatapos; - char *m_outdata; - long m_outdatalen; - long m_outdatapos; -}; - -#endif // _httpdefs_ diff --git a/include/http/httpthread.h b/include/http/httpthread.h index 8ebd00d..b6d7035 100644 --- a/include/http/httpthread.h +++ b/include/http/httpthread.h @@ -1,29 +1,23 @@ #ifndef _httpthread_ #define _httpthread_ -#include "../pthreadwrapper/runnable.h" +#include "../threadwrapper/cancelablerunnable.h" #include "../ilogger.h" #include "../idatabase.h" -#include "ipagehandler.h" -#include "httpdefs.h" #include -#include -class HTTPThread:public PThread::Runnable,public ILogger, public IDatabase +class HTTPThread:public CancelableRunnable,public ILogger, public IDatabase { public: HTTPThread(); - ~HTTPThread(); - void Run(); + void run(); private: - static void PageCallback(shttpd_arg *arg); + //static void PageCallback(shttpd_arg *arg); - struct shttpd_ctx *m_ctx; - - std::vector m_pagehandlers; + int m_listenport; }; diff --git a/include/http/ipagehandler.h b/include/http/ipagehandler.h index 66e15b8..745f727 100644 --- a/include/http/ipagehandler.h +++ b/include/http/ipagehandler.h @@ -1,38 +1,40 @@ #ifndef _ipagehandler_ #define _ipagehandler_ +#include "../ilogger.h" + +#include +#include +#include + #include #include #include #include -#include -class IPageHandler +class IPageHandler:public Poco::Net::HTTPRequestHandler,public ILogger { public: IPageHandler() {} IPageHandler(const std::string &templatestr) { m_template=templatestr; } virtual ~IPageHandler() {} + virtual const bool WillHandleURI(const std::string &uri)=0; + + virtual IPageHandler *New()=0; // returns a new instance of the object - /** - \brief Handles request for a page - - \return true if request was handled, false if it was ignored - */ - const bool Handle(shttpd_arg *arg); + virtual void handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response); private: - virtual const bool WillHandleURI(const std::string &uri)=0; virtual const std::string GeneratePage(const std::string &method, const std::map &queryvars)=0; - + protected: - // splits apart data into name,data pairs in args map - void HandleMultiPartData(const std::string &contenttypeheader, char *data, const long datalen, std::map &args); // converts from basename[#] query args into a vector where the vector pos is the index pos # void CreateArgArray(const std::map &vars, const std::string &basename, std::vector &args); const std::string CreateTrueFalseDropDown(const std::string &name, const std::string &selected); - // replaces html control characters with elements (i.e. < becomes <) + void CreateQueryVarMap(Poco::Net::HTTPServerRequest &request, std::map &vars); + + // replaces html elements with encoded characters (i.e. < becomes <) const std::string SanitizeOutput(const std::string &input); std::string m_template; diff --git a/include/http/multipartparser.h b/include/http/multipartparser.h new file mode 100644 index 0000000..a4a99d6 --- /dev/null +++ b/include/http/multipartparser.h @@ -0,0 +1,19 @@ +#ifndef _multipartparser_ +#define _multipartparser_ + +#include +#include +#include + +class MultiPartParser:public Poco::Net::PartHandler +{ +public: + void handlePart(const Poco::Net::MessageHeader &header, std::istream &stream); + + std::map GetVars() { return vars; } + +private: + std::map vars; +}; + +#endif // _multipartparser_ diff --git a/include/http/pages/addpeerpage.h b/include/http/pages/addpeerpage.h index 79aedb3..ac050e2 100644 --- a/include/http/pages/addpeerpage.h +++ b/include/http/pages/addpeerpage.h @@ -9,6 +9,8 @@ class AddPeerPage:public IPageHandler,public IDatabase public: AddPeerPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new AddPeerPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/announceidentitypage.h b/include/http/pages/announceidentitypage.h index e2817f9..0ac5be9 100644 --- a/include/http/pages/announceidentitypage.h +++ b/include/http/pages/announceidentitypage.h @@ -9,6 +9,8 @@ class AnnounceIdentityPage:public IPageHandler,public IDatabase public: AnnounceIdentityPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new AnnounceIdentityPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/boardspage.h b/include/http/pages/boardspage.h index 7f8ae92..a8e1c1a 100644 --- a/include/http/pages/boardspage.h +++ b/include/http/pages/boardspage.h @@ -9,6 +9,8 @@ class BoardsPage:public IPageHandler,public IDatabase public: BoardsPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new BoardsPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/confirmpage.h b/include/http/pages/confirmpage.h index 10ee226..2ad4ed9 100644 --- a/include/http/pages/confirmpage.h +++ b/include/http/pages/confirmpage.h @@ -8,6 +8,8 @@ class ConfirmPage:public IPageHandler public: ConfirmPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new ConfirmPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/controlboardpage.h b/include/http/pages/controlboardpage.h index 6471ada..7484989 100644 --- a/include/http/pages/controlboardpage.h +++ b/include/http/pages/controlboardpage.h @@ -9,6 +9,8 @@ class ControlBoardPage:public IPageHandler,public IDatabase public: ControlBoardPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new ControlBoardPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/createidentitypage.h b/include/http/pages/createidentitypage.h index 4a5374c..e6d938c 100644 --- a/include/http/pages/createidentitypage.h +++ b/include/http/pages/createidentitypage.h @@ -9,6 +9,8 @@ class CreateIdentityPage:public IPageHandler,public IDatabase public: CreateIdentityPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new CreateIdentityPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/execquerypage.h b/include/http/pages/execquerypage.h index 4679ec2..37255b9 100644 --- a/include/http/pages/execquerypage.h +++ b/include/http/pages/execquerypage.h @@ -9,6 +9,8 @@ class ExecQueryPage:public IPageHandler,public IDatabase public: ExecQueryPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new ExecQueryPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/homepage.h b/include/http/pages/homepage.h index 0205557..1a4b832 100644 --- a/include/http/pages/homepage.h +++ b/include/http/pages/homepage.h @@ -9,6 +9,8 @@ class HomePage:public IPageHandler,public IDatabase public: HomePage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new HomePage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/insertedfilespage.h b/include/http/pages/insertedfilespage.h index c09e638..80c4b0e 100644 --- a/include/http/pages/insertedfilespage.h +++ b/include/http/pages/insertedfilespage.h @@ -9,6 +9,8 @@ class InsertedFilesPage:public IPageHandler,public IDatabase public: InsertedFilesPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new InsertedFilesPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/localidentitiespage.h b/include/http/pages/localidentitiespage.h index 71e0caa..d994fd2 100644 --- a/include/http/pages/localidentitiespage.h +++ b/include/http/pages/localidentitiespage.h @@ -8,10 +8,20 @@ class LocalIdentitiesPage:public IPageHandler,public IDatabase { public: LocalIdentitiesPage(const std::string &templatestr):IPageHandler(templatestr) {} + + IPageHandler *New() { return new LocalIdentitiesPage(m_template); } + + void handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response); + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); + void HandleUpdate(const std::map &queryvars); + void HandleDelete(const std::map &queryvars); + void HandleImport(const std::map &queryvars); + const std::string HandleExport(); + }; #endif // _localidentitiespage_ diff --git a/include/http/pages/optionspage.h b/include/http/pages/optionspage.h index 414875d..447b00f 100644 --- a/include/http/pages/optionspage.h +++ b/include/http/pages/optionspage.h @@ -9,6 +9,8 @@ class OptionsPage:public IPageHandler,public IDatabase public: OptionsPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new OptionsPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/peerdetailspage.h b/include/http/pages/peerdetailspage.h index 5a2b79f..20d9149 100644 --- a/include/http/pages/peerdetailspage.h +++ b/include/http/pages/peerdetailspage.h @@ -9,6 +9,8 @@ class PeerDetailsPage:public IPageHandler,public IDatabase public: PeerDetailsPage(const std::string templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new PeerDetailsPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/peermaintenancepage.h b/include/http/pages/peermaintenancepage.h index 80f74f1..95e4966 100644 --- a/include/http/pages/peermaintenancepage.h +++ b/include/http/pages/peermaintenancepage.h @@ -9,6 +9,8 @@ class PeerMaintenancePage:public IPageHandler,public IDatabase public: PeerMaintenancePage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new PeerMaintenancePage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/peertrustpage.h b/include/http/pages/peertrustpage.h index 851296f..cce9ae6 100644 --- a/include/http/pages/peertrustpage.h +++ b/include/http/pages/peertrustpage.h @@ -9,6 +9,8 @@ class PeerTrustPage:public IPageHandler,public IDatabase public: PeerTrustPage(const std::string &templatestr):IPageHandler(templatestr) {} + IPageHandler *New() { return new PeerTrustPage(m_template); } + private: const bool WillHandleURI(const std::string &uri); const std::string GeneratePage(const std::string &method, const std::map &queryvars); diff --git a/include/http/pages/showcaptchapage.h b/include/http/pages/showcaptchapage.h index 121ad9a..739e412 100644 --- a/include/http/pages/showcaptchapage.h +++ b/include/http/pages/showcaptchapage.h @@ -8,9 +8,13 @@ class ShowCaptchaPage:public IPageHandler,public IDatabase { public: + void handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response); + + IPageHandler *New() { return new ShowCaptchaPage; } + private: const bool WillHandleURI(const std::string &uri); - const std::string GeneratePage(const std::string &method, const std::map &queryvars); + const std::string GeneratePage(const std::string &method, const std::map &queryvars) {return "";} }; diff --git a/include/ifmsxmldocument.h b/include/ifmsxmldocument.h index ae555a1..6358e8f 100644 --- a/include/ifmsxmldocument.h +++ b/include/ifmsxmldocument.h @@ -1,10 +1,18 @@ #ifndef _ifmsxmldocument_ #define _ifmsxmldocument_ +#include +#include +#include +#include +#include +#include +#include +#include + #include "stringfunctions.h" #include -#include #ifdef XMEM #include @@ -33,53 +41,116 @@ public: protected: /** + Poco doesn't like CDATA with whitespace outside the tags + This will remove the whitespace from around CDATA tags + */ + virtual const std::string FixCDATA(const std::string &xmlstr) + { + std::string rstring=xmlstr; + std::string::size_type beg1=std::string::npos; + std::string::size_type end1=rstring.find("",end1); + if(beg1!=end1-1) + { + rstring.erase(beg1+1,end1-(beg1+1)); + } + + beg2=rstring.find("]]>",end1); + if(beg2!=std::string::npos) + { + end2=rstring.find("<",beg2); + if(end2!=std::string::npos) + { + rstring.erase(beg2+3,end2-(beg2+3)); + } + } + + end1=rstring.find("LinkEndChild(txt); - return el; + if(doc) + { + Poco::XML::Text *txt=doc->createTextNode(value ? "true" : "false"); + Poco::XML::Element *el=doc->createElement(name); + el->appendChild(txt); + return el; + } + else + { + return NULL; + } } /** \brief Creates and returns an element with a CDATA value */ - virtual TiXmlElement *XMLCreateCDATAElement(const std::string &name, const std::string &data) + virtual Poco::XML::Element *XMLCreateCDATAElement(Poco::XML::Document *doc, const std::string &name, const std::string &data) { - TiXmlText *txt=new TiXmlText(data); - txt->SetCDATA(true); - TiXmlElement *el=new TiXmlElement(name); - el->LinkEndChild(txt); - return el; + if(doc) + { + // Poco XML won't break up CDATA sections correctly when assigned a string with the + // end tag is present. However, it will parse it correctly, so we will manually break the + // CDATA into separate parts + Poco::XML::CDATASection *sec=doc->createCDATASection(StringFunctions::Replace(data,"]]>","]]]>")); + Poco::XML::Element *el=doc->createElement(name); + el->appendChild(sec); + return el; + } + else + { + return NULL; + } } /** \brief Creates and returns a text element */ - virtual TiXmlElement *XMLCreateTextElement(const std::string &name, const std::string &data) + virtual Poco::XML::Element *XMLCreateTextElement(Poco::XML::Document *doc, const std::string &name, const std::string &data) { - TiXmlText *txt=new TiXmlText(data); - TiXmlElement *el=new TiXmlElement(name); - el->LinkEndChild(txt); - return el; + if(doc) + { + Poco::XML::Text *txt=doc->createTextNode(data); + Poco::XML::Element *el=doc->createElement(name); + el->appendChild(txt); + return el; + } + else + { + return NULL; + } } - virtual TiXmlElement *XMLCreateTextElement(const std::string &name, const long data) + virtual Poco::XML::Element *XMLCreateTextElement(Poco::XML::Document *doc, const std::string &name, const long data) { - std::string datastr; - StringFunctions::Convert(data,datastr); - return XMLCreateTextElement(name,datastr); + if(doc) + { + std::string datastr; + StringFunctions::Convert(data,datastr); + return XMLCreateTextElement(doc,name,datastr); + } + else + { + return NULL; + } } - virtual const bool XMLGetBooleanElement(TiXmlElement *parent, const std::string &name) + virtual const bool XMLGetBooleanElement(Poco::XML::Element *parent, const std::string &name) { - TiXmlHandle hnd(parent); - TiXmlText *txt=hnd.FirstChild(name).FirstChild().ToText(); - if(txt) + Poco::XML::Element *el=XMLGetFirstChild(parent,name); + if(el && el->firstChild()) { - if(txt->ValueStr()=="true") + if(el->firstChild()->getNodeValue()=="true") { return true; } @@ -91,6 +162,40 @@ protected: return false; } + virtual Poco::XML::Element *XMLGetFirstChild(Poco::XML::Node *parent, const std::string &name) + { + if(parent) + { + Poco::XML::Node *child=parent->firstChild(); + while(child && child->nodeName()!=name) + { + child=child->nextSibling(); + } + return static_cast(child); + } + else + { + return NULL; + } + } + + virtual Poco::XML::Element *XMLGetNextSibling(Poco::XML::Node *node, const std::string &name) + { + if(node) + { + Poco::XML::Node *next=node->nextSibling(); + while(next && next->nodeName()!=name) + { + next=next->nextSibling(); + } + return static_cast(next); + } + else + { + return NULL; + } + } + const std::string SanitizeSingleString(const std::string &text) { std::string returntext=text; @@ -101,6 +206,19 @@ protected: } return returntext; } + + const std::string GenerateXML(Poco::XML::Document *doc) + { + std::ostringstream str; + if(doc) + { + Poco::XML::DOMWriter dr; + dr.setOptions(Poco::XML::XMLWriter::WRITE_XML_DECLARATION | Poco::XML::XMLWriter::PRETTY_PRINT); + dr.setNewLine(Poco::XML::XMLWriter::NEWLINE_CRLF); + dr.writeNode(str,doc); + } + return str.str(); + } }; diff --git a/include/ilogger.h b/include/ilogger.h index b03499d..8617e9e 100644 --- a/include/ilogger.h +++ b/include/ilogger.h @@ -1,7 +1,8 @@ #ifndef _ilogger_ #define _ilogger_ -#include "logfile.h" +#include +#include /** \brief Base class for classes that want to use the singleton LogFile object @@ -9,10 +10,10 @@ class ILogger { public: - ILogger():m_log(LogFile::Instance()) {} + ILogger():m_log(&Poco::Util::ServerApplication::instance().logger()) {} protected: - LogFile *m_log; + Poco::Logger *m_log; }; #endif // _ilogger_ diff --git a/include/ipaddressacl.h b/include/ipaddressacl.h new file mode 100644 index 0000000..100392d --- /dev/null +++ b/include/ipaddressacl.h @@ -0,0 +1,41 @@ +#ifndef _ipaddressacl_ +#define _ipaddressacl_ + +#include +#include +#include + +class IPAddressACL +{ +public: + IPAddressACL(); + + const bool IsAllowed(const Poco::Net::IPAddress &addr); + const bool IsAllowed(const std::string &addrstr); + + const bool Add(const std::string &aclentry); + + void SetAllowByDefault(const bool allowbydefault) { m_allowbydefault=allowbydefault; } + const bool GetAllowByDefault() const { return m_allowbydefault; } + +private: + const std::string CreateMask(const int maskbits); + + // Poco 1.3.0 + has Poco::Net::IPAddress::mask - but 1.2.9 does not + Poco::Net::IPAddress MaskAddress(const Poco::Net::IPAddress &addr, const Poco::Net::IPAddress &mask); + + struct entry + { + entry(const bool allow, const Poco::Net::IPAddress &mask, const Poco::Net::IPAddress &addr):m_allow(allow),m_mask(mask),m_addr(addr) {} + bool m_allow; + Poco::Net::IPAddress m_mask; + Poco::Net::IPAddress m_addr; + }; + + bool m_allowbydefault; // allow or deny hosts if not explicitly defined + + std::vector m_entries; + +}; + +#endif // _acl_ diff --git a/include/logfile.h b/include/logfile.h deleted file mode 100644 index 92ab17f..0000000 --- a/include/logfile.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _logfile_ -#define _logfile_ - -//#include -//#include -#include "pthreadwrapper/mutex.h" -#include -#include "pthreadwrapper/singleton.h" - -class LogFile:public PThread::Singleton -{ -public: - LogFile(); - LogFile(const std::string &filename); - ~LogFile(); - - enum LogLevel - { - LOGLEVEL_FATAL=0, - LOGLEVEL_ERROR=1, - LOGLEVEL_WARNING=2, - LOGLEVEL_INFO=3, - LOGLEVEL_DEBUG=4 - }; - - bool OpenFile(); - bool CloseFile(); - - std::string GetFileName() { return m_filename; } - void SetFileName(std::string filename) { m_filename=filename; } - - const bool GetWriteDate() { return m_writedate; } - void SetWriteDate(const bool writedate) { m_writedate=writedate; } - - const bool GetWriteLogLevel() { return m_writeloglevel; } - void SetWriteLogLevel(const bool writeloglevel) { m_writeloglevel=writeloglevel; } - - const LogLevel GetLogLevel() { return m_loglevel; } - void SetLogLevel(const LogLevel loglevel) { m_loglevel=loglevel; } - - const bool GetWriteNewLine() { return m_writenewline; } - void SetWriteNewLine(const bool writenewline) { m_writenewline=writenewline; } - - void WriteLog(const char *format, ...); - void WriteLog(const std::string &text); - void WriteLog(const LogLevel level, const char *format, ...); - void WriteLog(const LogLevel level, const std::string &text); - - void WriteNewLine(); - -private: - void WriteDate(); - void WriteLogLevel(LogLevel level); - - FILE *m_fileptr; - std::string m_filename; - LogLevel m_loglevel; - bool m_writedate; - bool m_writeloglevel; - bool m_writenewline; - char *m_datebuffer; - - PThread::Mutex m_logmutex; - -}; - -#endif // _logfile_ diff --git a/include/message.h b/include/message.h index 4b4cb6e..cfc8734 100644 --- a/include/message.h +++ b/include/message.h @@ -3,7 +3,8 @@ #include "idatabase.h" #include "ilogger.h" -#include "datetime.h" + +#include class Message:public IDatabase,public ILogger { @@ -17,7 +18,7 @@ public: const std::string GetSubject() const { return m_subject; } const std::string GetBody() const { return m_body; } const std::string GetReplyBoardName() { return m_replyboardname; } - const DateTime GetDateTime() const { return m_datetime; } + const Poco::DateTime GetDateTime() const { return m_datetime; } const std::string GetFromName() const { return m_fromname; } std::vector GetBoards() const { return m_boards; } std::map GetInReplyTo() const { return m_inreplyto; } @@ -73,7 +74,7 @@ private: std::string m_subject; std::string m_body; std::string m_replyboardname; - DateTime m_datetime; + Poco::DateTime m_datetime; std::string m_fromname; std::vector m_boards; std::map m_inreplyto; diff --git a/include/nntp/nntpconnection.h b/include/nntp/nntpconnection.h index d116148..15c2080 100644 --- a/include/nntp/nntpconnection.h +++ b/include/nntp/nntpconnection.h @@ -1,6 +1,7 @@ #ifndef _nntpconnection_ #define _nntpconnection_ +#include "../threadwrapper/cancelablerunnable.h" #include "../socketdefines.h" #include "../ilogger.h" #include "../message.h" @@ -8,8 +9,6 @@ #include #include -//#include -#include "../pthreadwrapper/runnable.h" #ifdef _WIN32 @@ -22,7 +21,7 @@ #include #endif -class NNTPConnection:public PThread::Runnable,public ILogger +class NNTPConnection:public CancelableRunnable,public ILogger { public: NNTPConnection(SOCKET sock); @@ -31,7 +30,7 @@ public: void Disconnect(); const bool Disconnected() { return m_socket==INVALID_SOCKET; } - void Run(); + void run(); private: diff --git a/include/nntp/nntplistener.h b/include/nntp/nntplistener.h index 4e4d1ca..0bcca8f 100644 --- a/include/nntp/nntplistener.h +++ b/include/nntp/nntplistener.h @@ -3,34 +3,28 @@ #include #include -//#include -//#include -//#include -//#include -#include "../pthreadwrapper/runnable.h" -#include "../pthreadwrapper/threadedexecutor.h" - +#include "../threadwrapper/threadedexecutor.h" #include "../socketdefines.h" +#include "../ilogger.h" /** \brief Listens for NNTP connections */ -class NNTPListener:public PThread::Runnable +class NNTPListener:public CancelableRunnable,public ILogger { public: NNTPListener(); ~NNTPListener(); - void Run(); + void run(); void StartListen(); private: unsigned short m_listenport; std::vector m_listensockets; - //ZThread::ThreadedExecutor m_connections; - //std::vector m_connectionthreads; - PThread::ThreadedExecutor m_connections; + + ThreadedExecutor m_connections; }; diff --git a/include/option.h b/include/option.h index c18c716..c01621d 100644 --- a/include/option.h +++ b/include/option.h @@ -4,11 +4,10 @@ #include "db/sqlite3db.h" #include -//#include -#include "pthreadwrapper/singleton.h" +#include "threadwrapper/singleton.h" //just a wrapper around the database for the options table -class Option:public PThread::Singleton