From 4e96d123460d6363cf7274e36bd9357768eb86ad Mon Sep 17 00:00:00 2001 From: SomeDude Date: Sun, 4 Jan 2009 18:43:00 +0100 Subject: [PATCH] version 0.3.28 --- CMakeLists.txt | 37 +- include/db/sqlite3db/sqlite3db.h | 4 +- include/freenet/boardlistinserter.h | 6 +- include/freenet/boardlistrequester.h | 6 +- include/freenet/fcpv2.h | 290 ++++++++++-- include/freenet/fileinserter.h | 6 +- include/freenet/fmsversionrequester.h | 8 +- include/freenet/freenetmasterthread.h | 4 +- include/freenet/identityinserter.h | 4 +- include/freenet/identityintroductioninserter.h | 4 +- include/freenet/identityintroductionrequester.h | 8 +- include/freenet/identityrequester.h | 6 +- include/freenet/ifcpconnected.h | 8 +- include/freenet/ifcpmessagehandler.h | 2 +- include/freenet/iindexinserter.h | 12 +- include/freenet/iindexrequester.h | 20 +- include/freenet/inactivemessagelistrequester.h | 2 +- include/freenet/introductionpuzzleinserter.h | 6 +- include/freenet/introductionpuzzlerequester.h | 6 +- include/freenet/messageinserter.h | 6 +- include/freenet/messagelistinserter.h | 6 +- include/freenet/messagelistrequester.h | 8 +- include/freenet/messagerequester.h | 6 +- include/freenet/siteinserter.h | 6 +- include/freenet/trustlistinserter.h | 4 +- include/freenet/trustlistrequester.h | 6 +- include/freenet/unkeyedidcreator.h | 4 +- include/freenet/unknownidentityrequester.h | 2 +- include/global.h | 6 +- include/unicode/unicodeformatter.h | 2 +- include/unicode/utfconversion.h | 2 +- readme.txt | 19 +- src/freenet/boardlistinserter.cpp | 12 +- src/freenet/boardlistrequester.cpp | 23 +- src/freenet/fcpv2.cpp | 573 +++++++++++++----------- src/freenet/fileinserter.cpp | 12 +- src/freenet/fmsversionrequester.cpp | 25 +- src/freenet/freenetmasterthread.cpp | 32 +- src/freenet/identityinserter.cpp | 10 +- src/freenet/identityintroductioninserter.cpp | 15 +- src/freenet/identityintroductionrequester.cpp | 25 +- src/freenet/identityrequester.cpp | 23 +- src/freenet/inactivemessagelistrequester.cpp | 4 +- src/freenet/introductionpuzzleinserter.cpp | 18 +- src/freenet/introductionpuzzlerequester.cpp | 23 +- src/freenet/messageinserter.cpp | 12 +- src/freenet/messagelistinserter.cpp | 18 +- src/freenet/messagelistrequester.cpp | 29 +- src/freenet/messagerequester.cpp | 23 +- src/freenet/siteinserter.cpp | 12 +- src/freenet/trustlistinserter.cpp | 16 +- src/freenet/trustlistrequester.cpp | 23 +- src/freenet/unkeyedidcreator.cpp | 8 +- src/freenet/unknownidentityrequester.cpp | 2 +- src/http/pages/forumviewthreadpage.cpp | 39 +- src/unicode/unicodeformatter.cpp | 6 +- src/unicode/utfconversion.cpp | 32 +- 57 files changed, 870 insertions(+), 661 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c9997e..6412e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ ENDIF(COMMAND CMAKE_POLICY) PROJECT(fms) -OPTION(USE_BUNDLED_SQLITE "Use the bundled SQLite3 library." OFF) +OPTION(USE_BUNDLED_SQLITE "Use the bundled SQLite3 library." ON) IF(APPLE) SET(USE_BUNDLED_SQLITE ON) ENDIF(APPLE) @@ -131,11 +131,27 @@ 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) +# Get a relative list of include files. +FILE(GLOB_RECURSE FMS_INC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h) + +# Create source groups for all sources and includes, in their original directory structure. +FOREACH(SRC ${FMS_SRC} ${FMS_INC}) + STRING(REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "Files" REL_DIR "${SRC}") + STRING(REGEX REPLACE "[\\\\/][^\\\\/]*$" "" REL_DIR "${REL_DIR}") + STRING(REGEX REPLACE "^[\\\\/]" "" REL_DIR "${REL_DIR}") + IF(REL_DIR) + STRING(REPLACE "/" "\\" REL_DIR "${REL_DIR}") + SOURCE_GROUP(${REL_DIR} FILES ${SRC}) + ELSE(REL_DIR) + SOURCE_GROUP(Files FILES ${SRC}) + ENDIF(REL_DIR) +ENDFOREACH(SRC) + 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_EXECUTABLE(fms ${FMS_SRC} ${FMS_PLATFORM_SRC}) +ADD_EXECUTABLE(fms ${FMS_SRC} ${FMS_PLATFORM_SRC} ${FMS_INC}) # link dl - For SQLite3 and shttpd - not for FreeBSD IF(CMAKE_COMPILER_IS_GNUCC) @@ -181,23 +197,32 @@ IF(ALTERNATE_CAPTCHA) ENDIF(ALTERNATE_CAPTCHA) IF(POCO_FOUNDATION_LIBRARY) - TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY}) + # We don't need to explicitly link under MSVC, POCO uses #pragmas to specify linked libraries. + IF(NOT MSVC) + TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY}) + ENDIF(NOT MSVC) ADD_DEFINITIONS(-DPOCO_HAVE_IPv6) IF(WIN32) ADD_DEFINITIONS(-DPOCO_STATIC) ENDIF(WIN32) IF(POCO_UTIL_LIBRARY) - TARGET_LINK_LIBRARIES(fms ${POCO_UTIL_LIBRARY}) + IF(NOT MSVC) + TARGET_LINK_LIBRARIES(fms ${POCO_UTIL_LIBRARY}) + ENDIF(NOT MSVC) 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}) + IF(NOT MSVC) + TARGET_LINK_LIBRARIES(fms ${POCO_NET_LIBRARY}) + ENDIF(NOT MSVC) 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}) + IF(NOT MSVC) + TARGET_LINK_LIBRARIES(fms ${POCO_XML_LIBRARY}) + ENDIF(NOT MSVC) ELSE(POCO_XML_LIBRARY) MESSAGE(FATAL_ERROR "Could not find system Poco XML library. You must set the location manually.") ENDIF(POCO_XML_LIBRARY) diff --git a/include/db/sqlite3db/sqlite3db.h b/include/db/sqlite3db/sqlite3db.h index 8c2ee39..f60961b 100644 --- a/include/db/sqlite3db/sqlite3db.h +++ b/include/db/sqlite3db/sqlite3db.h @@ -7,8 +7,8 @@ #include "../sqlite3db.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." +#if SQLITE_VERSION_NUMBER<3006006 +#error "Your version of SQLite is too old! 3.6.6.2 or later is required." #endif namespace SQLite3DB diff --git a/include/freenet/boardlistinserter.h b/include/freenet/boardlistinserter.h index d041cdb..f0883a1 100644 --- a/include/freenet/boardlistinserter.h +++ b/include/freenet/boardlistinserter.h @@ -7,12 +7,12 @@ class BoardListInserter:public IIndexInserter { public: BoardListInserter(); - BoardListInserter(FCPv2 *fcp); + BoardListInserter(FCPv2::Connection *fcp); private: void Initialize(); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); const bool StartInsert(const long &localidentityid); void CheckForNeededInsert(); }; diff --git a/include/freenet/boardlistrequester.h b/include/freenet/boardlistrequester.h index b2cacb2..3eb7823 100644 --- a/include/freenet/boardlistrequester.h +++ b/include/freenet/boardlistrequester.h @@ -7,14 +7,14 @@ class BoardListRequester:public IIndexRequester { public: BoardListRequester(); - BoardListRequester(FCPv2 *fcp); + BoardListRequester(FCPv2::Connection *fcp); private: void Initialize(); void PopulateIDList(); void StartRequest(const long &identityid); - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); std::string GetIdentityName(const long identityid); diff --git a/include/freenet/fcpv2.h b/include/freenet/fcpv2.h index 864b14f..1f033a9 100644 --- a/include/freenet/fcpv2.h +++ b/include/freenet/fcpv2.h @@ -1,14 +1,24 @@ -/* +/** + + \mainpage FCPv2 library FCPv2 C++ library - link with ws2_32.lib in Windows + link with ws2_32.lib and iphlpapi.lib in Windows + +*/ +/** + \file fcpv2.h */ #ifndef _fcpv2_ #define _fcpv2_ +#include +#include +#include + #ifdef _WIN32 #include #include @@ -19,74 +29,276 @@ #include #endif -#include -#include -#include +/** + \brief %FCPv2 namespace + This namespace contains the %FCPv2 library +*/ +namespace FCPv2 +{ -class FCPMessage:public std::map +/** + \brief An FCP message + + FCP Messages are comprised of a name and zero or more field/value pairs. +*/ +class Message { public: - FCPMessage() {}; - FCPMessage(const std::string &name) {m_name=name;} + /** + \brief Default constructor + */ + Message(); + /** + \brief Construct message with a specific name + + \param name The name of the message + */ + Message(const std::string &name); + /** + \brief Construct message with a specific name and fields - const std::string GetName() const { return m_name; } - void SetName(const std::string &name) { m_name=name; } + The number of field/value pairs must match the fieldcount parameter. + + \param name The name of the message + \param fieldcount The number of field/value pairs that follow + */ + Message(const std::string &name, const int fieldcount, ...); + + /** + \brief Gets the name of the message + + \return The name of the message + */ + const std::string &GetName() const { return m_name; } + /** + \brief Sets the name of the message + + \param name The name of the message + */ + void SetName(const std::string &name) { m_name=name; } + + /** + \brief Accesses the field/value pairs + + \param field The field to access + \return Reference to the value of the field + */ + std::string &operator[](const std::string &field) { return m_fields[field]; } + + /** + \brief Non-const accessor for field map + + \return field map + */ + std::map &GetFields() { return m_fields; } + /** + \brief Const accessor for field map + + \return field map + */ + const std::map &GetFields() const { return m_fields; } + + /** + \brief Clears the name and fields of the message + */ + void Clear() { m_name=""; m_fields.clear(); } + + const bool operator==(const Message &rhs) const { return (m_name==rhs.m_name && m_fields==rhs.m_fields); } + const bool operator!=(const Message &rhs) const { return !(*this==rhs); } + const bool operator<(const Message &rhs) const { return (m_name(const Message &rhs) const { return !(*this<=rhs); } + const bool operator>=(const Message &rhs) const { return !(*this m_fields; + }; -class FCPv2 +/** + \brief An FCP connection to a Freenet node +*/ +class Connection { public: - FCPv2(); - ~FCPv2(); + /** + \brief Default constructor + */ + Connection(); + /** + \brief Construct connection with an existing socket + + \param sock An existing socket connection to a Freenet node + */ + Connection(const int sock); + /** + \brief Default constructor + + The deconstructor will close the connection if it is open + */ + ~Connection(); + + /** + \brief Creates an FCP connection to a Freenet node + + If the instaciated object has an existing connection open, it will be closed. + + \param fcphost The IP Address, hostname, FQDN, or other resolvable name that points to the Freenet node + \param fcpport The port that the Freenet node is listening for FCP connections on + \return true if the connection was established, false if it was not + */ + const bool Connect(const std::string &fcphost, const int fcpport); + /** + \brief Checks if the connection is currently connected + + \return true if there is a connection, false if there is not + */ + const bool IsConnected() const { return m_socket!=-1; } + /** + \brief Disconnects the connection - const bool Connect(const char *host, const int port); + \return always true + */ const bool Disconnect(); + + /** + \brief Sends and receives data on the connection + + \param ms Maximum number of milliseconds to wait for the send and receive buffers to become available + \return true if the connection remains connected, false if the connection is disconnected + */ + const bool Update(const unsigned long ms); - const bool Connected() const { return m_serversocket!=-1 ? true : false ; } + /** + \brief Checks if an FCP message is ready to be received - const bool Update(const long waittime); + \return true if an FCP message is ready to be received, false otherwise + */ + const bool MessageReady() const; + + /** + \brief Gets the number of bytes on the receive buffer - const int SendMessage(const char *messagename, const int fieldcount, ...); - const int SendMessage(FCPMessage &message); - const int SendRaw(const char *data, const int datalen); - const std::vector::size_type SendBufferSize() const { return m_sendbuffer.size(); } + \return The number of bytes on the receive buffer + */ + const std::vector::size_type ReceiveBufferSize() const { return m_receivebuffer.size(); } + /** + \brief Receives an FCP message + + \param[out] message The FCP message + \return true if an FCP message was received, false otherwise + */ + const bool Receive(Message &message); + /** + \brief Receives raw data + + The received data is inserted at the end of the supplied vector - FCPMessage ReceiveMessage(); - const long ReceiveRaw(char *data, long &datalen); // data must be preallocated, with datalen being max length of data. Returns length of data received - const std::vector::size_type ReceiveBufferSize() const { return m_receivebuffer.size(); } + \param[out] data vector to place received data in + \param len number of bytes to receive + \return true if the bytes were received, false otherwise + */ + const bool Receive(std::vector &data, const std::vector::size_type len); + /** + \brief Receives raw data -private: + \param[out] data char array to place received data in + \param len number of bytes to receive + \return true if the bytes were received, false otherwise + */ + const bool Receive(char *data, const size_t len); + /** + \brief Discards data on receive buffer + + \param len The number of bytes on the receive buffer to discard + \return true if the bytes were discarded, false otherwise + */ + const bool ReceiveIgnore(const size_t len); - void SocketReceive(); - void SocketSend(); + /** + \brief Gets the number of bytes waiting to be sent to the node + + \return The number of bytes waiting to be sent to the node + */ + const std::vector::size_type SendBufferSize() const { return m_sendbuffer.size(); } + /** + \brief Sends an FCP Message + + \param message The Message to send + \return true if the Message was buffered for sending successfully, false otherwise + */ + const bool Send(const Message &message); + /** + \brief Sends raw data - void SendBufferedText(const char *text); // puts text on send buffer - void SendBufferedRaw(const char *data, const long len); // puts raw data on send buffer + \param data A vector of the data to send + \return true if the data was buffered for sending successfully, false otherwise + */ + const bool Send(const std::vector &data); + /** + \brief Sends raw data - int FindOnReceiveBuffer(const char *text); // finds text string on receive buffer and returns index to first char position, -1 if not found + \param data A char array of data to send + \param len The number of bytes on the array to send + \return true if the data was buffered for sending successfully, false otherwise + */ + const bool Send(const char *data, const size_t len); + /** + \brief Gets the socket identifier of the connection + + \return The socket identifier. It will be -1 if the socket is invalid. + */ + const int Socket() { return m_socket; } + + /** + \brief Waits until the receive buffer contains a specified number of bytes + + This will continuously call Update until either the specific number of bytes have been received, + or the connection becomes disconnected + + \param ms The number of milliseconds for each call to Update + \param len The number of bytes to wait for + \return true if the number of bytes is waiting on the receive buffer, false if the connection was closed + */ + const bool WaitForBytes(const unsigned long ms, const size_t len); + +private: + // can't be copied + Connection(const Connection &connection); + Connection &operator=(const Connection &connection); + + const bool MessageReady(std::vector::const_iterator &endpos, std::vector::size_type &endlen) const; + const bool MessageReady(std::vector::iterator &endpos, std::vector::size_type &endlen); + void Split(const std::string &str, const std::string &separators, std::vector &elements); + + void DoSend(); + void DoReceive(); #ifdef _WIN32 static bool m_wsastartup; #endif - int m_serversocket; - - char *m_tempbuffer; // temp buffer used for recv - - std::vector m_sendbuffer; + int m_socket; std::vector m_receivebuffer; - + std::vector m_sendbuffer; + std::vector m_tempbuffer; fd_set m_readfs; fd_set m_writefs; struct timeval m_timeval; - + }; -#endif // _fcpv2_ +} // namespace + +#endif // _fcpv2_connection_ diff --git a/include/freenet/fileinserter.h b/include/freenet/fileinserter.h index c02b0ea..6ac76bd 100644 --- a/include/freenet/fileinserter.h +++ b/include/freenet/fileinserter.h @@ -7,12 +7,12 @@ class FileInserter:public IIndexInserter { public: FileInserter(); - FileInserter(FCPv2 *fcp); + FileInserter(FCPv2::Connection *fcp); private: void Initialize(); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); const bool StartInsert(const long &fileinsertid); void CheckForNeededInsert(); diff --git a/include/freenet/fmsversionrequester.h b/include/freenet/fmsversionrequester.h index 6a6d5f7..afe18ca 100644 --- a/include/freenet/fmsversionrequester.h +++ b/include/freenet/fmsversionrequester.h @@ -14,19 +14,19 @@ class FMSVersionRequester:public IFreenetRegistrable,public IFCPConnected,public { public: FMSVersionRequester(); - FMSVersionRequester(FCPv2 *fcp); + FMSVersionRequester(FCPv2::Connection *fcp); void FCPConnected() {} void FCPDisconnected() {} - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void Process(); void RegisterWithThread(FreenetMasterThread *thread); private: - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); void Initialize(); void StartRequest(); diff --git a/include/freenet/freenetmasterthread.h b/include/freenet/freenetmasterthread.h index f604fde..3e9cae5 100644 --- a/include/freenet/freenetmasterthread.h +++ b/include/freenet/freenetmasterthread.h @@ -18,7 +18,7 @@ public: FreenetMasterThread(); ~FreenetMasterThread(); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void run(); @@ -34,7 +34,7 @@ private: std::string m_fcphost; int m_fcpport; - FCPv2 m_fcp; + FCPv2::Connection m_fcp; std::vector m_registrables; std::vector m_processors; std::vector m_fcpconnected; diff --git a/include/freenet/identityinserter.h b/include/freenet/identityinserter.h index e0e974d..1170e99 100644 --- a/include/freenet/identityinserter.h +++ b/include/freenet/identityinserter.h @@ -14,12 +14,12 @@ class IdentityInserter:public IFreenetRegistrable,public IFCPConnected,public IF { public: IdentityInserter(); - IdentityInserter(FCPv2 *fcp); + IdentityInserter(FCPv2::Connection *fcp); void FCPConnected(); void FCPDisconnected(); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void Process(); diff --git a/include/freenet/identityintroductioninserter.h b/include/freenet/identityintroductioninserter.h index 17c3728..77f2bba 100644 --- a/include/freenet/identityintroductioninserter.h +++ b/include/freenet/identityintroductioninserter.h @@ -14,12 +14,12 @@ class IdentityIntroductionInserter:public IFreenetRegistrable,public IFCPConnect { public: IdentityIntroductionInserter(); - IdentityIntroductionInserter(FCPv2 *fcp); + IdentityIntroductionInserter(FCPv2::Connection *fcp); void FCPConnected(); void FCPDisconnected(); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void Process(); diff --git a/include/freenet/identityintroductionrequester.h b/include/freenet/identityintroductionrequester.h index f6dac85..cd66727 100644 --- a/include/freenet/identityintroductionrequester.h +++ b/include/freenet/identityintroductionrequester.h @@ -14,11 +14,11 @@ class IdentityIntroductionRequester:public IFreenetRegistrable,public IFCPConnec { public: IdentityIntroductionRequester(); - IdentityIntroductionRequester(FCPv2 *fcp); + IdentityIntroductionRequester(FCPv2::Connection *fcp); void FCPDisconnected(); void FCPConnected(); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void Process(); @@ -30,8 +30,8 @@ private: void StartRequest(const std::string &UUID); void PopulateIDList(); void RemoveFromRequestList(const std::string &UUID); - const bool HandleGetFailed(FCPMessage &message); - const bool HandleAllData(FCPMessage &message); + const bool HandleGetFailed(FCPv2::Message &message); + const bool HandleAllData(FCPv2::Message &message); Poco::DateTime m_tempdate; std::map m_ids; diff --git a/include/freenet/identityrequester.h b/include/freenet/identityrequester.h index b371d11..0b70abd 100644 --- a/include/freenet/identityrequester.h +++ b/include/freenet/identityrequester.h @@ -7,14 +7,14 @@ class IdentityRequester:public IIndexRequester { public: IdentityRequester(); - IdentityRequester(FCPv2 *fcp); + IdentityRequester(FCPv2::Connection *fcp); private: virtual void Initialize(); virtual void PopulateIDList(); // clear and re-populate m_ids with identities we want to query void StartRequest(const long &identityid); - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); }; diff --git a/include/freenet/ifcpconnected.h b/include/freenet/ifcpconnected.h index 19bea17..9ecf015 100644 --- a/include/freenet/ifcpconnected.h +++ b/include/freenet/ifcpconnected.h @@ -10,10 +10,10 @@ class IFCPConnected { public: IFCPConnected():m_fcp(NULL) {} - IFCPConnected(FCPv2 *fcp):m_fcp(fcp) {} + IFCPConnected(FCPv2::Connection *fcp):m_fcp(fcp) {} - virtual void SetFCPConnection(FCPv2 *fcp) { m_fcp=fcp; } - virtual FCPv2 *GetFCPConnection() { return m_fcp; } + virtual void SetFCPConnection(FCPv2::Connection *fcp) { m_fcp=fcp; } + virtual FCPv2::Connection *GetFCPConnection() { return m_fcp; } /** \brief called when the FCP connection becomes disconnected @@ -29,7 +29,7 @@ public: virtual void FCPConnected()=0; protected: - FCPv2 *m_fcp; + FCPv2::Connection *m_fcp; }; #endif // _ifcpconnected_ diff --git a/include/freenet/ifcpmessagehandler.h b/include/freenet/ifcpmessagehandler.h index 01525d7..30147ba 100644 --- a/include/freenet/ifcpmessagehandler.h +++ b/include/freenet/ifcpmessagehandler.h @@ -14,7 +14,7 @@ public: \param message FCP message to handle \return true if the message was handled, false if it was not */ - virtual const bool HandleMessage(FCPMessage &message)=0; + virtual const bool HandleMessage(FCPv2::Message &message)=0; }; #endif // _ifcpmessagehandler_ diff --git a/include/freenet/iindexinserter.h b/include/freenet/iindexinserter.h index ba5c988..fb65b0e 100644 --- a/include/freenet/iindexinserter.h +++ b/include/freenet/iindexinserter.h @@ -23,12 +23,12 @@ class IIndexInserter:public IFreenetRegistrable,public IFCPConnected,public IFCP { public: IIndexInserter(); - IIndexInserter(FCPv2 *fcp); + IIndexInserter(FCPv2::Connection *fcp); virtual ~IIndexInserter() {} virtual void FCPConnected(); virtual void FCPDisconnected(); - virtual const bool HandleMessage(FCPMessage &message); + virtual const bool HandleMessage(FCPv2::Message &message); virtual void Process(); @@ -37,8 +37,8 @@ public: protected: void InitializeIIndexInserter(); virtual void Initialize()=0; // initialize m_fcpuniquename - virtual const bool HandlePutSuccessful(FCPMessage &message)=0; - virtual const bool HandlePutFailed(FCPMessage &message)=0; + virtual const bool HandlePutSuccessful(FCPv2::Message &message)=0; + virtual const bool HandlePutFailed(FCPv2::Message &message)=0; virtual const bool StartInsert(const IDTYPE &id)=0; virtual void CheckForNeededInsert()=0; virtual void RemoveFromInsertList(const IDTYPE id); @@ -58,7 +58,7 @@ IIndexInserter::IIndexInserter() } template -IIndexInserter::IIndexInserter(FCPv2 *fcp):IFCPConnected(fcp) +IIndexInserter::IIndexInserter(FCPv2::Connection *fcp):IFCPConnected(fcp) { InitializeIIndexInserter(); } @@ -86,7 +86,7 @@ void IIndexInserter::FCPDisconnected() } template -const bool IIndexInserter::HandleMessage(FCPMessage &message) +const bool IIndexInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find(m_fcpuniquename)==0) diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 6173868..37dcdda 100644 --- a/include/freenet/iindexrequester.h +++ b/include/freenet/iindexrequester.h @@ -25,12 +25,12 @@ class IIndexRequester:public IFreenetRegistrable,public IFCPConnected,public IFC { public: IIndexRequester(); - IIndexRequester(FCPv2 *fcp); + IIndexRequester(FCPv2::Connection *fcp); virtual ~IIndexRequester() {} virtual void FCPConnected(); virtual void FCPDisconnected(); - virtual const bool HandleMessage(FCPMessage &message); + virtual const bool HandleMessage(FCPv2::Message &message); virtual void Process(); @@ -41,8 +41,8 @@ protected: virtual void Initialize()=0; // initialize m_maxrequests and m_fcpuniquename virtual void PopulateIDList()=0; virtual void StartRequest(const IDTYPE &id)=0; - virtual const bool HandleAllData(FCPMessage &message)=0; - virtual const bool HandleGetFailed(FCPMessage &message)=0; + virtual const bool HandleAllData(FCPv2::Message &message)=0; + virtual const bool HandleGetFailed(FCPv2::Message &message)=0; virtual void RemoveFromRequestList(const IDTYPE id); Poco::DateTime m_tempdate; @@ -65,7 +65,7 @@ IIndexRequester::IIndexRequester() } template -IIndexRequester::IIndexRequester(FCPv2 *fcp):IFCPConnected(fcp) +IIndexRequester::IIndexRequester(FCPv2::Connection *fcp):IFCPConnected(fcp) { InitializeIIndexRequester(); } @@ -100,7 +100,7 @@ void IIndexRequester::FCPDisconnected() } template -const bool IIndexRequester::HandleMessage(FCPMessage &message) +const bool IIndexRequester::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find(m_fcpuniquename)==0) @@ -210,14 +210,6 @@ void IIndexRequester::RegisterWithThread(FreenetMasterThread *thread) template void IIndexRequester::RemoveFromRequestList(const IDTYPE id) { -/* - typename std::vector::iterator i=m_requesting.begin(); - while(i!=m_requesting.end() && (*i)!=id) - { - i++; - } -*/ - // better typename std::vector::iterator i=std::find(m_requesting.begin(),m_requesting.end(),id); if(i!=m_requesting.end()) diff --git a/include/freenet/inactivemessagelistrequester.h b/include/freenet/inactivemessagelistrequester.h index 8891fec..f7787a9 100644 --- a/include/freenet/inactivemessagelistrequester.h +++ b/include/freenet/inactivemessagelistrequester.h @@ -9,7 +9,7 @@ class InactiveMessageListRequester:public MessageListRequester { public: InactiveMessageListRequester(); - InactiveMessageListRequester(FCPv2 *fcp); + InactiveMessageListRequester(FCPv2::Connection *fcp); private: virtual void Initialize(); diff --git a/include/freenet/introductionpuzzleinserter.h b/include/freenet/introductionpuzzleinserter.h index 9cd88e3..a65d96d 100644 --- a/include/freenet/introductionpuzzleinserter.h +++ b/include/freenet/introductionpuzzleinserter.h @@ -10,15 +10,15 @@ class IntroductionPuzzleInserter:public IIndexInserter { public: IntroductionPuzzleInserter(); - IntroductionPuzzleInserter(FCPv2 *fcp); + IntroductionPuzzleInserter(FCPv2::Connection *fcp); private: void Initialize(); void CheckForNeededInsert(); const bool StartInsert(const long &localidentityid); void GenerateCaptcha(std::string &encodeddata, std::string &solution); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); Poco::DateTime m_lastchecked; int m_maxpuzzleinserts; diff --git a/include/freenet/introductionpuzzlerequester.h b/include/freenet/introductionpuzzlerequester.h index dc24327..e2ca076 100644 --- a/include/freenet/introductionpuzzlerequester.h +++ b/include/freenet/introductionpuzzlerequester.h @@ -9,14 +9,14 @@ class IntroductionPuzzleRequester:public IIndexRequester { public: IntroductionPuzzleRequester(); - IntroductionPuzzleRequester(FCPv2 *fcp); + IntroductionPuzzleRequester(FCPv2::Connection *fcp); private: void Initialize(); void StartRequest(const long &identityid); void PopulateIDList(); // clear and re-populate m_ids with identities we want to query - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); }; diff --git a/include/freenet/messageinserter.h b/include/freenet/messageinserter.h index a73813e..04d6169 100644 --- a/include/freenet/messageinserter.h +++ b/include/freenet/messageinserter.h @@ -8,12 +8,12 @@ class MessageInserter:public IIndexInserter { public: MessageInserter(); - MessageInserter(FCPv2 *fcp); + MessageInserter(FCPv2::Connection *fcp); private: void Initialize(); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); const bool StartInsert(const std::string &messageuuid); void CheckForNeededInsert(); diff --git a/include/freenet/messagelistinserter.h b/include/freenet/messagelistinserter.h index 8658960..4afed68 100644 --- a/include/freenet/messagelistinserter.h +++ b/include/freenet/messagelistinserter.h @@ -7,12 +7,12 @@ class MessageListInserter:public IIndexInserter { public: MessageListInserter(); - MessageListInserter(FCPv2 *fcp); + MessageListInserter(FCPv2::Connection *fcp); private: void Initialize(); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); const bool StartInsert(const long &localidentityid); void CheckForNeededInsert(); diff --git a/include/freenet/messagelistrequester.h b/include/freenet/messagelistrequester.h index ccd463c..1b324e2 100644 --- a/include/freenet/messagelistrequester.h +++ b/include/freenet/messagelistrequester.h @@ -9,15 +9,15 @@ class MessageListRequester:public IIndexRequester { public: MessageListRequester(); - MessageListRequester(FCPv2 *fcp); + MessageListRequester(FCPv2::Connection *fcp); private: virtual void Initialize(); virtual void PopulateIDList(); void StartRequest(const long &id); - void StartRedirectRequest(FCPMessage &message); - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + void StartRedirectRequest(FCPv2::Message &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); void GetBoardList(std::map &boards); const bool CheckDateNotFuture(const std::string &datestr) const; const bool CheckDateWithinMaxDays(const std::string &datestr) const; diff --git a/include/freenet/messagerequester.h b/include/freenet/messagerequester.h index d458ccb..76feb71 100644 --- a/include/freenet/messagerequester.h +++ b/include/freenet/messagerequester.h @@ -7,14 +7,14 @@ class MessageRequester:public IIndexRequester { public: MessageRequester(); - MessageRequester(FCPv2 *fcp); + MessageRequester(FCPv2::Connection *fcp); private: void Initialize(); void PopulateIDList(); void StartRequest(const std::string &requestid); - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); const long GetBoardID(const std::string &boardname, const std::string &identityname); const bool SaveToBoard(const std::string &boardname); diff --git a/include/freenet/siteinserter.h b/include/freenet/siteinserter.h index a24f3a5..5c17e79 100644 --- a/include/freenet/siteinserter.h +++ b/include/freenet/siteinserter.h @@ -7,12 +7,12 @@ class SiteInserter:public IIndexInserter { public: SiteInserter(); - SiteInserter(FCPv2 *fcp); + SiteInserter(FCPv2::Connection *fcp); private: void Initialize(); - const bool HandlePutSuccessful(FCPMessage &message); - const bool HandlePutFailed(FCPMessage &message); + const bool HandlePutSuccessful(FCPv2::Message &message); + const bool HandlePutFailed(FCPv2::Message &message); const bool StartInsert(const long &localidentityid); void CheckForNeededInsert(); const std::string SanitizeOutput(const std::string &input); diff --git a/include/freenet/trustlistinserter.h b/include/freenet/trustlistinserter.h index 6c5003a..26cdd52 100644 --- a/include/freenet/trustlistinserter.h +++ b/include/freenet/trustlistinserter.h @@ -14,12 +14,12 @@ class TrustListInserter:public IFreenetRegistrable,public IFCPConnected,public I { public: TrustListInserter(); - TrustListInserter(FCPv2 *fcp); + TrustListInserter(FCPv2::Connection *fcp); void FCPConnected(); void FCPDisconnected(); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void Process(); diff --git a/include/freenet/trustlistrequester.h b/include/freenet/trustlistrequester.h index 516f3f5..0bbf69f 100644 --- a/include/freenet/trustlistrequester.h +++ b/include/freenet/trustlistrequester.h @@ -7,14 +7,14 @@ class TrustListRequester:public IIndexRequester//public IFreenetRegistrabl { public: TrustListRequester(); - TrustListRequester(FCPv2 *fcp); + TrustListRequester(FCPv2::Connection *fcp); private: void Initialize(); void PopulateIDList(); // clear and re-populate m_ids with identities we want to query void StartRequest(const long &identityid); - const bool HandleAllData(FCPMessage &message); - const bool HandleGetFailed(FCPMessage &message); + const bool HandleAllData(FCPv2::Message &message); + const bool HandleGetFailed(FCPv2::Message &message); }; diff --git a/include/freenet/unkeyedidcreator.h b/include/freenet/unkeyedidcreator.h index d0db037..054a95d 100644 --- a/include/freenet/unkeyedidcreator.h +++ b/include/freenet/unkeyedidcreator.h @@ -18,9 +18,9 @@ class UnkeyedIDCreator:public IFreenetRegistrable,public IFCPConnected,public IF { public: UnkeyedIDCreator(); - UnkeyedIDCreator(FCPv2 *fcp); + UnkeyedIDCreator(FCPv2::Connection *fcp); - const bool HandleMessage(FCPMessage &message); + const bool HandleMessage(FCPv2::Message &message); void FCPDisconnected(); void FCPConnected(); diff --git a/include/freenet/unknownidentityrequester.h b/include/freenet/unknownidentityrequester.h index 883f183..67c8372 100644 --- a/include/freenet/unknownidentityrequester.h +++ b/include/freenet/unknownidentityrequester.h @@ -7,7 +7,7 @@ class UnknownIdentityRequester:public IdentityRequester { public: UnknownIdentityRequester(); - UnknownIdentityRequester(FCPv2 *fcp); + UnknownIdentityRequester(FCPv2::Connection *fcp); private: void Initialize(); diff --git a/include/global.h b/include/global.h index e453851..eb0deae 100644 --- a/include/global.h +++ b/include/global.h @@ -7,10 +7,10 @@ #define VERSION_MAJOR "0" #define VERSION_MINOR "3" -#define VERSION_RELEASE "27" +#define VERSION_RELEASE "28" #define FMS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_RELEASE -#define FMS_FREESITE_USK "USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/89/" -#define FMS_VERSION_EDITION "29" +#define FMS_FREESITE_USK "USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/90/" +#define FMS_VERSION_EDITION "30" typedef Poco::ScopedLock Guard; diff --git a/include/unicode/unicodeformatter.h b/include/unicode/unicodeformatter.h index 1f2d31c..0194b02 100644 --- a/include/unicode/unicodeformatter.h +++ b/include/unicode/unicodeformatter.h @@ -12,7 +12,7 @@ public: private: static std::wstring m_unicodenewline; - static wchar_t m_unicodewhitespace[]; + static std::wstring::value_type m_unicodewhitespace[]; }; diff --git a/include/unicode/utfconversion.h b/include/unicode/utfconversion.h index 2ebe864..d5eb77d 100644 --- a/include/unicode/utfconversion.h +++ b/include/unicode/utfconversion.h @@ -15,7 +15,7 @@ namespace UTFConversion { // UTF-8 byte sequence to UTF-16 or UTF-32, depending on size of wchar_t -const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring); +const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring); const bool FromUTF8(const std::string &utf8string, std::wstring &wcstring); // UTF-16 or UTF-32 to UTF-8 byte sequence const bool ToUTF8(const std::wstring &wcstring, std::string &utf8string); diff --git a/readme.txt b/readme.txt index 4968c47..5e5cf8c 100644 --- a/readme.txt +++ b/readme.txt @@ -7,13 +7,13 @@ To compile, run these commands from the source directory: cmake -D I_HAVE_READ_THE_README=ON . make -If you want to use the bundled SQLite3 library, add a -D USE_BUNDLED_SQLITE=ON -to the cmake command. Use of the bundled SQLite3 library is on by default when -compiling on a Mac. To turn off charset conversion to UTF-8 when sending -messages, add a -D DO_CHARSET_CONVERSION=OFF. Compiling with charset -conversion turned on is recommended. If you would like to compile using the -alternate captchas, add a -D ALTERNATE_CAPTCHA=ON to the cmake command line. -This option requires the FreeImage library to be installed. +Compiling with the bundled SQLite library is on by default. If you do not want +to use the bundled SQLite library, add a -D USE_BUNDLED_SQLITE=OFF to the cmake +command. To turn off charset conversion to UTF-8 when sending messages, add a +-D DO_CHARSET_CONVERSION=OFF. Compiling with charset conversion turned on is +recommended. If you would like to compile using the alternate captchas, add a +-D ALTERNATE_CAPTCHA=ON to the cmake command line. This option requires the +FreeImage library to be installed. UPGRADING --------- @@ -42,6 +42,11 @@ argument when installing the service to set the service name to whatever you want. You will need to manually start the service unless you change the startup type in the service properties. +FMS must run a good portion of the day every day to work properly. The slower +your Freenet connection is, the longer FMS must be run to find the +communications of other identities. You will not have a good experience only +running FMS a few hours a day. + If you are experiencing a problem with FMS that you can't solve, and you've already rebooted your machine, restarted FMS, and have reproduced the problem with a brand new database, follow these instructions. Set the logging option diff --git a/src/freenet/boardlistinserter.cpp b/src/freenet/boardlistinserter.cpp index 69ca362..a3b9b22 100644 --- a/src/freenet/boardlistinserter.cpp +++ b/src/freenet/boardlistinserter.cpp @@ -14,7 +14,7 @@ BoardListInserter::BoardListInserter() Initialize(); } -BoardListInserter::BoardListInserter(FCPv2 *fcp):IIndexInserter(fcp) +BoardListInserter::BoardListInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -45,7 +45,7 @@ void BoardListInserter::CheckForNeededInsert() } } -const bool BoardListInserter::HandlePutFailed(FCPMessage &message) +const bool BoardListInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long localidentityid; @@ -69,7 +69,7 @@ const bool BoardListInserter::HandlePutFailed(FCPMessage &message) return true; } -const bool BoardListInserter::HandlePutSuccessful(FCPMessage &message) +const bool BoardListInserter::HandlePutSuccessful(FCPv2::Message &message) { Poco::DateTime now; std::vector idparts; @@ -108,7 +108,7 @@ const bool BoardListInserter::StartInsert(const long &localidentityid) Poco::DateTime daysback; Poco::DateTime now; BoardListXML xml; - FCPMessage message; + FCPv2::Message message; std::string data; std::string datasizestr; std::string privatekey=""; @@ -172,8 +172,8 @@ const bool BoardListInserter::StartInsert(const long &localidentityid) message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); m_inserting.push_back(localidentityid); diff --git a/src/freenet/boardlistrequester.cpp b/src/freenet/boardlistrequester.cpp index abcc473..21e82b7 100644 --- a/src/freenet/boardlistrequester.cpp +++ b/src/freenet/boardlistrequester.cpp @@ -13,7 +13,7 @@ BoardListRequester::BoardListRequester() Initialize(); } -BoardListRequester::BoardListRequester(FCPv2 *fcp):IIndexRequester(fcp) +BoardListRequester::BoardListRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } @@ -48,7 +48,7 @@ std::string BoardListRequester::GetIdentityName(const long identityid) } } -const bool BoardListRequester::HandleAllData(FCPMessage &message) +const bool BoardListRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -68,23 +68,16 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) identityname=GetIdentityName(identityid); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -163,7 +156,7 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) } -const bool BoardListRequester::HandleGetFailed(FCPMessage &message) +const bool BoardListRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -264,7 +257,7 @@ void BoardListRequester::PopulateIDList() void BoardListRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; std::string indexstr; int index; @@ -303,7 +296,7 @@ void BoardListRequester::StartRequest(const long &identityid) message["ReturnType"]="direct"; message["MaxSize"]="100000"; // 100 KB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); diff --git a/src/freenet/fcpv2.cpp b/src/freenet/fcpv2.cpp index 16a7348..ecd81e7 100644 --- a/src/freenet/fcpv2.cpp +++ b/src/freenet/fcpv2.cpp @@ -1,8 +1,8 @@ #include "../../include/freenet/fcpv2.h" -#include -#include + #include -#include +#include +#include #ifdef _WIN32 #include @@ -11,19 +11,83 @@ #include #endif -/* XMEM doesn't play nice with strtok - should replace strtok with something else anyway -#ifdef XMEM - #include -#endif +namespace FCPv2 +{ + +/* + + Message Methods + */ -#ifdef _WIN32 - bool FCPv2::m_wsastartup=false; -#endif +Message::Message():m_name("") +{ +} +Message::Message(const std::string &name):m_name(name) +{ + +} -FCPv2::FCPv2() +Message::Message(const std::string &name, const int fieldcount, ...):m_name(name) +{ + const char *field=0; + const char *val=0; + va_list args; + va_start(args,fieldcount); + + for(int i=0; i::const_iterator i=m_fields.begin(); i!=m_fields.end(); i++) + { + rval+=(*i).first; + rval+="="+(*i).second; + rval+="\n"; + } + if(m_name=="AllData") + { + rval+="Data\n"; + } + else + { + rval+="EndMessage\n"; + } + return rval; +} + + + + + +/* + + Connection Methods + +*/ + +#ifdef _WIN32 + bool Connection::m_wsastartup=false; +#endif + +Connection::Connection():m_socket(-1),m_tempbuffer(65535,0) { #ifdef _WIN32 if(m_wsastartup==false) @@ -33,68 +97,66 @@ FCPv2::FCPv2() m_wsastartup=true; } #endif - - // initialize socket to server - m_serversocket=-1; - - // initialize buffers - m_tempbuffer=new char[65535]; - } +Connection::Connection(const int sock):m_socket(sock),m_tempbuffer(65535,0) +{ +#ifdef _WIN32 + if(m_wsastartup==false) + { + WSAData wsadata; + WSAStartup(MAKEWORD(2,2),&wsadata); + m_wsastartup=true; + } +#endif +} -FCPv2::~FCPv2() +Connection::~Connection() { Disconnect(); #ifdef _WIN32 WSACleanup(); #endif - - delete [] m_tempbuffer; - } - -const bool FCPv2::Connect(const char *host, const int port) +const bool Connection::Connect(const std::string &fcphost, const int fcpport) { - // disconnect socket to server if it is currently open - if(Connected()) + + m_sendbuffer.clear(); + m_receivebuffer.clear(); + + if(IsConnected()==true) { Disconnect(); } int rval=-1; - struct sockaddr_storage m_serveraddr; - std::ostringstream portstring; addrinfo hint,*result,*current; - result=NULL; - portstring << port; - memset(&hint,0,sizeof(addrinfo)); + result=current=0; + portstring << fcpport; + std::memset(&hint,0,sizeof(hint)); hint.ai_socktype=SOCK_STREAM; - rval=getaddrinfo(host,portstring.str().c_str(),&hint,&result); - // erase any data in buffers - m_sendbuffer.clear(); - m_receivebuffer.clear(); + rval=getaddrinfo(fcphost.c_str(),portstring.str().c_str(),&hint,&result); if(result) { - for(current=result; current!=NULL && m_serversocket==-1; current=current->ai_next) + for(current=result; current!=0 && m_socket==-1; current=current->ai_next) { - memset(&m_serveraddr,0,sizeof(struct sockaddr_storage)); - m_serversocket=socket(current->ai_family,current->ai_socktype,current->ai_protocol); + m_socket=socket(current->ai_family,current->ai_socktype,current->ai_protocol); - if(m_serversocket!=-1) + if(m_socket!=-1) { - rval=connect(m_serversocket,current->ai_addr,current->ai_addrlen); + rval=connect(m_socket,current->ai_addr,current->ai_addrlen); if(rval==-1) { Disconnect(); } } + } freeaddrinfo(result); @@ -111,333 +173,293 @@ const bool FCPv2::Connect(const char *host, const int port) } -const bool FCPv2::Disconnect() +const bool Connection::Disconnect() { - if(Connected()) + m_sendbuffer.clear(); + m_receivebuffer.clear(); + if(IsConnected()) { #ifdef _WIN32 - closesocket(m_serversocket); + closesocket(m_socket); #else - close(m_serversocket); + close(m_socket); #endif - m_serversocket=-1; + m_socket=-1; } return true; } -int FCPv2::FindOnReceiveBuffer(const char *text) +void Connection::DoReceive() { - bool found; - std::vector::size_type i,j; - size_t tlen=strlen(text); - - if(m_receivebuffer.size()>=tlen) + if(IsConnected()) { - for(i=0; i<=m_receivebuffer.size()-tlen; i++) + int len=recv(m_socket,&m_tempbuffer[0],m_tempbuffer.size(),0); + if(len>0) { - found=true; - for(j=0; j0) + { + int len=send(m_socket,&m_sendbuffer[0],m_sendbuffer.size(),0); + if(len>0) + { + m_sendbuffer.erase(m_sendbuffer.begin(),m_sendbuffer.begin()+len); + } + else + { + Disconnect(); + } + } } -FCPMessage FCPv2::ReceiveMessage() +const bool Connection::MessageReady() const { - int field=0; - int len=0; - int endlen=0; - int endmessage=-1; - char *buffpos; - char *prevpos; - char *buffer; + std::vector::const_iterator tempi; + std::vector::size_type temp; + return MessageReady(tempi,temp); +} - FCPMessage message; +const bool Connection::MessageReady(std::vector::const_iterator &endpos, std::vector::size_type &endlen) const +{ + static std::string alldatastring="AllData\n"; + static std::string datastring="\nData\n"; // need the \n at the beginning to differentiate from AllData\n + static std::string endmessagestring="EndMessage\n"; + std::vector::const_iterator tempendpos=m_receivebuffer.end(); + std::vector::size_type tempendlen=0; - // there is data on the receive buffer if(m_receivebuffer.size()>0) { - - // find Data on a line by itself following AllData - if(FindOnReceiveBuffer("AllData\n")==0) + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),alldatastring.begin(),alldatastring.end()); + if(tempendpos==m_receivebuffer.begin()) { - endmessage=FindOnReceiveBuffer("\nData\n"); - if(endmessage!=-1) + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),datastring.begin(),datastring.end()); + if(tempendpos!=m_receivebuffer.end()) { - endmessage++; - endlen=5; + tempendpos+=1; + tempendlen=datastring.size()-1; } } - // otherwise this is a regular message - search for EndMessage else { - endmessage=FindOnReceiveBuffer("EndMessage\n"); - endlen=11; + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),endmessagestring.begin(),endmessagestring.end()); + tempendlen=endmessagestring.size(); } - // continue if we found "EndMessage\n" or "Data\n" - if(endmessage!=-1) + if(tempendpos!=m_receivebuffer.end()) { - // total length of message (including ending \n) - len=endmessage+endlen; - - // allocate space for message - buffer=new char[len+1]; - - // copy message from receive buffer to message buffer - std::copy(m_receivebuffer.begin(),m_receivebuffer.begin()+len,buffer); - buffer[len]='\0'; - - // remove from receive buffer - m_receivebuffer.erase(m_receivebuffer.begin(),m_receivebuffer.begin()+len); - - // set buffer position - buffpos=buffer; - - // find message name - buffpos=strtok(buffer,"\n"); - message.SetName(buffer); - - do - { - // find next field - prevpos=buffpos; - buffpos=strtok(NULL,"="); - - // continue if we aren't at the end of a regular message, or at Data for an AllData message - if(strncmp(buffpos,"EndMessage\n",11)!=0 && strncmp(buffpos,"Data\n",5)!=0) //!(strncmp(message->MessageName,"AllData",7)==0 && strncmp(buffpos,"Data\n",5)==0)) - { - - // find next value - prevpos=buffpos; - buffpos=strtok(NULL,"\n"); - - if(prevpos && buffpos) - { - message[prevpos]=buffpos; - } - - field++; - } - else - { - buffpos=0; - } - - }while(buffpos!=0); - - delete [] buffer; - + endpos=tempendpos; + endlen=tempendlen; + return true; } + } - return message; + return false; } -const long FCPv2::ReceiveRaw(char *data, long &datalen) +const bool Connection::MessageReady(std::vector::iterator &endpos, std::vector::size_type &endlen) { - long len=0; - if(m_receivebuffer.size()>0 && datalen>0) + static std::string alldatastring="AllData\n"; + static std::string datastring="\nData\n"; // need the \n at the beginning to differentiate from AllData\n + static std::string endmessagestring="EndMessage\n"; + std::vector::iterator tempendpos=m_receivebuffer.end(); + std::vector::size_type tempendlen=0; + + if(m_receivebuffer.size()>0) { - if(datalen>m_receivebuffer.size()) + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),alldatastring.begin(),alldatastring.end()); + if(tempendpos==m_receivebuffer.begin()) { - len=m_receivebuffer.size(); + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),datastring.begin(),datastring.end()); + if(tempendpos!=m_receivebuffer.end()) + { + tempendpos+=1; + tempendlen=datastring.size()-1; + } } else { - len=datalen; + tempendpos=std::search(m_receivebuffer.begin(),m_receivebuffer.end(),endmessagestring.begin(),endmessagestring.end()); + tempendlen=endmessagestring.size(); } - std::copy(m_receivebuffer.begin(),m_receivebuffer.begin()+len,data); - - // erase bytes from receive buffer - m_receivebuffer.erase(m_receivebuffer.begin(),m_receivebuffer.begin()+len); + if(tempendpos!=m_receivebuffer.end()) + { + endpos=tempendpos; + endlen=tempendlen; + return true; + } } - datalen=len; - return datalen; -} -void FCPv2::SendBufferedText(const char *text) -{ - unsigned int i; - for(i=0; i::iterator endpos; + std::vector::size_type endlen; + if(MessageReady(endpos,endlen)==true) { - m_sendbuffer.push_back(data[i]); - } -} + std::vector fields; -const int FCPv2::SendMessage(const char *messagename, const int fieldcount, ...) -{ - va_list args; - const char *field; - const char *val; - std::vector::size_type bytecount=0; - int i; - std::vector::size_type startlen; + Split(std::string(m_receivebuffer.begin(),endpos),"\n=",fields); + m_receivebuffer.erase(m_receivebuffer.begin(),endpos+endlen); - startlen=m_sendbuffer.size(); + message.Clear(); - SendBufferedText(messagename); - SendBufferedText("\n"); - - va_start(args,fieldcount); + if(fields.size()>0) + { + message.SetName(fields[0]); + } - for(i=0; i1) + { + for(std::vector::iterator i=fields.begin()+1; i!=fields.end();) + { + if(i+1!=fields.end()) + { + message.GetFields()[(*i)]=(*(i+1)); + i+=2; + } + else + { + i++; + } + } + } - SendBufferedText(field); - SendBufferedText("="); - SendBufferedText(val); - SendBufferedText("\n"); } - - SendBufferedText("EndMessage\n"); - - bytecount=m_sendbuffer.size()-startlen; - - va_end(args); - - return bytecount; + return false; } -const int FCPv2::SendMessage(FCPMessage &message) +const bool Connection::Receive(std::vector &data, const std::vector::size_type len) { - std::vector::size_type bytecount=0; - std::vector::size_type startlen; - FCPMessage::iterator i; - - startlen=m_sendbuffer.size(); - - if(message.GetName()!="") + if(m_receivebuffer.size()>=len && len>=0) { - SendBufferedText(message.GetName().c_str()); - SendBufferedText("\n"); - - for(i=message.begin(); i!=message.end(); i++) - { - SendBufferedText((*i).first.c_str()); - SendBufferedText("="); - SendBufferedText((*i).second.c_str()); - SendBufferedText("\n"); - } - - SendBufferedText("EndMessage\n"); + data.insert(data.end(),m_receivebuffer.begin(),m_receivebuffer.begin()+len); + m_receivebuffer.erase(m_receivebuffer.begin(),m_receivebuffer.begin()+len); + return true; + } + else + { + return false; } - - bytecount=m_sendbuffer.size()-startlen; - - return bytecount; } - -const int FCPv2::SendRaw(const char *data, const int datalen) +const bool Connection::Receive(char *data, const size_t len) { - int bytecount=datalen; - - if(bytecount>0) + if(m_receivebuffer.size()>=len && len>=0) { - SendBufferedRaw(data,datalen); + std::copy(m_receivebuffer.begin(),m_receivebuffer.begin()+len,data); + m_receivebuffer.erase(m_receivebuffer.begin(),m_receivebuffer.begin()+len); + return true; + } + else + { + return false; } - - return bytecount; - } -void FCPv2::SocketReceive() +const bool Connection::ReceiveIgnore(const size_t len) { - int len=0; - - len=recv(m_serversocket,m_tempbuffer,65535,0); - - if(len>0) + if(m_receivebuffer.size()>=len && len>=0) { - - m_receivebuffer.resize(m_receivebuffer.size()+len); - std::copy(m_tempbuffer,&m_tempbuffer[len],m_receivebuffer.end()-len); - + m_receivebuffer.erase(m_receivebuffer.begin(),m_receivebuffer.begin()+len); + return true; } - // there was an error or server closed connection - disconnect socket else { - Disconnect(); + return false; } } -void FCPv2::SocketSend() +const bool Connection::Send(const Message &message) { - int len=0; - if(m_sendbuffer.size()>0) + if(message.GetName()!="") { - len=send(m_serversocket,&m_sendbuffer[0],m_sendbuffer.size(),0); - if(len>0) - { - // move remaining data in buffer to beginning of buffer (erase the bytes we just sent) - m_sendbuffer.erase(m_sendbuffer.begin(),m_sendbuffer.begin()+len); - } - // there was an error with send - disconnect socket - else - { - Disconnect(); - } + std::string fcpstring=message.GetFCPString(); + m_sendbuffer.insert(m_sendbuffer.end(),fcpstring.begin(),fcpstring.end()); + return true; } + return false; } +const bool Connection::Send(const std::vector &data) +{ + m_sendbuffer.insert(m_sendbuffer.end(),data.begin(),data.end()); + return true; +} -const bool FCPv2::Update(const long waittime) +const bool Connection::Send(const char *data, const size_t len) { + if(data) + { + m_sendbuffer.insert(m_sendbuffer.end(),data[0],data[0]+len); + return true; + } + return false; +} - if(Connected()) +void Connection::Split(const std::string &str, const std::string &separators, std::vector &elements) +{ + std::string::size_type offset = 0; + std::string::size_type delimIndex = 0; + + delimIndex = str.find_first_of(separators, offset); + + while (delimIndex != std::string::npos) + { + elements.push_back(str.substr(offset, delimIndex - offset)); + offset += delimIndex - offset + 1; + delimIndex = str.find_first_of(separators, offset); + } + + elements.push_back(str.substr(offset)); +} + +const bool Connection::Update(const unsigned long ms) +{ + if(IsConnected()) { - m_timeval.tv_sec=waittime; - m_timeval.tv_usec=0; + m_timeval.tv_sec=ms/1000; + m_timeval.tv_usec=(ms%1000)*1000; FD_ZERO(&m_readfs); FD_ZERO(&m_writefs); - FD_SET(m_serversocket,&m_readfs); - + FD_SET(m_socket,&m_readfs); + if(m_sendbuffer.size()>0) { - FD_SET(m_serversocket,&m_writefs); + FD_SET(m_socket,&m_writefs); } - select(m_serversocket+1,&m_readfs,&m_writefs,0,&m_timeval); + select(m_socket+1,&m_readfs,&m_writefs,0,&m_timeval); - if(FD_ISSET(m_serversocket,&m_readfs)) + if(FD_ISSET(m_socket,&m_readfs)) { - SocketReceive(); + DoReceive(); } - if(Connected() && FD_ISSET(m_serversocket,&m_writefs)) + if(IsConnected() && FD_ISSET(m_socket,&m_writefs)) { - SocketSend(); + DoSend(); } - return true; + } + if(IsConnected()) + { + return true; } else { @@ -445,3 +467,22 @@ const bool FCPv2::Update(const long waittime) } } + +const bool Connection::WaitForBytes(const unsigned long ms, const size_t len) +{ + while(IsConnected() && m_receivebuffer.size()=len) + { + return true; + } + else + { + return false; + } +} + +} // namespace diff --git a/src/freenet/fileinserter.cpp b/src/freenet/fileinserter.cpp index 437543d..0ed526c 100644 --- a/src/freenet/fileinserter.cpp +++ b/src/freenet/fileinserter.cpp @@ -9,7 +9,7 @@ FileInserter::FileInserter() Initialize(); } -FileInserter::FileInserter(FCPv2 *fcp):IIndexInserter(fcp) +FileInserter::FileInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -30,7 +30,7 @@ void FileInserter::CheckForNeededInsert() } } -const bool FileInserter::HandlePutFailed(FCPMessage &message) +const bool FileInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long fileinsertid; @@ -46,7 +46,7 @@ const bool FileInserter::HandlePutFailed(FCPMessage &message) } -const bool FileInserter::HandlePutSuccessful(FCPMessage &message) +const bool FileInserter::HandlePutSuccessful(FCPv2::Message &message) { std::vector idparts; long fileinsertid; @@ -71,7 +71,7 @@ void FileInserter::Initialize() const bool FileInserter::StartInsert(const long &fileinsertid) { - FCPMessage message; + FCPv2::Message message; std::string fileinsertidstr=""; std::string sizestr=""; std::string filename=""; @@ -105,8 +105,8 @@ const bool FileInserter::StartInsert(const long &fileinsertid) message["Identifier"]=m_fcpuniquename+"|"+fileinsertidstr; message["UploadFrom"]="direct"; message["DataLength"]=sizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(&data[0],data.size()); + m_fcp->Send(message); + m_fcp->Send(data); m_inserting.push_back(fileinsertid); diff --git a/src/freenet/fmsversionrequester.cpp b/src/freenet/fmsversionrequester.cpp index 7632998..39fb027 100644 --- a/src/freenet/fmsversionrequester.cpp +++ b/src/freenet/fmsversionrequester.cpp @@ -11,12 +11,12 @@ FMSVersionRequester::FMSVersionRequester() Initialize(); } -FMSVersionRequester::FMSVersionRequester(FCPv2 *fcp):IFCPConnected(fcp) +FMSVersionRequester::FMSVersionRequester(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } -const bool FMSVersionRequester::HandleAllData(FCPMessage &message) +const bool FMSVersionRequester::HandleAllData(FCPv2::Message &message) { std::vector data; long datalength; @@ -25,23 +25,16 @@ const bool FMSVersionRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(message["DataLength"],datalength); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // update latest edition # std::vector parts; @@ -76,7 +69,7 @@ const bool FMSVersionRequester::HandleAllData(FCPMessage &message) return true; } -const bool FMSVersionRequester::HandleGetFailed(FCPMessage &message) +const bool FMSVersionRequester::HandleGetFailed(FCPv2::Message &message) { std::vector parts; StringFunctions::Split(message["Identifier"],"/",parts); @@ -95,7 +88,7 @@ const bool FMSVersionRequester::HandleGetFailed(FCPMessage &message) return true; } -const bool FMSVersionRequester::HandleMessage(FCPMessage &message) +const bool FMSVersionRequester::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find(m_fcpuniquename)==0) { @@ -154,7 +147,7 @@ void FMSVersionRequester::RegisterWithThread(FreenetMasterThread *thread) void FMSVersionRequester::StartRequest() { - FCPMessage message; + FCPv2::Message message; std::string key=""; std::string editionstr="0"; int edition=0; @@ -174,6 +167,6 @@ void FMSVersionRequester::StartRequest() message["ReturnType"]="direct"; message["MaxSize"]="30000"; // 30K - m_fcp->SendMessage(message); + m_fcp->Send(message); } diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index c0feb6a..4890339 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -95,7 +95,7 @@ const bool FreenetMasterThread::FCPConnect() std::string clientname="FMSClient-"+uuid.toString(); // send ClientHello message to node - m_fcp.SendMessage("ClientHello",2,"Name",clientname.c_str(),"ExpectedVersion","2.0"); + m_fcp.Send(FCPv2::Message("ClientHello",2,"Name",clientname.c_str(),"ExpectedVersion","2.0")); m_log->information("FreenetMasterThread::FCPConnect connected to node"); @@ -108,7 +108,7 @@ const bool FreenetMasterThread::FCPConnect() } -const bool FreenetMasterThread::HandleMessage(FCPMessage &message) +const bool FreenetMasterThread::HandleMessage(FCPv2::Message &message) { if(message.GetName()=="NodeHello") { @@ -136,7 +136,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) if(handled==false) { std::string info(""); - for(std::map::iterator mi=message.begin(); mi!=message.end(); mi++) + for(std::map::iterator mi=message.GetFields().begin(); mi!=message.GetFields().end(); mi++) { info+="\t\t\t\t"+(*mi).first+"="+(*mi).second+"\r\n"; } @@ -147,15 +147,11 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) { long length; StringFunctions::Convert(message["DataLength"],length); - while(m_fcp.Connected() && m_fcp.ReceiveBufferSize()0) + m_fcp.WaitForBytes(1000,length); + + if(m_fcp.IsConnected() && length>0) { - char *data=new char[length]; - m_fcp.ReceiveRaw(data,length); - delete [] data; + m_fcp.ReceiveIgnore(length); } } } @@ -192,7 +188,7 @@ void FreenetMasterThread::run() Poco::DateTime lastreceivedmessage; Poco::DateTime lastconnected; Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; bool done=false; lastconnected-=Poco::Timespan(0,0,1,0,0); @@ -205,7 +201,7 @@ void FreenetMasterThread::run() { try { - if(m_fcp.Connected()==false) + if(m_fcp.IsConnected()==false) { // wait at least 1 minute since last successful connect now=Poco::Timestamp(); @@ -235,13 +231,13 @@ void FreenetMasterThread::run() // fcp is connected else { - m_fcp.Update(1); + m_fcp.Update(1000); // check for message on receive buffer and handle it - if(m_fcp.ReceiveBufferSize()>0) + if(m_fcp.MessageReady()==true) { - message.Reset(); - message=m_fcp.ReceiveMessage(); + message.Clear(); + m_fcp.Receive(message); if(message.GetName()!="") { @@ -264,7 +260,7 @@ void FreenetMasterThread::run() m_fcp.Disconnect(); } - if(m_fcp.Connected()==false) + if(m_fcp.IsConnected()==false) { m_log->information("FreenetMasterThread::Run Disconnected from Freenet node."); } diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index f28a738..15e52aa 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -15,7 +15,7 @@ IdentityInserter::IdentityInserter() Initialize(); } -IdentityInserter::IdentityInserter(FCPv2 *fcp):IFCPConnected(fcp) +IdentityInserter::IdentityInserter(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } @@ -55,7 +55,7 @@ void IdentityInserter::FCPDisconnected() } -const bool IdentityInserter::HandleMessage(FCPMessage &message) +const bool IdentityInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("IdentityInserter")==0) @@ -154,7 +154,7 @@ void IdentityInserter::StartInsert(const long localidentityid) if(rs.Empty()==false) { IdentityXML idxml; - FCPMessage mess; + FCPv2::Message mess; Poco::DateTime now; std::string messagebase; std::string data; @@ -232,8 +232,8 @@ void IdentityInserter::StartInsert(const long localidentityid) mess["Identifier"]="IdentityInserter|"+idstring+"|"+indexstr+"|"+mess["URI"]; mess["UploadFrom"]="direct"; mess["DataLength"]=datasizestr; - m_fcp->SendMessage(mess); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(mess); + m_fcp->Send(std::vector(data.begin(),data.end())); m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='true' WHERE LocalIdentityID="+idstring+";"); diff --git a/src/freenet/identityintroductioninserter.cpp b/src/freenet/identityintroductioninserter.cpp index 7537c91..78a0f93 100644 --- a/src/freenet/identityintroductioninserter.cpp +++ b/src/freenet/identityintroductioninserter.cpp @@ -15,7 +15,7 @@ IdentityIntroductionInserter::IdentityIntroductionInserter() Initialize(); } -IdentityIntroductionInserter::IdentityIntroductionInserter(FCPv2 *fcp):IFCPConnected(fcp) +IdentityIntroductionInserter::IdentityIntroductionInserter(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } @@ -42,7 +42,7 @@ void IdentityIntroductionInserter::FCPDisconnected() } -const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) +const bool IdentityIntroductionInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("IdentityIntroductionInserter")==0) @@ -115,12 +115,11 @@ void IdentityIntroductionInserter::RegisterWithThread(FreenetMasterThread *threa void IdentityIntroductionInserter::StartInsert(const long localidentityid, const std::string &day, const std::string &UUID, const std::string &solution) { - FCPMessage message; + FCPv2::Message message; IdentityIntroductionXML xml; std::string publickey; std::string data; std::string datasizestr; -// std::vector hash; std::string encodedhash; SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LocalIdentityID=?;"); @@ -140,18 +139,14 @@ void IdentityIntroductionInserter::StartInsert(const long localidentityid, const encodedhash=Poco::DigestEngine::digestToHex(sha1.digest()); StringFunctions::UpperCase(encodedhash,encodedhash); -// hash.resize(20); -// sha1((unsigned char *)solution.c_str(),solution.size(),&hash[0]); -// Hex::Encode(hash,encodedhash); - message.SetName("ClientPut"); message["URI"]="KSK@"+m_messagebase+"|"+day+"|"+UUID+"|"+encodedhash+".xml"; message["Identifier"]="IdentityIntroductionInserter|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); m_inserting=true; } diff --git a/src/freenet/identityintroductionrequester.cpp b/src/freenet/identityintroductionrequester.cpp index 951e12d..20fb31f 100644 --- a/src/freenet/identityintroductionrequester.cpp +++ b/src/freenet/identityintroductionrequester.cpp @@ -19,7 +19,7 @@ IdentityIntroductionRequester::IdentityIntroductionRequester() Initialize(); } -IdentityIntroductionRequester::IdentityIntroductionRequester(FCPv2 *fcp):IFCPConnected(fcp) +IdentityIntroductionRequester::IdentityIntroductionRequester(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } @@ -35,7 +35,7 @@ void IdentityIntroductionRequester::FCPDisconnected() } -const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) +const bool IdentityIntroductionRequester::HandleAllData(FCPv2::Message &message) { FreenetSSK ssk; Poco::DateTime date; @@ -48,23 +48,16 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(message["DataLength"],datalength); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -123,7 +116,7 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) return true; } -const bool IdentityIntroductionRequester::HandleGetFailed(FCPMessage &message) +const bool IdentityIntroductionRequester::HandleGetFailed(FCPv2::Message &message) { std::vector idparts; @@ -146,7 +139,7 @@ const bool IdentityIntroductionRequester::HandleGetFailed(FCPMessage &message) return true; } -const bool IdentityIntroductionRequester::HandleMessage(FCPMessage &message) +const bool IdentityIntroductionRequester::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("IdentityIntroductionRequester")==0) @@ -280,7 +273,7 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID) std::string day; std::string solution; std::string encodedhash; - FCPMessage message; + FCPv2::Message message; SQLite3DB::Statement st=m_db->Prepare("SELECT Day, PuzzleSolution FROM tblIntroductionPuzzleInserts WHERE FoundSolution='false' AND UUID=?;"); st.Bind(0,UUID); st.Step(); @@ -303,7 +296,7 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID) message["ReturnType"]="direct"; message["MaxSize"]="10000"; - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(UUID); diff --git a/src/freenet/identityrequester.cpp b/src/freenet/identityrequester.cpp index 0738698..9e7a769 100644 --- a/src/freenet/identityrequester.cpp +++ b/src/freenet/identityrequester.cpp @@ -17,12 +17,12 @@ IdentityRequester::IdentityRequester() Initialize(); } -IdentityRequester::IdentityRequester(FCPv2 *fcp):IIndexRequester(fcp) +IdentityRequester::IdentityRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } -const bool IdentityRequester::HandleAllData(FCPMessage &message) +const bool IdentityRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -41,23 +41,16 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(idparts[2],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -136,7 +129,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) } -const bool IdentityRequester::HandleGetFailed(FCPMessage &message) +const bool IdentityRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -210,7 +203,7 @@ void IdentityRequester::PopulateIDList() void IdentityRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -251,7 +244,7 @@ void IdentityRequester::StartRequest(const long &identityid) message["ReturnType"]="direct"; message["MaxSize"]="10000"; // 10 KB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); } diff --git a/src/freenet/inactivemessagelistrequester.cpp b/src/freenet/inactivemessagelistrequester.cpp index 7cbfbe8..2a47d81 100644 --- a/src/freenet/inactivemessagelistrequester.cpp +++ b/src/freenet/inactivemessagelistrequester.cpp @@ -11,7 +11,7 @@ InactiveMessageListRequester::InactiveMessageListRequester() Initialize(); } -InactiveMessageListRequester::InactiveMessageListRequester(FCPv2 *fcp):MessageListRequester(fcp) +InactiveMessageListRequester::InactiveMessageListRequester(FCPv2::Connection *fcp):MessageListRequester(fcp) { Initialize(); } @@ -25,7 +25,7 @@ void InactiveMessageListRequester::Initialize() Option::Instance()->GetInt("MaxMessageListRequests",m_maxrequests); // inactive identities get 1/2 of the max requests option - active identities get 1/2 + any remaining if not evenly divisible - m_maxrequests=(m_maxrequests/2)+(m_maxrequests%2); + m_maxrequests=(m_maxrequests/2); if(m_maxrequests<1) { diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index 5ccb25e..089e4ac 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -22,7 +22,7 @@ IntroductionPuzzleInserter::IntroductionPuzzleInserter():IIndexInserter() Initialize(); } -IntroductionPuzzleInserter::IntroductionPuzzleInserter(FCPv2 *fcp):IIndexInserter(fcp) +IntroductionPuzzleInserter::IntroductionPuzzleInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -106,7 +106,7 @@ void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std:: } -const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message) +const bool IntroductionPuzzleInserter::HandlePutFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -132,7 +132,7 @@ const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message) return true; } -const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message) +const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -187,7 +187,7 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) IntroductionPuzzleXML xml; std::string encodedpuzzle=""; std::string solutionstring=""; - FCPMessage message; + FCPv2::Message message; std::string xmldata=""; std::string xmldatasizestr=""; std::string privatekey=""; @@ -257,11 +257,11 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) 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()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xmldata.begin(),xmldata.end())); // insert to USK - message.Reset(); + message.Clear(); 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"]; @@ -269,8 +269,8 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) 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_fcp->Send(message); + m_fcp->Send(std::vector(xmldata.begin(),xmldata.end())); m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');"); diff --git a/src/freenet/introductionpuzzlerequester.cpp b/src/freenet/introductionpuzzlerequester.cpp index 80aacb1..fd81f14 100644 --- a/src/freenet/introductionpuzzlerequester.cpp +++ b/src/freenet/introductionpuzzlerequester.cpp @@ -19,12 +19,12 @@ IntroductionPuzzleRequester::IntroductionPuzzleRequester() Initialize(); } -IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2 *fcp):IIndexRequester(fcp) +IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } -const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) +const bool IntroductionPuzzleRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -42,23 +42,16 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(idparts[2],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -158,7 +151,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) } -const bool IntroductionPuzzleRequester::HandleGetFailed(FCPMessage &message) +const bool IntroductionPuzzleRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -237,7 +230,7 @@ void IntroductionPuzzleRequester::PopulateIDList() void IntroductionPuzzleRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -278,7 +271,7 @@ void IntroductionPuzzleRequester::StartRequest(const long &identityid) message["ReturnType"]="direct"; message["MaxSize"]="1000000"; // 1 MB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); } diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index d248cd3..c1688f3 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -10,7 +10,7 @@ MessageInserter::MessageInserter() Initialize(); } -MessageInserter::MessageInserter(FCPv2 *fcp):IIndexInserter(fcp) +MessageInserter::MessageInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -46,7 +46,7 @@ void MessageInserter::CheckForNeededInsert() } } -const bool MessageInserter::HandlePutFailed(FCPMessage &message) +const bool MessageInserter::HandlePutFailed(FCPv2::Message &message) { int index; int localidentityid; @@ -72,7 +72,7 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) return true; } -const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) +const bool MessageInserter::HandlePutSuccessful(FCPv2::Message &message) { MessageXML xml; Poco::DateTime date; @@ -149,7 +149,7 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) std::string xmlsizestr; std::string privatekey; std::string publickey; - FCPMessage message; + FCPv2::Message message; std::string indexstr; int index=0; @@ -208,8 +208,8 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+xmlfile.GetMessageID()+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xml.c_str(),xml.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xml.begin(),xml.end())); m_inserting.push_back(messageuuid); diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index 786fffe..04ab9f3 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -15,7 +15,7 @@ MessageListInserter::MessageListInserter() Initialize(); } -MessageListInserter::MessageListInserter(FCPv2 *fcp):IIndexInserter(fcp) +MessageListInserter::MessageListInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -60,7 +60,7 @@ void MessageListInserter::CheckForNeededInsert() } -const bool MessageListInserter::HandlePutFailed(FCPMessage &message) +const bool MessageListInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long localidentityid; @@ -97,7 +97,7 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message) } -const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) +const bool MessageListInserter::HandlePutSuccessful(FCPv2::Message &message) { Poco::DateTime now; std::vector idparts; @@ -162,7 +162,7 @@ void MessageListInserter::Initialize() const bool MessageListInserter::StartInsert(const long &localidentityid) { - FCPMessage message; + FCPv2::Message message; Poco::DateTime date; Poco::DateTime now; std::string privatekey; @@ -262,10 +262,10 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xmlstr.begin(),xmlstr.end())); - message.Reset(); + message.Clear(); message.SetName("ClientPutComplexDir"); message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|MessageList/0/"; message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"]; @@ -273,8 +273,8 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) message["Files.0.Name"]="MessageList.xml"; message["Files.0.UploadFrom"]="direct"; message["Files.0.DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xmlstr.begin(),xmlstr.end())); m_inserting.push_back(localidentityid); m_lastinsertedxml[localidentityid]=xmlstr; diff --git a/src/freenet/messagelistrequester.cpp b/src/freenet/messagelistrequester.cpp index d8ed8aa..17aba0a 100644 --- a/src/freenet/messagelistrequester.cpp +++ b/src/freenet/messagelistrequester.cpp @@ -15,7 +15,7 @@ MessageListRequester::MessageListRequester() Initialize(); } -MessageListRequester::MessageListRequester(FCPv2 *fcp):IIndexRequester(fcp) +MessageListRequester::MessageListRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } @@ -97,7 +97,7 @@ void MessageListRequester::GetBoardList(std::map &boards) } } -const bool MessageListRequester::HandleAllData(FCPMessage &message) +const bool MessageListRequester::HandleAllData(FCPv2::Message &message) { SQLite3DB::Statement st; SQLite3DB::Statement trustst; @@ -121,23 +121,16 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(idparts[2],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -300,7 +293,7 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) } -const bool MessageListRequester::HandleGetFailed(FCPMessage &message) +const bool MessageListRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -416,13 +409,13 @@ void MessageListRequester::PopulateIDList() } } -void MessageListRequester::StartRedirectRequest(FCPMessage &message) +void MessageListRequester::StartRedirectRequest(FCPv2::Message &message) { std::vector parts; std::string indexstr=""; std::string identityidstr=""; std::string datestr=""; - FCPMessage newmessage; + FCPv2::Message newmessage; // get the new edition # StringFunctions::Split(message["RedirectURI"],"/",parts); @@ -450,14 +443,14 @@ void MessageListRequester::StartRedirectRequest(FCPMessage &message) newmessage["ReturnType"]="direct"; newmessage["MaxSize"]="1000000"; - m_fcp->SendMessage(newmessage); + m_fcp->Send(newmessage); } void MessageListRequester::StartRequest(const long &id) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index=0; std::string indexstr; @@ -500,7 +493,7 @@ void MessageListRequester::StartRequest(const long &id) message["ReturnType"]="direct"; message["MaxSize"]="1000000"; - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(id); } diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index c5361ec..fbd767c 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -16,7 +16,7 @@ MessageRequester::MessageRequester() Initialize(); } -MessageRequester::MessageRequester(FCPv2 *fcp):IIndexRequester(fcp) +MessageRequester::MessageRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } @@ -85,7 +85,7 @@ const std::string MessageRequester::GetIdentityName(const long identityid) } } -const bool MessageRequester::HandleAllData(FCPMessage &message) +const bool MessageRequester::HandleAllData(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -104,23 +104,16 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(idparts[4],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // mark this index as received st=m_db->Prepare("UPDATE tblMessageRequests SET Found='true' WHERE IdentityID=? AND Day=? AND RequestIndex=?;"); @@ -291,7 +284,7 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) return true; } -const bool MessageRequester::HandleGetFailed(FCPMessage &message) +const bool MessageRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -479,7 +472,7 @@ const bool MessageRequester::SaveToBoard(const std::string &boardname) void MessageRequester::StartRequest(const std::string &requestid) { - FCPMessage message; + FCPv2::Message message; std::vector parts; std::string tempval; long identityid; @@ -507,7 +500,7 @@ void MessageRequester::StartRequest(const std::string &requestid) message["MaxSize"]="1000000"; // 1 MB message["MaxRetries"]="-1"; // use ULPR since we are fairly sure message exists since the author says it does - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(requestid); diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index 99a96c7..0ae9fc5 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -14,7 +14,7 @@ SiteInserter::SiteInserter() Initialize(); } -SiteInserter::SiteInserter(FCPv2 *fcp):IIndexInserter(fcp) +SiteInserter::SiteInserter(FCPv2::Connection *fcp):IIndexInserter(fcp) { Initialize(); } @@ -354,7 +354,7 @@ const std::string SiteInserter::GetClassString(const std::string &trustlevel) } } -const bool SiteInserter::HandlePutFailed(FCPMessage &message) +const bool SiteInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long localidentityid; @@ -369,7 +369,7 @@ const bool SiteInserter::HandlePutFailed(FCPMessage &message) return true; } -const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) +const bool SiteInserter::HandlePutSuccessful(FCPv2::Message &message) { std::vector idparts; std::vector uriparts; @@ -418,7 +418,7 @@ const std::string SiteInserter::SanitizeOutput(const std::string &input) const bool SiteInserter::StartInsert(const long &localidentityid) { - FCPMessage message; + FCPv2::Message message; std::string localidentityidstr=""; std::string sizestr=""; std::string uskkey=""; @@ -450,12 +450,12 @@ const bool SiteInserter::StartInsert(const long &localidentityid) filenum++; } - m_fcp->SendMessage(message); + m_fcp->Send(message); // send data of each page for(std::map::iterator pagei=pages.begin(); pagei!=pages.end(); pagei++) { - m_fcp->SendRaw(&(*pagei).second[0],(*pagei).second.size()); + m_fcp->Send(std::vector((*pagei).second.begin(),(*pagei).second.end())); } m_inserting.push_back(localidentityid); diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index fc02e8b..0851c61 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -16,7 +16,7 @@ TrustListInserter::TrustListInserter() Initialize(); } -TrustListInserter::TrustListInserter(FCPv2 *fcp):IFCPConnected(fcp) +TrustListInserter::TrustListInserter(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } @@ -49,7 +49,7 @@ void TrustListInserter::FCPDisconnected() } -const bool TrustListInserter::HandleMessage(FCPMessage &message) +const bool TrustListInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("TrustListInserter")==0) @@ -133,7 +133,7 @@ void TrustListInserter::RegisterWithThread(FreenetMasterThread *thread) void TrustListInserter::StartInsert(const long localidentityid, const std::string &privatekey) { - FCPMessage message; + FCPv2::Message message; TrustListXML xml; std::string data; std::string datasizestr; @@ -257,11 +257,11 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin message["Identifier"]="TrustListInserter|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); // insert to USK - message.Reset(); + message.Clear(); message.SetName("ClientPutComplexDir"); message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|TrustList/0/"; message["Identifier"]="TrustListInserterUSK|"+message["URI"]; @@ -269,8 +269,8 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin message["Files.0.Name"]="TrustList.xml"; message["Files.0.UplaodFrom"]="direct"; message["Files.0.DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='true' WHERE LocalIdentityID="+localidentityidstr+";"); diff --git a/src/freenet/trustlistrequester.cpp b/src/freenet/trustlistrequester.cpp index 77f4f4e..bedc845 100644 --- a/src/freenet/trustlistrequester.cpp +++ b/src/freenet/trustlistrequester.cpp @@ -15,12 +15,12 @@ TrustListRequester::TrustListRequester() Initialize(); } -TrustListRequester::TrustListRequester(FCPv2 *fcp):IIndexRequester(fcp) +TrustListRequester::TrustListRequester(FCPv2::Connection *fcp):IIndexRequester(fcp) { Initialize(); } -const bool TrustListRequester::HandleAllData(FCPMessage &message) +const bool TrustListRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -41,23 +41,16 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) StringFunctions::Convert(idparts[2],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // get count of identities added in last 24 hours st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE DateAdded>=?;"); @@ -238,7 +231,7 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message) } -const bool TrustListRequester::HandleGetFailed(FCPMessage &message) +const bool TrustListRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -315,7 +308,7 @@ void TrustListRequester::PopulateIDList() void TrustListRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -354,7 +347,7 @@ void TrustListRequester::StartRequest(const long &identityid) message["ReturnType"]="direct"; message["MaxSize"]="1000000"; // 1 MB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); } diff --git a/src/freenet/unkeyedidcreator.cpp b/src/freenet/unkeyedidcreator.cpp index e23a81c..e873dad 100644 --- a/src/freenet/unkeyedidcreator.cpp +++ b/src/freenet/unkeyedidcreator.cpp @@ -14,7 +14,7 @@ UnkeyedIDCreator::UnkeyedIDCreator() Initialize(); } -UnkeyedIDCreator::UnkeyedIDCreator(FCPv2 *fcp):IFCPConnected(fcp) +UnkeyedIDCreator::UnkeyedIDCreator(FCPv2::Connection *fcp):IFCPConnected(fcp) { Initialize(); } @@ -42,10 +42,10 @@ void UnkeyedIDCreator::CheckForUnkeyedID() long id=rs.GetInt(0); idstr << id; - FCPMessage message; + FCPv2::Message message; message.SetName("GenerateSSK"); message["Identifier"]="UnkeyedIDRequest|"+idstr.str(); - m_fcp->SendMessage(message); + m_fcp->Send(message); m_waiting=true; @@ -56,7 +56,7 @@ void UnkeyedIDCreator::CheckForUnkeyedID() } -const bool UnkeyedIDCreator::HandleMessage(FCPMessage &message) +const bool UnkeyedIDCreator::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("UnkeyedIDRequest")==0) { diff --git a/src/freenet/unknownidentityrequester.cpp b/src/freenet/unknownidentityrequester.cpp index 765eb3f..63e12c3 100644 --- a/src/freenet/unknownidentityrequester.cpp +++ b/src/freenet/unknownidentityrequester.cpp @@ -10,7 +10,7 @@ UnknownIdentityRequester::UnknownIdentityRequester() Initialize(); } -UnknownIdentityRequester::UnknownIdentityRequester(FCPv2 *fcp):IdentityRequester(fcp) +UnknownIdentityRequester::UnknownIdentityRequester(FCPv2::Connection *fcp):IdentityRequester(fcp) { Initialize(); } diff --git a/src/http/pages/forumviewthreadpage.cpp b/src/http/pages/forumviewthreadpage.cpp index a680bfe..e4447d4 100644 --- a/src/http/pages/forumviewthreadpage.cpp +++ b/src/http/pages/forumviewthreadpage.cpp @@ -8,32 +8,11 @@ const std::string ForumViewThreadPage::FixBody(const std::string &body) { - static std::string whitespace=" \t\r\n"; std::string output=body; output=StringFunctions::Replace(output,"\r\n","\n"); UnicodeFormatter::LineWrap(output,80,"",output); - /* - // put \n after 80 contiguous characters in the body - std::string::size_type prevpos=0; - std::string::size_type pos=output.find_first_of(whitespace); - while(pos!=std::string::npos) - { - while(pos-prevpos>80) - { - output.insert(prevpos+80,"\n"); - prevpos+=81; // 81 because of the extra newline we just inserted - } - prevpos=pos; - pos=output.find_first_of(whitespace,pos+1); - } - while(output.size()-prevpos>80) // check the last line of the message (no whitespace after it) - { - output.insert(prevpos+80,"\n"); - prevpos+=81; - } - */ output=StringFunctions::Replace(output,"<","<"); output=StringFunctions::Replace(output,">",">"); @@ -73,9 +52,18 @@ const std::string ForumViewThreadPage::GeneratePage(const std::string &method, c firstunreadst.ResultText(0,firstunreadidstr); } - SQLite3DB::Statement updateread=m_db->Prepare("UPDATE tblMessage SET Read=1 WHERE tblMessage.MessageID IN (SELECT MessageID FROM tblThreadPost WHERE ThreadID=?);"); - updateread.Bind(0,threadidstr); - updateread.Step(); + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="markunread") + { + SQLite3DB::Statement updateread=m_db->Prepare("UPDATE tblMessage SET Read=0 WHERE tblMessage.MessageID IN (SELECT MessageID FROM tblThreadPost WHERE ThreadID=?);"); + updateread.Bind(0,threadidstr); + updateread.Step(); + } + else + { + SQLite3DB::Statement updateread=m_db->Prepare("UPDATE tblMessage SET Read=1 WHERE tblMessage.MessageID IN (SELECT MessageID FROM tblThreadPost WHERE ThreadID=?);"); + updateread.Bind(0,threadidstr); + updateread.Step(); + } SQLite3DB::Statement trustst=m_db->Prepare("SELECT LocalMessageTrust, LocalTrustListTrust, PeerMessageTrust, PeerTrustListTrust, Name FROM tblIdentity WHERE IdentityID=?;"); @@ -97,6 +85,9 @@ const std::string ForumViewThreadPage::GeneratePage(const std::string &method, c content+="First Unread Message"; content+=""; } + content+=""; + content+="Mark Unread"; + content+=""; content+=""; content+="\r\n"; diff --git a/src/unicode/unicodeformatter.cpp b/src/unicode/unicodeformatter.cpp index c89cc7c..bc6a238 100644 --- a/src/unicode/unicodeformatter.cpp +++ b/src/unicode/unicodeformatter.cpp @@ -2,7 +2,7 @@ #include "../../include/unicode/utfconversion.h" std::wstring UnicodeFormatter::m_unicodenewline=L"\n"; -wchar_t UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x000D, +std::wstring::value_type UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x000D, 0x0020,0x0085,0x00A0,0x1680,0x180E, 0x2000,0x2001,0x2002,0x2003,0x2004, 0x2005,0x2006,0x2007,0x2008,0x2009, @@ -11,8 +11,8 @@ wchar_t UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x0 const bool UnicodeFormatter::LineWrap(const std::string &utf8input, const int linelength, const std::string &ignorechars, std::string &utf8output) { - std::wstring wcstring; - std::wstring wcignorechars; + std::wstring wcstring=L""; + std::wstring wcignorechars=L""; if(UTFConversion::FromUTF8(utf8input,wcstring) && UTFConversion::FromUTF8(ignorechars,wcignorechars)) { diff --git a/src/unicode/utfconversion.cpp b/src/unicode/utfconversion.cpp index 112ed17..5d7c835 100644 --- a/src/unicode/utfconversion.cpp +++ b/src/unicode/utfconversion.cpp @@ -3,7 +3,7 @@ namespace UTFConversion { -const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) +const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) { if(utf8string.size()==0) { @@ -11,7 +11,7 @@ const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) return true; } - std::vector dest(utf8string.size(),0); // dest will never be bigger than the input but could be smaller + std::vector dest(utf8string.size(),0); // dest will never be bigger than the input but could be smaller const UTF8 *sourcestart=reinterpret_cast(&utf8string[0]); const UTF8 *sourceend=sourcestart+utf8string.size(); @@ -40,7 +40,7 @@ const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) if(rval!=conversionOK) { - return false; + return false; } wcstring.assign(dest.begin(),dest.end()-(destend-deststart)); @@ -48,7 +48,7 @@ const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) } else { - return false; + return false; } return true; @@ -57,7 +57,15 @@ const bool FromUTF8(const std::vector &utf8string, std::wstring &wcstring) const bool FromUTF8(const std::string &utf8string, std::wstring &wcstring) { - return FromUTF8(std::vector(utf8string.begin(),utf8string.end()),wcstring); + if(utf8string.size()>0) + { + return FromUTF8(std::vector(utf8string.begin(),utf8string.end()),wcstring); + } + else + { + wcstring.assign(L""); + return true; + } } @@ -69,11 +77,11 @@ const bool ToUTF8(const std::wstring &wcstring, std::string &utf8string) return true; } - std::vector source(wcstring.begin(),wcstring.end()); + std::vector source(wcstring.begin(),wcstring.end()); - if(sizeof(wchar_t)==2) + if(sizeof(std::wstring::value_type)==2) { - std::vector dest(wcstring.size()*2,0); + std::vector dest(wcstring.size()*2,0); const UTF16 *sourcestart=reinterpret_cast(&source[0]); const UTF16 *sourceend=sourcestart+source.size(); @@ -85,15 +93,15 @@ const bool ToUTF8(const std::wstring &wcstring, std::string &utf8string) if(rval!=conversionOK) { - return false; + return false; } utf8string.assign(dest.begin(),dest.end()-(destend-deststart)); } - else if(sizeof(wchar_t)==4) + else if(sizeof(std::wstring::value_type)==4) { - std::vector dest(wcstring.size()*4,0); + std::vector dest(wcstring.size()*4,0); const UTF32 *sourcestart=reinterpret_cast(&source[0]); const UTF32 *sourceend=sourcestart+source.size(); @@ -105,7 +113,7 @@ const bool ToUTF8(const std::wstring &wcstring, std::string &utf8string) if(rval!=conversionOK) { - return false; + return false; } utf8string.assign(dest.begin(),dest.end()-(destend-deststart)); -- 2.7.4