diff options
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/Daemon.cpp | 108 | ||||
-rw-r--r-- | lib/server/Daemon.h | 8 | ||||
-rw-r--r-- | lib/server/Protocol.cpp | 77 | ||||
-rw-r--r-- | lib/server/Protocol.h | 42 | ||||
-rw-r--r-- | lib/server/ProtocolObject.cpp | 125 | ||||
-rw-r--r-- | lib/server/ProtocolObject.h | 41 | ||||
-rw-r--r-- | lib/server/SSLLib.cpp | 31 | ||||
-rw-r--r-- | lib/server/SSLLib.h | 4 | ||||
-rw-r--r-- | lib/server/ServerException.txt | 4 | ||||
-rw-r--r-- | lib/server/ServerStream.h | 18 | ||||
-rw-r--r-- | lib/server/Socket.cpp | 39 | ||||
-rw-r--r-- | lib/server/SocketListen.h | 44 | ||||
-rw-r--r-- | lib/server/SocketStream.cpp | 21 | ||||
-rw-r--r-- | lib/server/SocketStream.h | 7 | ||||
-rw-r--r-- | lib/server/SocketStreamTLS.cpp | 36 | ||||
-rw-r--r-- | lib/server/TLSContext.cpp | 20 | ||||
-rwxr-xr-x | lib/server/makeprotocol.pl.in | 789 |
17 files changed, 0 insertions, 1414 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 9b96647b..7419f973 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -25,19 +25,6 @@ #ifdef WIN32 #include <ws2tcpip.h> -<<<<<<< HEAD -#endif - -#include <iostream> - -#include "Daemon.h" -#include "Configuration.h" -#include "ServerException.h" -#include "Guards.h" -#include "UnixUser.h" -#include "FileModificationTime.h" -#include "Logging.h" -======= #include <process.h> #endif @@ -56,7 +43,6 @@ #include "Logging.h" #include "ServerException.h" #include "UnixUser.h" ->>>>>>> 0.12 #include "Utils.h" #include "MemLeakFindOn.h" @@ -85,10 +71,7 @@ Daemon::Daemon() mKeepConsoleOpenAfterFork(false), #endif mHaveConfigFile(false), -<<<<<<< HEAD -======= mLogFileLevel(Log::INVALID), ->>>>>>> 0.12 mAppName(DaemonName()) { // In debug builds, switch on assert failure logging to syslog @@ -125,25 +108,16 @@ std::string Daemon::GetOptionString() { return "c:" #ifndef WIN32 -<<<<<<< HEAD - "DFK" - #endif - "hkPqQt:TUvVW:"; -======= "DF" #endif "hkKo:O:PqQt:TUvVW:"; ->>>>>>> 0.12 } void Daemon::Usage() { std::cout << DaemonBanner() << "\n" -<<<<<<< HEAD -======= "(built with QDBM " << dpversion << ")\n" ->>>>>>> 0.12 "\n" "Usage: " << mAppName << " [options] [config file]\n" "\n" @@ -156,20 +130,6 @@ void Daemon::Usage() " -F Do not fork into background, but fork to serve multiple clients\n" #endif " -k Keep console open after fork, keep writing log messages to it\n" -<<<<<<< HEAD -#ifndef WIN32 - " -K Stop writing log messages to console while daemon is running\n" - " -P Show process ID (PID) in console output\n" -#endif - " -q Run more quietly, reduce verbosity level by one, can repeat\n" - " -Q Run at minimum verbosity, log nothing\n" - " -v Run more verbosely, increase verbosity level by one, can repeat\n" - " -V Run at maximum verbosity, log everything\n" - " -W <level> Set verbosity to error/warning/notice/info/trace/everything\n" - " -t <tag> Tag console output with specified marker\n" - " -T Timestamp console output\n" - " -U Timestamp console output with microseconds\n"; -======= " -K Stop writing log messages to console while daemon is running\n" " -o <file> Log to a file, defaults to maximum verbosity\n" " -O <level> Set file log verbosity to error/warning/notice/info/trace/everything\n" @@ -183,7 +143,6 @@ void Daemon::Usage() " -V Run at maximum verbosity, log everything to console and system\n" " -W <level> Set verbosity to error/warning/notice/info/trace/everything\n" ; ->>>>>>> 0.12 } // -------------------------------------------------------------------------- @@ -222,8 +181,6 @@ int Daemon::ProcessOption(signed int option) break; #endif // !WIN32 -<<<<<<< HEAD -======= case 'h': { Usage(); @@ -231,7 +188,6 @@ int Daemon::ProcessOption(signed int option) } break; ->>>>>>> 0.12 case 'k': { mKeepConsoleOpenAfterFork = true; @@ -244,12 +200,6 @@ int Daemon::ProcessOption(signed int option) } break; -<<<<<<< HEAD - case 'h': - { - Usage(); - return 2; -======= case 'o': { mLogFile = optarg; @@ -265,7 +215,6 @@ int Daemon::ProcessOption(signed int option) BOX_FATAL("Invalid logging level: " << optarg); return 2; } ->>>>>>> 0.12 } break; @@ -294,8 +243,6 @@ int Daemon::ProcessOption(signed int option) } break; -<<<<<<< HEAD -======= case 't': { Logging::SetProgramName(optarg); @@ -315,7 +262,6 @@ int Daemon::ProcessOption(signed int option) Console::SetShowTimeMicros(true); } break; ->>>>>>> 0.12 case 'v': { @@ -341,39 +287,12 @@ int Daemon::ProcessOption(signed int option) mLogLevel = Logging::GetNamedLevel(optarg); if (mLogLevel == Log::INVALID) { -<<<<<<< HEAD - BOX_FATAL("Invalid logging level"); -======= BOX_FATAL("Invalid logging level: " << optarg); ->>>>>>> 0.12 return 2; } } break; -<<<<<<< HEAD - case 't': - { - Logging::SetProgramName(optarg); - Console::SetShowTag(true); - } - break; - - case 'T': - { - Console::SetShowTime(true); - } - break; - - case 'U': - { - Console::SetShowTime(true); - Console::SetShowTimeMicros(true); - } - break; - -======= ->>>>>>> 0.12 case '?': { BOX_FATAL("Unknown option on command line: " @@ -403,18 +322,6 @@ int Daemon::ProcessOption(signed int option) // Created: 2003/07/29 // // -------------------------------------------------------------------------- -<<<<<<< HEAD -int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) -{ - // Find filename of config file - mConfigFileName = DefaultConfigFile; - mAppName = argv[0]; - - #ifdef BOX_RELEASE_BUILD - mLogLevel = Log::NOTICE; // need an int to do math with - #else - mLogLevel = Log::INFO; // need an int to do math with -======= int Daemon::Main(const std::string& rDefaultConfigFile, int argc, const char *argv[]) { @@ -448,7 +355,6 @@ int Daemon::ProcessOptions(int argc, const char *argv[]) mLogLevel = Log::NOTICE; #else mLogLevel = Log::INFO; ->>>>>>> 0.12 #endif if (argc == 2 && strcmp(argv[1], "/?") == 0) @@ -503,9 +409,6 @@ int Daemon::ProcessOptions(int argc, const char *argv[]) Logging::FilterConsole((Log::Level)mLogLevel); Logging::FilterSyslog ((Log::Level)mLogLevel); -<<<<<<< HEAD - return Main(mConfigFileName); -======= if (mLogFileLevel != Log::INVALID) { mapLogFileLogger.reset( @@ -513,7 +416,6 @@ int Daemon::ProcessOptions(int argc, const char *argv[]) } return 0; ->>>>>>> 0.12 } // -------------------------------------------------------------------------- @@ -535,11 +437,7 @@ bool Daemon::Configure(const std::string& rConfigFileName) try { -<<<<<<< HEAD - if (!FileExists(rConfigFileName.c_str())) -======= if (!FileExists(rConfigFileName)) ->>>>>>> 0.12 { BOX_FATAL("The main configuration file for " << DaemonName() << " was not found: " << @@ -1127,11 +1025,6 @@ void Daemon::SetProcessTitle(const char *format, ...) char title[256]; ::vsnprintf(title, sizeof(title), format, args); -<<<<<<< HEAD - // Set process title - ::setproctitle("%s", title); - -======= #ifdef WIN32 StringCchCatA(title, sizeof(title)," - " PACKAGE_NAME); SetConsoleTitleA(title); @@ -1140,7 +1033,6 @@ void Daemon::SetProcessTitle(const char *format, ...) ::setproctitle("%s", title); #endif ->>>>>>> 0.12 #endif // HAVE_SETPROCTITLE } diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h index f2fa98c3..2718c288 100644 --- a/lib/server/Daemon.h +++ b/lib/server/Daemon.h @@ -40,14 +40,9 @@ private: Daemon(const Daemon &rToCopy); public: -<<<<<<< HEAD - virtual int Main(const char *DefaultConfigFile, int argc, - const char *argv[]); -======= virtual int Main(const std::string& rDefaultConfigFile, int argc, const char *argv[]); virtual int ProcessOptions(int argc, const char *argv[]); ->>>>>>> 0.12 /* override this Main() if you want custom option processing: */ virtual int Main(const std::string &rConfigFile); @@ -105,12 +100,9 @@ private: bool mKeepConsoleOpenAfterFork; bool mHaveConfigFile; int mLogLevel; // need an int to do math with -<<<<<<< HEAD -======= std::string mLogFile; Log::Level mLogFileLevel; std::auto_ptr<FileLogger> mapLogFileLogger; ->>>>>>> 0.12 static Daemon *spDaemon; std::string mAppName; }; diff --git a/lib/server/Protocol.cpp b/lib/server/Protocol.cpp index 6333b1db..382f1c37 100644 --- a/lib/server/Protocol.cpp +++ b/lib/server/Protocol.cpp @@ -11,14 +11,9 @@ #include <sys/types.h> -<<<<<<< HEAD -#include <stdlib.h> -#include <string.h> -======= #include <cstdlib> #include <cstring> #include <cstdio> ->>>>>>> 0.12 #include <new> @@ -50,19 +45,6 @@ // // -------------------------------------------------------------------------- Protocol::Protocol(IOStream &rStream) -<<<<<<< HEAD - : mrStream(rStream), - mHandshakeDone(false), - mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), - mTimeout(PROTOCOL_DEFAULT_TIMEOUT), - mpBuffer(0), - mBufferSize(0), - mReadOffset(-1), - mWriteOffset(-1), - mValidDataSize(-1), - mLastErrorType(NoError), - mLastErrorSubType(NoError) -======= : mrStream(rStream), mHandshakeDone(false), mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), @@ -74,7 +56,6 @@ Protocol::Protocol(IOStream &rStream) mValidDataSize(-1), mLogToSysLog(false), mLogToFile(NULL) ->>>>>>> 0.12 { BOX_TRACE("Send block allocation size is " << PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK); @@ -102,37 +83,6 @@ Protocol::~Protocol() // -------------------------------------------------------------------------- // // Function -<<<<<<< HEAD -// Name: Protocol::GetLastError(int &, int &) -// Purpose: Returns true if there was an error, and type and subtype if there was. -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -bool Protocol::GetLastError(int &rTypeOut, int &rSubTypeOut) -{ - if(mLastErrorType == NoError) - { - // no error. - return false; - } - - // Return type and subtype in args - rTypeOut = mLastErrorType; - rSubTypeOut = mLastErrorSubType; - - // and unset them - mLastErrorType = NoError; - mLastErrorSubType = NoError; - - return true; -} - - -// -------------------------------------------------------------------------- -// -// Function -======= ->>>>>>> 0.12 // Name: Protocol::Handshake() // Purpose: Handshake with peer (exchange ident strings) // Created: 2003/08/20 @@ -150,11 +100,7 @@ void Protocol::Handshake() PW_Handshake hsSend; ::memset(&hsSend, 0, sizeof(hsSend)); // Copy in ident string -<<<<<<< HEAD - ::strncpy(hsSend.mIdent, GetIdentString(), sizeof(hsSend.mIdent)); -======= ::strncpy(hsSend.mIdent, GetProtocolIdentString(), sizeof(hsSend.mIdent)); ->>>>>>> 0.12 // Send it mrStream.Write(&hsSend, sizeof(hsSend)); @@ -227,11 +173,7 @@ void Protocol::CheckAndReadHdr(void *hdr) // Created: 2003/08/19 // // -------------------------------------------------------------------------- -<<<<<<< HEAD -std::auto_ptr<ProtocolObject> Protocol::Receive() -======= std::auto_ptr<Message> Protocol::ReceiveInternal() ->>>>>>> 0.12 { // Get object header PW_ObjectHeader objHeader; @@ -251,11 +193,7 @@ std::auto_ptr<Message> Protocol::ReceiveInternal() } // Create a blank object -<<<<<<< HEAD - std::auto_ptr<ProtocolObject> obj(MakeProtocolObject(ntohl(objHeader.mObjType))); -======= std::auto_ptr<Message> obj(MakeMessage(ntohl(objHeader.mObjType))); ->>>>>>> 0.12 // Make sure memory is allocated to read it into EnsureBufferAllocated(objSize); @@ -307,11 +245,7 @@ std::auto_ptr<Message> Protocol::ReceiveInternal() // Created: 2003/08/19 // // -------------------------------------------------------------------------- -<<<<<<< HEAD -void Protocol::Send(const ProtocolObject &rObject) -======= void Protocol::SendInternal(const Message &rObject) ->>>>>>> 0.12 { // Check usage if(mValidDataSize != -1 || mWriteOffset != -1 || mReadOffset != -1) @@ -754,8 +688,6 @@ void Protocol::SendStream(IOStream &rStream) // Can't send this using the fixed size header uncertainSize = true; } -<<<<<<< HEAD -======= if(streamSize == 0) { @@ -767,7 +699,6 @@ void Protocol::SendStream(IOStream &rStream) "Sending a stream with a definite size of zero " "is not allowed in the protocol"); } ->>>>>>> 0.12 // Inform sub class InformStreamSending(streamSize); @@ -907,9 +838,6 @@ int Protocol::SendStreamSendBlock(uint8_t *Block, int BytesInBlock) // -------------------------------------------------------------------------- void Protocol::InformStreamReceiving(u_int32_t Size) { -<<<<<<< HEAD - // Do nothing -======= if(GetLogToSysLog()) { if(Size == Protocol::ProtocolStream_SizeUncertain) @@ -930,7 +858,6 @@ void Protocol::InformStreamReceiving(u_int32_t Size) : "Receiving stream, size %d\n", Size); ::fflush(GetLogToFile()); } ->>>>>>> 0.12 } // -------------------------------------------------------------------------- @@ -943,9 +870,6 @@ void Protocol::InformStreamReceiving(u_int32_t Size) // -------------------------------------------------------------------------- void Protocol::InformStreamSending(u_int32_t Size) { -<<<<<<< HEAD - // Do nothing -======= if(GetLogToSysLog()) { if(Size == Protocol::ProtocolStream_SizeUncertain) @@ -966,7 +890,6 @@ void Protocol::InformStreamSending(u_int32_t Size) : "Sending stream, size %d\n", Size); ::fflush(GetLogToFile()); } ->>>>>>> 0.12 } diff --git a/lib/server/Protocol.h b/lib/server/Protocol.h index dc660ad5..42cb0ff8 100644 --- a/lib/server/Protocol.h +++ b/lib/server/Protocol.h @@ -12,22 +12,14 @@ #include <sys/types.h> -<<<<<<< HEAD -class IOStream; -#include "ProtocolObject.h" -======= ->>>>>>> 0.12 #include <memory> #include <vector> #include <string> -<<<<<<< HEAD -======= #include "Message.h" class IOStream; ->>>>>>> 0.12 // default timeout is 15 minutes #define PROTOCOL_DEFAULT_TIMEOUT (15*60*1000) // 16 default maximum object size -- should be enough @@ -50,13 +42,6 @@ public: private: Protocol(const Protocol &rToCopy); -<<<<<<< HEAD -public: - void Handshake(); - std::auto_ptr<ProtocolObject> Receive(); - void Send(const ProtocolObject &rObject); - -======= protected: // Unsafe to make public, as they may allow sending objects // from a different protocol. The derived class prevents this. @@ -65,7 +50,6 @@ protected: public: void Handshake(); ->>>>>>> 0.12 std::auto_ptr<IOStream> ReceiveStream(); void SendStream(IOStream &rStream); @@ -75,11 +59,6 @@ public: UnknownError = 0 }; -<<<<<<< HEAD - bool GetLastError(int &rTypeOut, int &rSubTypeOut); - -======= ->>>>>>> 0.12 // -------------------------------------------------------------------------- // // Function @@ -111,11 +90,7 @@ public: // -------------------------------------------------------------------------- void SetMaxObjectSize(unsigned int NewMaxObjSize) {mMaxObjectSize = NewMaxObjSize;} -<<<<<<< HEAD - // For ProtocolObject derived classes -======= // For Message derived classes ->>>>>>> 0.12 void Read(void *Buffer, int Size); void Read(std::string &rOut, int Size); void Read(int64_t &rOut); @@ -196,13 +171,6 @@ public: { ProtocolStream_SizeUncertain = 0xffffffff }; -<<<<<<< HEAD - -protected: - virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType) = 0; - virtual const char *GetIdentString() = 0; - void SetError(int Type, int SubType) {mLastErrorType = Type; mLastErrorSubType = SubType;} -======= bool GetLogToSysLog() { return mLogToSysLog; } FILE *GetLogToFile() { return mLogToFile; } void SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;} @@ -212,7 +180,6 @@ protected: virtual std::auto_ptr<Message> MakeMessage(int ObjType) = 0; virtual const char *GetProtocolIdentString() = 0; ->>>>>>> 0.12 void CheckAndReadHdr(void *hdr); // don't use type here to avoid dependency // Will be used for logging @@ -223,10 +190,6 @@ private: void EnsureBufferAllocated(int Size); int SendStreamSendBlock(uint8_t *Block, int BytesInBlock); -<<<<<<< HEAD -private: -======= ->>>>>>> 0.12 IOStream &mrStream; bool mHandshakeDone; unsigned int mMaxObjectSize; @@ -236,17 +199,12 @@ private: int mReadOffset; int mWriteOffset; int mValidDataSize; -<<<<<<< HEAD - int mLastErrorType; - int mLastErrorSubType; -======= bool mLogToSysLog; FILE *mLogToFile; }; class ProtocolContext { ->>>>>>> 0.12 }; #endif // PROTOCOL__H diff --git a/lib/server/ProtocolObject.cpp b/lib/server/ProtocolObject.cpp deleted file mode 100644 index fb09f820..00000000 --- a/lib/server/ProtocolObject.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// -------------------------------------------------------------------------- -// -// File -// Name: ProtocolObject.h -// Purpose: Protocol object base class -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- - -#include "Box.h" -#include "ProtocolObject.h" -#include "CommonException.h" - -#include "MemLeakFindOn.h" - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::ProtocolObject() -// Purpose: Default constructor -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -ProtocolObject::ProtocolObject() -{ -} - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::ProtocolObject() -// Purpose: Destructor -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -ProtocolObject::~ProtocolObject() -{ -} - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::ProtocolObject() -// Purpose: Copy constructor -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -ProtocolObject::ProtocolObject(const ProtocolObject &rToCopy) -{ -} - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::IsError(int &, int &) -// Purpose: Does this represent an error, and if so, what is the type and subtype? -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -bool ProtocolObject::IsError(int &rTypeOut, int &rSubTypeOut) const -{ - return false; -} - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::IsConversationEnd() -// Purpose: Does this command end the conversation? -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -bool ProtocolObject::IsConversationEnd() const -{ - return false; -} - - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::GetType() -// Purpose: Return type of the object -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -int ProtocolObject::GetType() const -{ - // This isn't implemented in the base class! - THROW_EXCEPTION(CommonException, Internal) -} - - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::SetPropertiesFromStreamData(Protocol &) -// Purpose: Set the properties of the object from the stream data ready in the Protocol object -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -void ProtocolObject::SetPropertiesFromStreamData(Protocol &rProtocol) -{ - // This isn't implemented in the base class! - THROW_EXCEPTION(CommonException, Internal) -} - - - -// -------------------------------------------------------------------------- -// -// Function -// Name: ProtocolObject::WritePropertiesToStreamData(Protocol &) -// Purpose: Write the properties of the object into the stream data in the Protocol object -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -void ProtocolObject::WritePropertiesToStreamData(Protocol &rProtocol) const -{ - // This isn't implemented in the base class! - THROW_EXCEPTION(CommonException, Internal) -} - - - diff --git a/lib/server/ProtocolObject.h b/lib/server/ProtocolObject.h deleted file mode 100644 index 0a127ab5..00000000 --- a/lib/server/ProtocolObject.h +++ /dev/null @@ -1,41 +0,0 @@ -// -------------------------------------------------------------------------- -// -// File -// Name: ProtocolObject.h -// Purpose: Protocol object base class -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- - -#ifndef PROTOCOLOBJECT__H -#define PROTOCOLOBJECT__H - -class Protocol; - -// -------------------------------------------------------------------------- -// -// Class -// Name: ProtocolObject -// Purpose: Basic object representation of objects to pass through a Protocol session -// Created: 2003/08/19 -// -// -------------------------------------------------------------------------- -class ProtocolObject -{ -public: - ProtocolObject(); - virtual ~ProtocolObject(); - ProtocolObject(const ProtocolObject &rToCopy); - - // Info about this object - virtual int GetType() const; - virtual bool IsError(int &rTypeOut, int &rSubTypeOut) const; - virtual bool IsConversationEnd() const; - - // reading and writing with Protocol objects - virtual void SetPropertiesFromStreamData(Protocol &rProtocol); - virtual void WritePropertiesToStreamData(Protocol &rProtocol) const; -}; - -#endif // PROTOCOLOBJECT__H - diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp index 6feaae4a..004d2d98 100644 --- a/lib/server/SSLLib.cpp +++ b/lib/server/SSLLib.cpp @@ -18,10 +18,7 @@ #include <wincrypt.h> #endif -<<<<<<< HEAD -======= #include "CryptoUtils.h" ->>>>>>> 0.12 #include "SSLLib.h" #include "ServerException.h" @@ -43,14 +40,9 @@ void SSLLib::Initialise() { if(!::SSL_library_init()) { -<<<<<<< HEAD - LogError("initialising OpenSSL"); - THROW_EXCEPTION(ServerException, SSLLibraryInitialisationError) -======= THROW_EXCEPTION_MESSAGE(ServerException, SSLLibraryInitialisationError, CryptoUtils::LogError("initialising OpenSSL")); ->>>>>>> 0.12 } // More helpful error messages @@ -99,26 +91,3 @@ void SSLLib::Initialise() } -<<<<<<< HEAD -// -------------------------------------------------------------------------- -// -// Function -// Name: SSLLib::LogError(const char *) -// Purpose: Logs an error -// Created: 2003/08/06 -// -// -------------------------------------------------------------------------- -void SSLLib::LogError(const std::string& rErrorDuringAction) -{ - unsigned long errcode; - char errname[256]; // SSL docs say at least 120 bytes - while((errcode = ERR_get_error()) != 0) - { - ::ERR_error_string_n(errcode, errname, sizeof(errname)); - BOX_ERROR("SSL error while " << rErrorDuringAction << ": " << - errname); - } -} - -======= ->>>>>>> 0.12 diff --git a/lib/server/SSLLib.h b/lib/server/SSLLib.h index b679d623..d11c7804 100644 --- a/lib/server/SSLLib.h +++ b/lib/server/SSLLib.h @@ -29,10 +29,6 @@ namespace SSLLib { void Initialise(); -<<<<<<< HEAD - void LogError(const std::string& rErrorDuringAction); -======= ->>>>>>> 0.12 }; #endif // SSLLIB__H diff --git a/lib/server/ServerException.txt b/lib/server/ServerException.txt index f8c558c6..474b4067 100644 --- a/lib/server/ServerException.txt +++ b/lib/server/ServerException.txt @@ -13,11 +13,7 @@ SocketOpenError 10 SocketPollError 11 SocketCloseError 13 SocketNameUNIXPathTooLong 14 -<<<<<<< HEAD -SocketBindError 16 Check the ListenAddresses directive in your config file -- must refer to local IP addresses only -======= SocketBindError 16 Check the ListenAddresses directive (bbstored) or CommandSocket (bbackupd) in your config file -- must refer to local IP addresses (or existing writable path) only ->>>>>>> 0.12 SocketAcceptError 17 ServerStreamBadListenAddrs 18 ServerForkError 19 diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 8625832d..a9b56169 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -48,8 +48,6 @@ private: ServerStream(const ServerStream &rToCopy) { } -<<<<<<< HEAD -======= std::string mConnectionDetails; @@ -59,7 +57,6 @@ protected: return mConnectionDetails; } ->>>>>>> 0.12 public: virtual const char *DaemonName() const @@ -134,13 +131,10 @@ public: protected: virtual void NotifyListenerIsReady() { } -<<<<<<< HEAD -======= virtual void LogConnectionDetails(std::string details) { BOX_NOTICE("Handling incoming connection from " << details); } ->>>>>>> 0.12 public: virtual void Run2(bool &rChildExit) @@ -256,14 +250,9 @@ public: { // Get the incoming connection // (with zero wait time) -<<<<<<< HEAD - std::string logMessage; - std::auto_ptr<StreamType> connection(psocket->Accept(0, &logMessage)); -======= std::auto_ptr<StreamType> connection( psocket->Accept(0, &mConnectionDetails)); ->>>>>>> 0.12 // Was there one (there should be...) if(connection.get()) @@ -289,10 +278,7 @@ public: // Set up daemon EnterChild(); SetProcessTitle("transaction"); -<<<<<<< HEAD -======= LogConnectionDetails(mConnectionDetails); ->>>>>>> 0.12 // Memory leak test the forked process #ifdef BOX_MEMORY_LEAK_TESTING @@ -310,13 +296,9 @@ public: } // Log it -<<<<<<< HEAD - BOX_NOTICE("Message from child process " << pid << ": " << logMessage); -======= BOX_TRACE("Forked child process " << pid << " to handle connection from " << mConnectionDetails); ->>>>>>> 0.12 } else { diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 69a11330..f2a4996b 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -123,32 +123,8 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, // -------------------------------------------------------------------------- void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrlen) { -<<<<<<< HEAD - if(addr == NULL) {THROW_EXCEPTION(CommonException, BadArguments)} - - switch(addr->sa_family) - { - case AF_UNIX: - BOX_INFO("Incoming connection from local (UNIX socket)"); - break; - - case AF_INET: - { - sockaddr_in *a = (sockaddr_in*)addr; - BOX_INFO("Incoming connection from " << - inet_ntoa(a->sin_addr) << " port " << - ntohs(a->sin_port)); - } - break; - - default: - BOX_WARNING("Incoming connection of unknown type"); - break; - } -======= BOX_INFO("Incoming connection from " << IncomingConnectionLogMessage(addr, addrlen)); ->>>>>>> 0.12 } // -------------------------------------------------------------------------- @@ -166,40 +142,25 @@ std::string Socket::IncomingConnectionLogMessage(const struct sockaddr *addr, so switch(addr->sa_family) { case AF_UNIX: -<<<<<<< HEAD - return std::string("Incoming connection from local (UNIX socket)"); -======= return std::string("local (UNIX socket)"); ->>>>>>> 0.12 break; case AF_INET: { -<<<<<<< HEAD - char msg[256]; // more than enough - sockaddr_in *a = (sockaddr_in*)addr; - sprintf(msg, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port)); - return std::string(msg); -======= sockaddr_in *a = (sockaddr_in*)addr; std::ostringstream oss; oss << inet_ntoa(a->sin_addr) << " port " << ntohs(a->sin_port); return oss.str(); ->>>>>>> 0.12 } break; default: -<<<<<<< HEAD - return std::string("Incoming connection of unknown type"); -======= { std::ostringstream oss; oss << "unknown socket type " << addr->sa_family; return oss.str(); } ->>>>>>> 0.12 break; } diff --git a/lib/server/SocketListen.h b/lib/server/SocketListen.h index 635b15e8..39c60ba6 100644 --- a/lib/server/SocketListen.h +++ b/lib/server/SocketListen.h @@ -87,24 +87,16 @@ public: { Close(); } -<<<<<<< HEAD -======= ->>>>>>> 0.12 private: SocketListen(const SocketListen &rToCopy) { } -<<<<<<< HEAD -public: - -======= int mType, mPort; std::string mName; public: ->>>>>>> 0.12 enum { MaxMultipleListenSockets = MaxMultiListenSockets @@ -120,13 +112,8 @@ public: if(::close(mSocketHandle) == -1) #endif { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to close network " - "socket"); -======= BOX_LOG_SOCKET_ERROR(mType, mName, mPort, "Failed to close network socket"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketCloseError) } @@ -144,13 +131,10 @@ public: // ------------------------------------------------------------------ void Listen(Socket::Type Type, const char *Name, int Port = 0) { -<<<<<<< HEAD -======= mType = Type; mName = Name; mPort = Port; ->>>>>>> 0.12 if(mSocketHandle != -1) { THROW_EXCEPTION(ServerException, SocketAlreadyOpen); @@ -168,12 +152,8 @@ public: 0 /* let OS choose protocol */); if(mSocketHandle == -1) { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to create a network socket"); -======= BOX_LOG_SOCKET_ERROR(Type, Name, Port, "Failed to create a network socket"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -187,12 +167,8 @@ public: &option, sizeof(option)) == -1) #endif { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to set socket options"); -======= BOX_LOG_SOCKET_ERROR(Type, Name, Port, "Failed to set socket options"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -200,12 +176,6 @@ public: if(::bind(mSocketHandle, &addr.sa_generic, addrLen) == -1 || ::listen(mSocketHandle, ListenBacklog) == -1) { -<<<<<<< HEAD - // Dispose of the socket - ::close(mSocketHandle); - mSocketHandle = -1; - THROW_EXCEPTION(ServerException, SocketBindError) -======= int err_number = errno; BOX_LOG_SOCKET_ERROR(Type, Name, Port, @@ -218,7 +188,6 @@ public: THROW_SYS_FILE_ERRNO("Failed to bind or listen " "on socket", Name, err_number, ServerException, SocketBindError); ->>>>>>> 0.12 } } @@ -271,11 +240,7 @@ public: // signal? if(errno == EINTR) { -<<<<<<< HEAD - BOX_ERROR("Failed to accept " -======= BOX_INFO("Failed to accept " ->>>>>>> 0.12 "connection: interrupted by " "signal"); // return nothing @@ -283,13 +248,8 @@ public: } else { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to poll " - "connection"); -======= BOX_LOG_SOCKET_ERROR(mType, mName, mPort, "Failed to poll connection"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketPollError) } @@ -308,12 +268,8 @@ public: // Got socket (or error), unlock (implicit in destruction) if(sock == -1) { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to accept connection"); -======= BOX_LOG_SOCKET_ERROR(mType, mName, mPort, "Failed to accept connection"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketAcceptError) } diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index 7c92ebba..6ef4b8d1 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -154,24 +154,16 @@ void SocketStream::Open(Socket::Type Type, const std::string& rName, int Port) int sockDomain = 0; SocketAllAddr addr; int addrLen = 0; -<<<<<<< HEAD - Socket::NameLookupToSockAddr(addr, sockDomain, Type, rName, Port, addrLen); -======= Socket::NameLookupToSockAddr(addr, sockDomain, Type, rName, Port, addrLen); ->>>>>>> 0.12 // Create the socket mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */); if(mSocketHandle == INVALID_SOCKET_VALUE) { -<<<<<<< HEAD - BOX_LOG_SYS_ERROR("Failed to create a network socket"); -======= BOX_LOG_SOCKET_ERROR(Type, rName, Port, "Failed to create a network socket"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -179,24 +171,11 @@ void SocketStream::Open(Socket::Type Type, const std::string& rName, int Port) if(::connect(mSocketHandle, &addr.sa_generic, addrLen) == -1) { // Dispose of the socket -<<<<<<< HEAD -#ifdef WIN32 - DWORD err = WSAGetLastError(); - ::closesocket(mSocketHandle); - BOX_LOG_WIN_ERROR_NUMBER("Failed to connect to socket " - "(type " << Type << ", name " << rName << - ", port " << Port << ")", err); -#else // !WIN32 - BOX_LOG_SYS_ERROR("Failed to connect to socket (type " << - Type << ", name " << rName << ", port " << Port << - ")"); -======= BOX_LOG_SOCKET_ERROR(Type, rName, Port, "Failed to connect to socket"); #ifdef WIN32 ::closesocket(mSocketHandle); #else // !WIN32 ->>>>>>> 0.12 ::close(mSocketHandle); #endif // WIN32 diff --git a/lib/server/SocketStream.h b/lib/server/SocketStream.h index aa62e4e9..2fb5e391 100644 --- a/lib/server/SocketStream.h +++ b/lib/server/SocketStream.h @@ -51,10 +51,6 @@ public: virtual bool GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut); protected: -<<<<<<< HEAD - tOSSocketHandle GetSocketHandle(); -======= ->>>>>>> 0.12 void MarkAsReadClosed() {mReadClosed = true;} void MarkAsWriteClosed() {mWriteClosed = true;} @@ -72,14 +68,11 @@ public: off_t GetBytesWritten() const {return mBytesWritten;} void ResetCounters() {mBytesRead = mBytesWritten = 0;} bool IsOpened() { return mSocketHandle != INVALID_SOCKET_VALUE; } -<<<<<<< HEAD -======= /** * Only for use by NiceSocketStream! */ tOSSocketHandle GetSocketHandle(); ->>>>>>> 0.12 }; #endif // SOCKETSTREAM__H diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp index 6f1cc46a..576b53a2 100644 --- a/lib/server/SocketStreamTLS.cpp +++ b/lib/server/SocketStreamTLS.cpp @@ -19,20 +19,12 @@ #include <poll.h> #endif -<<<<<<< HEAD -#include "SocketStreamTLS.h" -#include "SSLLib.h" -#include "ServerException.h" -#include "TLSContext.h" -#include "BoxTime.h" -======= #include "BoxTime.h" #include "CryptoUtils.h" #include "ServerException.h" #include "SocketStreamTLS.h" #include "SSLLib.h" #include "TLSContext.h" ->>>>>>> 0.12 #include "MemLeakFindOn.h" @@ -133,11 +125,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) mpBIO = ::BIO_new(::BIO_s_socket()); if(mpBIO == 0) { -<<<<<<< HEAD - SSLLib::LogError("creating socket bio"); -======= CryptoUtils::LogError("creating socket bio"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSAllocationFailed) } @@ -148,11 +136,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) mpSSL = ::SSL_new(rContext.GetRawContext()); if(mpSSL == 0) { -<<<<<<< HEAD - SSLLib::LogError("creating SSL object"); -======= CryptoUtils::LogError("creating SSL object"); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSAllocationFailed) } @@ -220,20 +204,12 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) // Error occured if(IsServer) { -<<<<<<< HEAD - SSLLib::LogError("accepting connection"); -======= CryptoUtils::LogError("accepting connection"); ->>>>>>> 0.12 THROW_EXCEPTION(ConnectionException, Conn_TLSHandshakeFailed) } else { -<<<<<<< HEAD - SSLLib::LogError("connecting"); -======= CryptoUtils::LogError("connecting"); ->>>>>>> 0.12 THROW_EXCEPTION(ConnectionException, Conn_TLSHandshakeFailed) } } @@ -360,11 +336,7 @@ int SocketStreamTLS::Read(void *pBuffer, int NBytes, int Timeout) break; default: -<<<<<<< HEAD - SSLLib::LogError("reading"); -======= CryptoUtils::LogError("reading"); ->>>>>>> 0.12 THROW_EXCEPTION(ConnectionException, Conn_TLSReadFailed) break; } @@ -429,11 +401,7 @@ void SocketStreamTLS::Write(const void *pBuffer, int NBytes) break; default: -<<<<<<< HEAD - SSLLib::LogError("writing"); -======= CryptoUtils::LogError("writing"); ->>>>>>> 0.12 THROW_EXCEPTION(ConnectionException, Conn_TLSWriteFailed) break; } @@ -475,11 +443,7 @@ void SocketStreamTLS::Shutdown(bool Read, bool Write) if(::SSL_shutdown(mpSSL) < 0) { -<<<<<<< HEAD - SSLLib::LogError("shutting down"); -======= CryptoUtils::LogError("shutting down"); ->>>>>>> 0.12 THROW_EXCEPTION(ConnectionException, Conn_TLSShutdownFailed) } diff --git a/lib/server/TLSContext.cpp b/lib/server/TLSContext.cpp index 1f06d602..341043e9 100644 --- a/lib/server/TLSContext.cpp +++ b/lib/server/TLSContext.cpp @@ -12,11 +12,7 @@ #define TLS_CLASS_IMPLEMENTATION_CPP #include <openssl/ssl.h> -<<<<<<< HEAD -#include "TLSContext.h" -======= #include "CryptoUtils.h" ->>>>>>> 0.12 #include "ServerException.h" #include "SSLLib.h" #include "TLSContext.h" @@ -81,22 +77,14 @@ void TLSContext::Initialise(bool AsServer, const char *CertificatesFile, const c { std::string msg = "loading certificates from "; msg += CertificatesFile; -<<<<<<< HEAD - SSLLib::LogError(msg); -======= CryptoUtils::LogError(msg); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSLoadCertificatesFailed) } if(::SSL_CTX_use_PrivateKey_file(mpContext, PrivateKeyFile, SSL_FILETYPE_PEM) != 1) { std::string msg = "loading private key from "; msg += PrivateKeyFile; -<<<<<<< HEAD - SSLLib::LogError(msg); -======= CryptoUtils::LogError(msg); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSLoadPrivateKeyFailed) } @@ -105,11 +93,7 @@ void TLSContext::Initialise(bool AsServer, const char *CertificatesFile, const c { std::string msg = "loading CA cert from "; msg += TrustedCAsFile; -<<<<<<< HEAD - SSLLib::LogError(msg); -======= CryptoUtils::LogError(msg); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSLoadTrustedCAsFailed) } @@ -121,11 +105,7 @@ void TLSContext::Initialise(bool AsServer, const char *CertificatesFile, const c // Setup allowed ciphers if(::SSL_CTX_set_cipher_list(mpContext, CIPHER_LIST) != 1) { -<<<<<<< HEAD - SSLLib::LogError("setting cipher list to " CIPHER_LIST); -======= CryptoUtils::LogError("setting cipher list to " CIPHER_LIST); ->>>>>>> 0.12 THROW_EXCEPTION(ServerException, TLSSetCiphersFailed) } } diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in index 9caa970d..a074b435 100755 --- a/lib/server/makeprotocol.pl.in +++ b/lib/server/makeprotocol.pl.in @@ -30,26 +30,6 @@ my %log_display_types = 'string' => ['%s', 'VAR.c_str()'] ); -<<<<<<< HEAD - - -my ($type, $file) = @ARGV; - -if($type ne 'Server' && $type ne 'Client') -{ - die "Neither Server or Client is specified on command line\n"; -} - -open IN, $file or die "Can't open input file $file\n"; - -print "Making $type protocol classes from $file...\n"; - -my @extra_header_files; - -my $implement_syslog = 0; -my $implement_filelog = 0; - -======= if (@ARGV != 1) { die "Usage: $0 <protocol-txt-file>\n"; @@ -63,7 +43,6 @@ print "Making protocol classes from $file...\n"; my @extra_header_files; ->>>>>>> 0.12 # read attributes my %attr; while(<IN>) @@ -75,43 +54,6 @@ while(<IN>) my ($k,$v) = split /\s+/,$l,2; -<<<<<<< HEAD - if($k eq 'ClientType') - { - add_type($v) if $type eq 'Client'; - } - elsif($k eq 'ServerType') - { - add_type($v) if $type eq 'Server'; - } - elsif($k eq 'ImplementLog') - { - my ($log_if_type,$log_type) = split /\s+/,$v; - if($type eq $log_if_type) - { - if($log_type eq 'syslog') - { - $implement_syslog = 1; - } - elsif($log_type eq 'file') - { - $implement_filelog = 1; - } - else - { - printf("ERROR: Unknown log type for implementation: $log_type\n"); - exit(1); - } - } - } - elsif($k eq 'LogTypeToText') - { - my ($log_if_type,$type_name,$printf_format,$arg_template) = split /\s+/,$v; - if($type eq $log_if_type) - { - $log_display_types{$type_name} = [$printf_format,$arg_template] - } -======= if($k eq 'AddType') { add_type($v); @@ -124,7 +66,6 @@ while(<IN>) { my ($type_name,$printf_format,$arg_template) = split /\s+/,$v; $log_display_types{$type_name} = [$printf_format,$arg_template] ->>>>>>> 0.12 } else { @@ -200,11 +141,6 @@ close IN; # open files -<<<<<<< HEAD -my $h_filename = 'autogen_'.$protocol_name.'Protocol'.$type.'.h'; -open CPP,'>autogen_'.$protocol_name.'Protocol'.$type.'.cpp'; -open H,">$h_filename"; -======= my $filename_base = 'autogen_'.$protocol_name.'Protocol'; print "Writing $filename_base.cpp\n"; print "Writing $filename_base.h\n"; @@ -212,7 +148,6 @@ open CPP, "> $filename_base.cpp"; open H, "> $filename_base.h"; my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol_H'; ->>>>>>> 0.12 print CPP <<__E; @@ -222,41 +157,16 @@ print CPP <<__E; #include <sstream> -<<<<<<< HEAD -#include "$h_filename" -#include "IOStream.h" - -__E - -if($implement_syslog) -{ - print H <<EOF; -#ifndef WIN32 -#include <syslog.h> -#endif -EOF -} - - -my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol'.$type.'_H'; -print H <<__E; - -======= #include "$filename_base.h" #include "IOStream.h" __E print H <<__E; ->>>>>>> 0.12 // Auto-generated file -- do not edit #ifndef $guardname #define $guardname -<<<<<<< HEAD -#include "Protocol.h" -#include "ProtocolObject.h" -======= #include <cstdio> #include <list> @@ -266,128 +176,16 @@ print H <<__E; #include "Protocol.h" #include "Message.h" ->>>>>>> 0.12 #include "ServerException.h" class IOStream; -<<<<<<< HEAD -__E - -if($implement_filelog) -{ - print H qq~#include <stdio.h>\n~; -} -======= __E ->>>>>>> 0.12 # extra headers for(@extra_header_files) { -<<<<<<< HEAD - print H qq~#include "$_"\n~ -} -print H "\n"; - -if($type eq 'Server') -{ - # need utils file for the server - print H '#include "Utils.h"',"\n\n" -} - - -my $derive_objects_from = 'ProtocolObject'; -my $objects_extra_h = ''; -my $objects_extra_cpp = ''; -if($type eq 'Server') -{ - # define the context - print H "class $context_class;\n\n"; - print CPP "#include \"$context_class_inc\"\n\n"; - - # change class we derive the objects from - $derive_objects_from = $protocol_name.'ProtocolObject'; - - $objects_extra_h = <<__E; - virtual std::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); -__E - $objects_extra_cpp = <<__E; -std::auto_ptr<ProtocolObject> ${derive_objects_from}::DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext) -{ - THROW_EXCEPTION(ConnectionException, Conn_Protocol_TriedToExecuteReplyCommand) -} -__E -} - -print CPP qq~#include "MemLeakFindOn.h"\n~; - -if($type eq 'Client' && ($implement_syslog || $implement_filelog)) -{ - # change class we derive the objects from - $derive_objects_from = $protocol_name.'ProtocolObjectCl'; -} -if($implement_syslog) -{ - $objects_extra_h .= <<__E; - virtual void LogSysLog(const char *Action) const = 0; -__E -} -if($implement_filelog) -{ - $objects_extra_h .= <<__E; - virtual void LogFile(const char *Action, FILE *file) const = 0; -__E -} - -if($derive_objects_from ne 'ProtocolObject') -{ - # output a definition for the protocol object derived class - print H <<__E; -class ${protocol_name}ProtocolServer; - -class $derive_objects_from : public ProtocolObject -{ -public: - $derive_objects_from(); - virtual ~$derive_objects_from(); - $derive_objects_from(const $derive_objects_from &rToCopy); - -$objects_extra_h -}; -__E - - # and some cpp definitions - print CPP <<__E; -${derive_objects_from}::${derive_objects_from}() -{ -} -${derive_objects_from}::~${derive_objects_from}() -{ -} -${derive_objects_from}::${derive_objects_from}(const $derive_objects_from &rToCopy) -{ -} -$objects_extra_cpp -__E -} - - - -my $classname_base = $protocol_name.'Protocol'.$type; - -# output the classes -for my $cmd (@cmd_list) -{ - print H <<__E; -class $classname_base$cmd : public $derive_objects_from -{ -public: - $classname_base$cmd(); - $classname_base$cmd(const $classname_base$cmd &rToCopy); - ~$classname_base$cmd(); -======= print H qq@#include "$_"\n@; } @@ -473,17 +271,13 @@ public: $cmd_class(); $cmd_class(const $cmd_class &rToCopy); ~$cmd_class(); ->>>>>>> 0.12 int GetType() const; enum { TypeID = $cmd_id{$cmd} }; __E -<<<<<<< HEAD -======= ->>>>>>> 0.12 # constants if(exists $cmd_constants{$cmd}) { @@ -491,82 +285,18 @@ __E print H join(",\n\t\t",@{$cmd_constants{$cmd}}); print H "\n\t};\n"; } -<<<<<<< HEAD -======= ->>>>>>> 0.12 # flags if(obj_is_type($cmd,'EndsConversation')) { print H "\tbool IsConversationEnd() const;\n"; } -<<<<<<< HEAD -======= ->>>>>>> 0.12 if(obj_is_type($cmd,'IsError')) { print H "\tbool IsError(int &rTypeOut, int &rSubTypeOut) const;\n"; print H "\tstd::string GetMessage() const;\n"; } -<<<<<<< HEAD - if($type eq 'Server' && obj_is_type($cmd, 'Command')) - { - print H "\tstd::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); // IMPLEMENT THIS\n" - } - - # want to be able to read from streams? - my $read_from_streams = (obj_is_type($cmd,'Command') && $type eq 'Server') || (obj_is_type($cmd,'Reply') && $type eq 'Client'); - my $write_to_streams = (obj_is_type($cmd,'Command') && $type eq 'Client') || (obj_is_type($cmd,'Reply') && $type eq 'Server'); - - if($read_from_streams) - { - print H "\tvoid SetPropertiesFromStreamData(Protocol &rProtocol);\n"; - - # write Get functions - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - print H "\t".translate_type_to_arg_type($ty)." Get$nm() {return m$nm;}\n"; - } - } - my $param_con_args = ''; - if($write_to_streams) - { - # extra constructor? - if($#{$cmd_contents{$cmd}} >= 0) - { - my @a; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - push @a,translate_type_to_arg_type($ty)." $nm"; - } - $param_con_args = join(', ',@a); - print H "\t$classname_base$cmd(".$param_con_args.");\n"; - } - print H "\tvoid WritePropertiesToStreamData(Protocol &rProtocol) const;\n"; - # set functions - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - print H "\tvoid Set$nm(".translate_type_to_arg_type($ty)." $nm) {m$nm = $nm;}\n"; - } - } - - if($implement_syslog) - { - print H "\tvirtual void LogSysLog(const char *Action) const;\n"; - } - if($implement_filelog) - { - print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; - } - -======= if(obj_is_type($cmd, 'Command')) { @@ -613,7 +343,6 @@ __E print H "\tvirtual void LogSysLog(const char *Action) const;\n"; print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; print H "\tvirtual std::string ToString() const;\n"; ->>>>>>> 0.12 # write member variables and setup for cpp file my @def_constructor_list; @@ -647,20 +376,6 @@ __E my $param_con_vars = join(",\n\t ",@param_constructor_list); $param_con_vars = "\n\t: ".$param_con_vars if $param_con_vars ne ''; -<<<<<<< HEAD - my $class = "$classname_base$cmd".'::'; - print CPP <<__E; -$class$classname_base$cmd()$def_con_vars -{ -} -$class$classname_base$cmd(const $classname_base$cmd &rToCopy)$copy_con_vars -{ -} -$class~$classname_base$cmd() -{ -} -int ${class}GetType() const -======= print CPP <<__E; $cmd_class\::$cmd_class()$def_con_vars { @@ -672,56 +387,10 @@ $cmd_class\::~$cmd_class() { } int $cmd_class\::GetType() const ->>>>>>> 0.12 { return $cmd_id{$cmd}; } __E -<<<<<<< HEAD - if($read_from_streams) - { - print CPP "void ${class}SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - if($ty =~ m/\Avector/) - { - print CPP "\trProtocol.ReadVector(m$nm);\n"; - } - else - { - print CPP "\trProtocol.Read(m$nm);\n"; - } - } - print CPP "}\n"; - } - if($write_to_streams) - { - # implement extra constructor? - if($param_con_vars ne '') - { - print CPP "$class$classname_base$cmd($param_con_args)$param_con_vars\n{\n}\n"; - } - print CPP "void ${class}WritePropertiesToStreamData(Protocol &rProtocol) const\n{\n"; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - if($ty =~ m/\Avector/) - { - print CPP "\trProtocol.WriteVector(m$nm);\n"; - } - else - { - print CPP "\trProtocol.Write(m$nm);\n"; - } - } - print CPP "}\n"; - } - if(obj_is_type($cmd,'EndsConversation')) - { - print CPP "bool ${class}IsConversationEnd() const\n{\n\treturn true;\n}\n"; - } -======= print CPP "void $cmd_class\::SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) { @@ -762,27 +431,18 @@ __E print CPP "bool $cmd_class\::IsConversationEnd() const\n{\n\treturn true;\n}\n"; } ->>>>>>> 0.12 if(obj_is_type($cmd,'IsError')) { # get parameters my ($mem_type,$mem_subtype) = split /,/,obj_get_type_params($cmd,'IsError'); print CPP <<__E; -<<<<<<< HEAD -bool ${class}IsError(int &rTypeOut, int &rSubTypeOut) const -======= bool $cmd_class\::IsError(int &rTypeOut, int &rSubTypeOut) const ->>>>>>> 0.12 { rTypeOut = m$mem_type; rSubTypeOut = m$mem_subtype; return true; } -<<<<<<< HEAD -std::string ${class}GetMessage() const -======= std::string $cmd_class\::GetMessage() const ->>>>>>> 0.12 { switch(m$mem_subtype) { @@ -806,149 +466,6 @@ __E __E } -<<<<<<< HEAD - if($implement_syslog) - { - my ($log) = make_log_strings_framework($cmd); - print CPP <<__E; -void ${class}LogSysLog(const char *Action) const -{ - BOX_TRACE($log); -} -__E - } - if($implement_filelog) - { - my ($log) = make_log_strings_framework($cmd); - print CPP <<__E; -void ${class}LogFile(const char *Action, FILE *File) const -{ - std::ostringstream oss; - oss << $log; - ::fprintf(File, "%s\\n", oss.str().c_str()); - ::fflush(File); -} -__E - } -} - -# finally, the protocol object itself -print H <<__E; -class $classname_base : public Protocol -{ -public: - $classname_base(IOStream &rStream); - virtual ~$classname_base(); - - std::auto_ptr<$derive_objects_from> Receive(); - void Send(const ${derive_objects_from} &rObject); -__E -if($implement_syslog) -{ - print H "\tvoid SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;}\n"; -} -if($implement_filelog) -{ - print H "\tvoid SetLogToFile(FILE *File = 0) {mLogToFile = File;}\n"; -} -if($type eq 'Server') -{ - # need to put in the conversation function - print H "\tvoid DoServer($context_class &rContext);\n\n"; - # and the send vector thing - print H "\tvoid SendStreamAfterCommand(IOStream *pStream);\n\n"; -} -if($type eq 'Client') -{ - # add plain object taking query functions - my $with_params; - for my $cmd (@cmd_list) - { - if(obj_is_type($cmd,'Command')) - { - my $has_stream = obj_is_type($cmd,'StreamWithCommand'); - my $argextra = $has_stream?', IOStream &rStream':''; - my $queryextra = $has_stream?', rStream':''; - my $reply = obj_get_type_params($cmd,'Command'); - print H "\tstd::auto_ptr<$classname_base$reply> Query(const $classname_base$cmd &rQuery$argextra);\n"; - my @a; - my @na; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - push @a,translate_type_to_arg_type($ty)." $nm"; - push @na,"$nm"; - } - my $ar = join(', ',@a); - my $nar = join(', ',@na); - $nar = "($nar)" if $nar ne ''; - - $with_params .= "\tinline std::auto_ptr<$classname_base$reply> Query$cmd($ar$argextra)\n\t{\n"; - $with_params .= "\t\t$classname_base$cmd send$nar;\n"; - $with_params .= "\t\treturn Query(send$queryextra);\n"; - $with_params .= "\t}\n"; - } - } - # quick hack to correct bad argument lists for commands with zero paramters but with streams - $with_params =~ s/\(, /(/g; - print H "\n",$with_params,"\n"; -} -print H <<__E; -private: - $classname_base(const $classname_base &rToCopy); -__E -if($type eq 'Server') -{ - # need to put the streams to send vector - print H "\tstd::vector<IOStream*> mStreamsToSend;\n\tvoid DeleteStreamsToSend();\n"; -} - -if($implement_filelog || $implement_syslog) -{ - print H <<__E; - virtual void InformStreamReceiving(u_int32_t Size); - virtual void InformStreamSending(u_int32_t Size); -__E -} - -if($implement_syslog) -{ - print H "private:\n\tbool mLogToSysLog;\n"; -} -if($implement_filelog) -{ - print H "private:\n\tFILE *mLogToFile;\n"; -} -print H <<__E; - -protected: - virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType); - virtual const char *GetIdentString(); -}; - -__E - -my $constructor_extra = ''; -$constructor_extra .= ', mLogToSysLog(false)' if $implement_syslog; -$constructor_extra .= ', mLogToFile(0)' if $implement_filelog; - -my $destructor_extra = ($type eq 'Server')?"\n\tDeleteStreamsToSend();":''; - -my $prefix = $classname_base.'::'; -print CPP <<__E; -$prefix$classname_base(IOStream &rStream) - : Protocol(rStream)$constructor_extra -{ -} -$prefix~$classname_base() -{$destructor_extra -} -const char *${prefix}GetIdentString() -{ - return "$ident_string"; -} -std::auto_ptr<ProtocolObject> ${prefix}MakeProtocolObject(int ObjType) -======= my ($log) = make_log_strings_framework($cmd); print CPP <<__E; std::string $cmd_class\::ToString() const @@ -1388,25 +905,11 @@ __E # write receive and send functions print CPP <<__E; std::auto_ptr<Message> $server_or_client_class\::MakeMessage(int ObjType) ->>>>>>> 0.12 { switch(ObjType) { __E -<<<<<<< HEAD -# do objects within this -for my $cmd (@cmd_list) -{ - print CPP <<__E; - case $cmd_id{$cmd}: - return std::auto_ptr<ProtocolObject>(new $classname_base$cmd); - break; -__E -} - -print CPP <<__E; -======= # do objects within this for my $cmd (@cmd_list) { @@ -1418,40 +921,11 @@ __E } print CPP <<__E; ->>>>>>> 0.12 default: THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnknownCommandRecieved) } } __E -<<<<<<< HEAD -# write receive and send functions -print CPP <<__E; -std::auto_ptr<$derive_objects_from> ${prefix}Receive() -{ - std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(Protocol::Receive().release())); - -__E - if($implement_syslog) - { - print CPP <<__E; - if(mLogToSysLog) - { - preply->LogSysLog("Receive"); - } -__E - } - if($implement_filelog) - { - print CPP <<__E; - if(mLogToFile != 0) - { - preply->LogFile("Receive", mLogToFile); - } -__E - } -print CPP <<__E; -======= if(not $writing_local) { @@ -1470,45 +944,10 @@ std::auto_ptr<$message_base_class> $server_or_client_class\::Receive() { preply->LogFile("Receive", GetLogToFile()); } ->>>>>>> 0.12 return preply; } -<<<<<<< HEAD -void ${prefix}Send(const ${derive_objects_from} &rObject) -{ -__E - if($implement_syslog) - { - print CPP <<__E; - if(mLogToSysLog) - { - rObject.LogSysLog("Send"); - } -__E - } - if($implement_filelog) - { - print CPP <<__E; - if(mLogToFile != 0) - { - rObject.LogFile("Send", mLogToFile); - } -__E - } - -print CPP <<__E; - Protocol::Send(rObject); -} - -__E -# write server function? -if($type eq 'Server') -{ - print CPP <<__E; -void ${prefix}DoServer($context_class &rContext) -======= void $server_or_client_class\::Send(const $message_base_class &rObject) { if(GetLogToSysLog()) @@ -1532,7 +971,6 @@ __E { print CPP <<__E; void $server_or_client_class\::DoServer($context_class &rContext) ->>>>>>> 0.12 { // Handshake with client Handshake(); @@ -1542,22 +980,6 @@ void $server_or_client_class\::DoServer($context_class &rContext) while(inProgress) { // Get an object from the conversation -<<<<<<< HEAD - std::auto_ptr<${derive_objects_from}> pobj(Receive()); - - // Run the command - std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(pobj->DoCommand(*this, rContext).release())); - - // Send the reply - Send(*(preply.get())); - - // Send any streams - for(unsigned int s = 0; s < mStreamsToSend.size(); s++) - { - // Send the streams - SendStream(*mStreamsToSend[s]); - } -======= std::auto_ptr<$message_base_class> pobj = Receive(); // Run the command @@ -1574,7 +996,6 @@ void $server_or_client_class\::DoServer($context_class &rContext) SendStream(**i); } ->>>>>>> 0.12 // Delete these streams DeleteStreamsToSend(); @@ -1586,122 +1007,6 @@ void $server_or_client_class\::DoServer($context_class &rContext) } } -<<<<<<< HEAD -void ${prefix}SendStreamAfterCommand(IOStream *pStream) -{ - ASSERT(pStream != NULL); - mStreamsToSend.push_back(pStream); -} - -void ${prefix}DeleteStreamsToSend() -{ - for(std::vector<IOStream*>::iterator i(mStreamsToSend.begin()); i != mStreamsToSend.end(); ++i) - { - delete (*i); - } - mStreamsToSend.clear(); -} - -__E -} - -# write logging functions? -if($implement_filelog || $implement_syslog) -{ - my ($fR,$fS); - - if($implement_syslog) - { - $fR .= <<__E; - if(mLogToSysLog) - { - if(Size==Protocol::ProtocolStream_SizeUncertain) - { - BOX_TRACE("Receiving stream, size uncertain"); - } - else - { - BOX_TRACE("Receiving stream, size " << Size); - } - } -__E - - $fS .= <<__E; - if(mLogToSysLog) - { - if(Size==Protocol::ProtocolStream_SizeUncertain) - { - BOX_TRACE("Sending stream, size uncertain"); - } - else - { - BOX_TRACE("Sending stream, size " << Size); - } - } -__E - } - - if($implement_filelog) - { - $fR .= <<__E; - if(mLogToFile) - { - ::fprintf(mLogToFile, - (Size==Protocol::ProtocolStream_SizeUncertain) - ?"Receiving stream, size uncertain\\n" - :"Receiving stream, size %d\\n", Size); - ::fflush(mLogToFile); - } -__E - $fS .= <<__E; - if(mLogToFile) - { - ::fprintf(mLogToFile, - (Size==Protocol::ProtocolStream_SizeUncertain) - ?"Sending stream, size uncertain\\n" - :"Sending stream, size %d\\n", Size); - ::fflush(mLogToFile); - } -__E - } - - print CPP <<__E; - -void ${prefix}InformStreamReceiving(u_int32_t Size) -{ -$fR} - -void ${prefix}InformStreamSending(u_int32_t Size) -{ -$fS} - -__E -} - - -# write client Query functions? -if($type eq 'Client') -{ - for my $cmd (@cmd_list) - { - if(obj_is_type($cmd,'Command')) - { - my $reply = obj_get_type_params($cmd,'Command'); - my $reply_id = $cmd_id{$reply}; - my $has_stream = obj_is_type($cmd,'StreamWithCommand'); - my $argextra = $has_stream?', IOStream &rStream':''; - my $send_stream_extra = ''; - if($has_stream) - { - $send_stream_extra = <<__E; - - // Send stream after the command - SendStream(rStream); -__E - } - print CPP <<__E; -std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_base$cmd &rQuery$argextra) -======= __E } @@ -1734,44 +1039,10 @@ __E print CPP <<__E; std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class &rQuery$argextra) ->>>>>>> 0.12 { // Send query Send(rQuery); $send_stream_extra -<<<<<<< HEAD - // Wait for the reply - std::auto_ptr<${derive_objects_from}> preply(Receive().release()); - - if(preply->GetType() == $reply_id) - { - // Correct response - return std::auto_ptr<$classname_base$reply>(($classname_base$reply*)preply.release()); - } - else - { - // Set protocol error - int type, subType; - if(preply->IsError(type, subType)) - { - SetError(type, subType); - BOX_WARNING("$cmd command failed: received error " << - ((${classname_base}Error&)*preply).GetMessage()); - } - else - { - SetError(Protocol::UnknownError, Protocol::UnknownError); - BOX_WARNING("$cmd command failed: received " - "unexpected response type " << - preply->GetType()); - } - - // Throw an exception - THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply) - } -} -__E -======= // Wait for the reply std::auto_ptr<$message_base_class> preply = Receive(); @@ -1808,16 +1079,10 @@ std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class __E } } ->>>>>>> 0.12 } } } -<<<<<<< HEAD - - -======= ->>>>>>> 0.12 print H <<__E; #endif // $guardname @@ -1827,12 +1092,7 @@ __E close H; close CPP; -<<<<<<< HEAD - -sub obj_is_type -======= sub obj_is_type ($$) ->>>>>>> 0.12 { my ($c,$ty) = @_; for(@{$cmd_attributes{$c}}) @@ -1886,43 +1146,6 @@ sub translate_type_to_member_type return $typename } -<<<<<<< HEAD -sub make_log_strings -{ - my ($cmd) = @_; - - my @str; - my @arg; - for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) - { - my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); - - if(exists $log_display_types{$ty}) - { - # need to translate it - my ($format,$arg) = @{$log_display_types{$ty}}; - $arg =~ s/VAR/m$nm/g; - - if ($format eq "0x%llx" and $target_windows) - { - $format = "0x%I64x"; - $arg = "(uint64_t)$arg"; - } - - push @str,$format; - push @arg,$arg; - } - else - { - # is opaque - push @str,'OPAQUE'; - } - } - return ($cmd.'('.join(',',@str).')', join(',','',@arg)); -} - -======= ->>>>>>> 0.12 sub make_log_strings_framework { my ($cmd) = @_; @@ -1939,11 +1162,7 @@ sub make_log_strings_framework my ($format,$arg) = @{$log_display_types{$ty}}; $arg =~ s/VAR/m$nm/g; -<<<<<<< HEAD - if ($format eq '\\"%s\\"') -======= if ($format eq '"%s"') ->>>>>>> 0.12 { $arg = "\"\\\"\" << $arg << \"\\\"\""; } @@ -1970,11 +1189,7 @@ sub make_log_strings_framework } } -<<<<<<< HEAD - my $log_cmd = "Action << \" $cmd(\" "; -======= my $log_cmd = '"'.$cmd.'(" '; ->>>>>>> 0.12 foreach my $arg (@args) { $arg = "<< $arg "; @@ -1984,7 +1199,3 @@ sub make_log_strings_framework return $log_cmd; } -<<<<<<< HEAD - -======= ->>>>>>> 0.12 |