diff options
Diffstat (limited to 'lib/server/Protocol.cpp')
-rw-r--r-- | lib/server/Protocol.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/server/Protocol.cpp b/lib/server/Protocol.cpp index 5dc5d0b1..6333b1db 100644 --- a/lib/server/Protocol.cpp +++ b/lib/server/Protocol.cpp @@ -11,8 +11,14 @@ #include <sys/types.h> +<<<<<<< HEAD #include <stdlib.h> #include <string.h> +======= +#include <cstdlib> +#include <cstring> +#include <cstdio> +>>>>>>> 0.12 #include <new> @@ -44,6 +50,7 @@ // // -------------------------------------------------------------------------- Protocol::Protocol(IOStream &rStream) +<<<<<<< HEAD : mrStream(rStream), mHandshakeDone(false), mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), @@ -55,6 +62,19 @@ Protocol::Protocol(IOStream &rStream) mValidDataSize(-1), mLastErrorType(NoError), mLastErrorSubType(NoError) +======= +: mrStream(rStream), + mHandshakeDone(false), + mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), + mTimeout(PROTOCOL_DEFAULT_TIMEOUT), + mpBuffer(0), + mBufferSize(0), + mReadOffset(-1), + mWriteOffset(-1), + mValidDataSize(-1), + mLogToSysLog(false), + mLogToFile(NULL) +>>>>>>> 0.12 { BOX_TRACE("Send block allocation size is " << PROTOCOL_ALLOCATE_SEND_BLOCK_CHUNK); @@ -82,6 +102,7 @@ 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 @@ -110,6 +131,8 @@ bool Protocol::GetLastError(int &rTypeOut, int &rSubTypeOut) // -------------------------------------------------------------------------- // // Function +======= +>>>>>>> 0.12 // Name: Protocol::Handshake() // Purpose: Handshake with peer (exchange ident strings) // Created: 2003/08/20 @@ -127,7 +150,11 @@ 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)); @@ -200,7 +227,11 @@ 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; @@ -220,7 +251,11 @@ std::auto_ptr<ProtocolObject> Protocol::Receive() } // 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); @@ -272,7 +307,11 @@ std::auto_ptr<ProtocolObject> Protocol::Receive() // 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) @@ -715,6 +754,20 @@ void Protocol::SendStream(IOStream &rStream) // Can't send this using the fixed size header uncertainSize = true; } +<<<<<<< HEAD +======= + + if(streamSize == 0) + { + // Server protocol will throw an assertion failure if we + // try to send a stream whose size is definitely zero: + // ASSERT FAILED: [BytesToRead > 0] at PartialReadStream.cpp:31 + // so catch this on the client side to help debugging + THROW_EXCEPTION_MESSAGE(ServerException, Protocol_BadUsage, + "Sending a stream with a definite size of zero " + "is not allowed in the protocol"); + } +>>>>>>> 0.12 // Inform sub class InformStreamSending(streamSize); @@ -854,7 +907,30 @@ 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) + { + BOX_TRACE("Receiving stream, size uncertain"); + } + else + { + BOX_TRACE("Receiving stream, size " << Size); + } + } + + if(GetLogToFile()) + { + ::fprintf(GetLogToFile(), + (Size == Protocol::ProtocolStream_SizeUncertain) + ? "Receiving stream, size uncertain\n" + : "Receiving stream, size %d\n", Size); + ::fflush(GetLogToFile()); + } +>>>>>>> 0.12 } // -------------------------------------------------------------------------- @@ -867,7 +943,30 @@ void Protocol::InformStreamReceiving(u_int32_t Size) // -------------------------------------------------------------------------- void Protocol::InformStreamSending(u_int32_t Size) { +<<<<<<< HEAD // Do nothing +======= + if(GetLogToSysLog()) + { + if(Size == Protocol::ProtocolStream_SizeUncertain) + { + BOX_TRACE("Sending stream, size uncertain"); + } + else + { + BOX_TRACE("Sending stream, size " << Size); + } + } + + if(GetLogToFile()) + { + ::fprintf(GetLogToFile(), + (Size == Protocol::ProtocolStream_SizeUncertain) + ? "Sending stream, size uncertain\n" + : "Sending stream, size %d\n", Size); + ::fflush(GetLogToFile()); + } +>>>>>>> 0.12 } |