summaryrefslogtreecommitdiffstats
path: root/lib/libtdekrb/src/tdekrbclientsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libtdekrb/src/tdekrbclientsocket.cpp')
-rw-r--r--lib/libtdekrb/src/tdekrbclientsocket.cpp70
1 files changed, 33 insertions, 37 deletions
diff --git a/lib/libtdekrb/src/tdekrbclientsocket.cpp b/lib/libtdekrb/src/tdekrbclientsocket.cpp
index 3705889..b49d48d 100644
--- a/lib/libtdekrb/src/tdekrbclientsocket.cpp
+++ b/lib/libtdekrb/src/tdekrbclientsocket.cpp
@@ -99,7 +99,7 @@ static int logSASLMessages(void *context __attribute__((unused)), int priority,
return SASL_OK;
}
-TDEKerberosClientSocket::TDEKerberosClientSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) {
+TDEKerberosClientSocket::TDEKerberosClientSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_bufferReadPointer(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) {
saslData = new SASLDataPrivate;
saslData->m_krbConnection = NULL;
m_buffer = new TQBuffer();
@@ -181,14 +181,12 @@ bool TDEKerberosClientSocket::at(TQIODevice::Offset off, int hidebasehack) {
// Remove the specified bytes from the buffer
m_bufferLength = m_bufferLength-off;
- TQByteArray ba = m_buffer->buffer();
- for (i=0; i<m_bufferLength;i++) {
- ba[i] = ba[i+off];
- }
+ m_bufferReadPointer = m_bufferReadPointer+off;
if (m_bufferLength < 1) {
// Clear the buffer from memory
m_buffer->close();
m_buffer->open(IO_ReadWrite|IO_Truncate);
+ m_bufferReadPointer = 0;
}
}
return true;
@@ -256,10 +254,11 @@ int TDEKerberosClientSocket::ungetch(int ch) {
int ret;
if (kerberosStatus() == KerberosInUse) {
- ret = m_buffer->ungetch(ch);
- if (ret >= 0) {
- m_bufferLength++;
- }
+ // FIXME
+ // UNIMPLEMENTED
+ // This feature, if supported, will be very expensive, requiring a full allocation+copy/shift+deallocation of the buffer array,
+ // followed by insertion of the new character to the head of the array
+ ret = -1;
}
else {
ret = TQSocket::ungetch(ch);
@@ -293,7 +292,7 @@ int TDEKerberosClientSocket::processPendingData() {
return -1;
}
if (reclen > 0) {
- m_buffer->at(m_bufferLength);
+ m_buffer->at(m_bufferLength+m_bufferReadPointer);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
@@ -354,7 +353,7 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) {
return -1;
}
if (reclen > 0) {
- m_buffer->at(m_bufferLength);
+ m_buffer->at(m_bufferLength+m_bufferReadPointer);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
@@ -367,19 +366,17 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) {
if (maxlen > (unsigned int)m_bufferLength) {
maxlen = m_bufferLength;
}
- m_buffer->at(0);
+ m_buffer->at(m_bufferReadPointer);
ret = m_buffer->readBlock(data, maxlen);
if (ret > 0) {
// Remove the read bytes from the buffer
m_bufferLength = m_bufferLength-ret;
- TQByteArray ba = m_buffer->buffer();
- for (i=0; i<m_bufferLength;i++) {
- ba[i] = ba[i+ret];
- }
+ m_bufferReadPointer = m_bufferReadPointer+ret;
if (m_bufferLength < 1) {
// Clear the buffer from memory
m_buffer->close();
m_buffer->open(IO_ReadWrite|IO_Truncate);
+ m_bufferReadPointer = 0;
}
}
}
@@ -418,7 +415,7 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) {
return -1;
}
if (reclen > 0) {
- m_buffer->at(m_bufferLength);
+ m_buffer->at(m_bufferLength+m_bufferReadPointer);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
@@ -431,19 +428,17 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) {
if (maxlen > (unsigned int)m_bufferLength) {
maxlen = m_bufferLength;
}
- m_buffer->at(0);
+ m_buffer->at(m_bufferReadPointer);
ret = m_buffer->readLine(data, maxlen);
if (ret > 0) {
// Remove the read bytes from the buffer
m_bufferLength = m_bufferLength-ret;
- TQByteArray ba = m_buffer->buffer();
- for (i=0; i<m_bufferLength;i++) {
- ba[i] = ba[i+ret];
- }
+ m_bufferReadPointer = m_bufferReadPointer+ret;
if (m_bufferLength < 1) {
// Clear the buffer from memory
m_buffer->close();
m_buffer->open(IO_ReadWrite|IO_Truncate);
+ m_bufferReadPointer = 0;
}
}
}
@@ -473,7 +468,7 @@ TQString TDEKerberosClientSocket::readLine() {
return TQString::null;
}
if (reclen > 0) {
- m_buffer->at(m_bufferLength);
+ m_buffer->at(m_bufferLength+m_bufferReadPointer);
wrlen = m_buffer->writeBlock(buf, reclen);
if (wrlen > 0) {
m_bufferLength = m_bufferLength + wrlen;
@@ -486,20 +481,18 @@ TQString TDEKerberosClientSocket::readLine() {
if (maxlen > m_bufferLength) {
maxlen = m_bufferLength;
}
- m_buffer->at(0);
+ m_buffer->at(m_bufferReadPointer);
buf = (char*)malloc(maxlen);
readlen = m_buffer->readLine(buf, maxlen);
if (readlen > 0) {
// Remove the read bytes from the buffer
m_bufferLength = m_bufferLength-readlen;
- TQByteArray ba = m_buffer->buffer();
- for (i=0; i<m_bufferLength;i++) {
- ba[i] = ba[i+readlen];
- }
+ m_bufferReadPointer = m_bufferReadPointer+readlen;
if (m_bufferLength < 1) {
// Clear the buffer from memory
m_buffer->close();
m_buffer->open(IO_ReadWrite|IO_Truncate);
+ m_bufferReadPointer = 0;
}
ret = TQString(buf);
}
@@ -726,8 +719,13 @@ int TDEKerberosClientSocket::writeEndOfFrame() {
bool TDEKerberosClientSocket::canReadFrame() {
processPendingData();
- if (m_buffer->buffer().contains(255) > 0) {
- return true;
+ if (m_bufferLength > 0) {
+ if (m_buffer->buffer().find(255, m_bufferReadPointer) >= 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -738,18 +736,16 @@ void TDEKerberosClientSocket::clearFrameTail() {
int i;
int eofLoc;
if (m_bufferLength > 0) {
- eofLoc = m_buffer->buffer().find(255, 0) + 1;
- if ((eofLoc > 0) && (eofLoc <= m_bufferLength)) {
+ eofLoc = m_buffer->buffer().find(255, m_bufferReadPointer) + 1;
+ if ((eofLoc > 0) && (eofLoc <= (m_bufferLength+m_bufferReadPointer))) {
// Remove the remaining frame bytes (including the End of Frame marker) from the buffer
- m_bufferLength = m_bufferLength-eofLoc;
- TQByteArray ba = m_buffer->buffer();
- for (i=0; i<m_bufferLength;i++) {
- ba[i] = ba[i+eofLoc];
- }
+ m_bufferLength = m_bufferLength-(eofLoc-m_bufferReadPointer);
+ m_bufferReadPointer = m_bufferReadPointer+(eofLoc-m_bufferReadPointer);
if (m_bufferLength < 1) {
// Clear the buffer from memory
m_buffer->close();
m_buffer->open(IO_ReadWrite|IO_Truncate);
+ m_bufferReadPointer = 0;
}
}
}