Normalize line endings to LF on the files touched by the TLS fix
The previous commit picked up CRLF line endings from a Windows-side working copy used during development. Converting to plain LF to match the rest of this Linux-native repo - content unchanged, this is purely a line-ending normalization (932 insertions/932 deletions, 1:1).
This commit is contained in:
1 parent
701d03dcd9
commit
989aee9482
6 files changed
+932
-932
No files matched your search
+95
-95
@@ -1,95 +1,95 @@
|
||||
#include "TCPSocket.h"
|
||||
#include "EPoll.h"
|
||||
#include "Log.h"
|
||||
#include "Exception.h"
|
||||
#include "errno.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll) : Socket(ePoll) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, TLSInfo *tlsInfo, std::string text) : Socket(ePoll, text), TLS(tlsInfo), tlsInfo(tlsInfo) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, SSL_CTX *ctx, std::string text) : Socket(ePoll, text), TLS(ctx) {}
|
||||
|
||||
TCPSocket::~TCPSocket() {}
|
||||
|
||||
void TCPSocket::connect(IPAddress &address) {
|
||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||
if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1)
|
||||
throw coreutils::Exception("Error on connect to TCP socket." + errno);
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Connected to IP..." << address.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSocket::output(std::stringstream &out) {
|
||||
out << "|" << ipAddress.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSocket::receiveData(coreutils::ZString &buffer) {
|
||||
if(tlsInfo) {
|
||||
int len = TLS::receiveData(buffer);
|
||||
if(len >= 0) {
|
||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||
onDataReceived(zbuffer);
|
||||
}
|
||||
} else {
|
||||
Socket::receiveData(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
int TCPSocket::sendData(const char *data, int length) {
|
||||
if(tlsInfo)
|
||||
return TLS::sendData(data, length);
|
||||
else
|
||||
return Socket::sendData(data, length);
|
||||
}
|
||||
|
||||
void TCPSocket::onDataReceived(coreutils::ZString &data) {
|
||||
|
||||
if (data.getLength() > 0) {
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||
lineBufferSize += data.getLength();
|
||||
while (lineBufferSize > 0) {
|
||||
if (blockSize == 0) {
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if (lineLength == lineBufferSize)
|
||||
break;
|
||||
coreutils::ZString zLine(lineBuffer, lineLength);
|
||||
onLineReceived(zLine);
|
||||
if (lineBuffer[lineLength] == '\r')
|
||||
++lineLength;
|
||||
if (lineBuffer[lineLength] == '\n')
|
||||
++lineLength;
|
||||
lineBufferSize -= lineLength;
|
||||
if (lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
else if (lineBufferSize >= blockLength) {
|
||||
coreutils::ZString zBlock(lineBuffer, blockLength);
|
||||
onBlockReceived(zBlock);
|
||||
lineBufferSize -= blockLength;
|
||||
if (lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSocket::onLineReceived(coreutils::ZString &line) {
|
||||
if (term)
|
||||
shutdown("termination requested");
|
||||
}
|
||||
|
||||
void TCPSocket::onBlockReceived(coreutils::ZString &block) {}
|
||||
|
||||
void TCPSocket::setBlockSize(int blockSize) {
|
||||
this->blockSize = blockSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "TCPSocket.h"
|
||||
#include "EPoll.h"
|
||||
#include "Log.h"
|
||||
#include "Exception.h"
|
||||
#include "errno.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll) : Socket(ePoll) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, TLSInfo *tlsInfo, std::string text) : Socket(ePoll, text), TLS(tlsInfo), tlsInfo(tlsInfo) {}
|
||||
|
||||
TCPSocket::TCPSocket(EPoll &ePoll, SSL_CTX *ctx, std::string text) : Socket(ePoll, text), TLS(ctx) {}
|
||||
|
||||
TCPSocket::~TCPSocket() {}
|
||||
|
||||
void TCPSocket::connect(IPAddress &address) {
|
||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||
if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1)
|
||||
throw coreutils::Exception("Error on connect to TCP socket." + errno);
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Connected to IP..." << address.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSocket::output(std::stringstream &out) {
|
||||
out << "|" << ipAddress.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSocket::receiveData(coreutils::ZString &buffer) {
|
||||
if(tlsInfo) {
|
||||
int len = TLS::receiveData(buffer);
|
||||
if(len >= 0) {
|
||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||
onDataReceived(zbuffer);
|
||||
}
|
||||
} else {
|
||||
Socket::receiveData(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
int TCPSocket::sendData(const char *data, int length) {
|
||||
if(tlsInfo)
|
||||
return TLS::sendData(data, length);
|
||||
else
|
||||
return Socket::sendData(data, length);
|
||||
}
|
||||
|
||||
void TCPSocket::onDataReceived(coreutils::ZString &data) {
|
||||
|
||||
if (data.getLength() > 0) {
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||
lineBufferSize += data.getLength();
|
||||
while (lineBufferSize > 0) {
|
||||
if (blockSize == 0) {
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if (lineLength == lineBufferSize)
|
||||
break;
|
||||
coreutils::ZString zLine(lineBuffer, lineLength);
|
||||
onLineReceived(zLine);
|
||||
if (lineBuffer[lineLength] == '\r')
|
||||
++lineLength;
|
||||
if (lineBuffer[lineLength] == '\n')
|
||||
++lineLength;
|
||||
lineBufferSize -= lineLength;
|
||||
if (lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
else if (lineBufferSize >= blockLength) {
|
||||
coreutils::ZString zBlock(lineBuffer, blockLength);
|
||||
onBlockReceived(zBlock);
|
||||
lineBufferSize -= blockLength;
|
||||
if (lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSocket::onLineReceived(coreutils::ZString &line) {
|
||||
if (term)
|
||||
shutdown("termination requested");
|
||||
}
|
||||
|
||||
void TCPSocket::onBlockReceived(coreutils::ZString &block) {}
|
||||
|
||||
void TCPSocket::setBlockSize(int blockSize) {
|
||||
this->blockSize = blockSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user