diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-29 19:07:27 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-29 19:07:27 -0500 |
commit | 67f0b146ecc82da4511bfe72bdbe4f850c263d8c (patch) | |
tree | f41dd17e138fbf3361cfe03479cedb862fcee5ce /lib | |
parent | 1f8f9ca9434d9e2c0d7e7e061b7177009fd504df (diff) | |
download | ulab-67f0b146ecc82da4511bfe72bdbe4f850c263d8c.tar.gz ulab-67f0b146ecc82da4511bfe72bdbe4f850c263d8c.zip |
Add helper functions to krb sockets
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libtdekrb/src/tdekrbclientsocket.cpp | 121 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbclientsocket.h | 3 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbserversocket.cpp | 121 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbserversocket.h | 3 |
4 files changed, 176 insertions, 72 deletions
diff --git a/lib/libtdekrb/src/tdekrbclientsocket.cpp b/lib/libtdekrb/src/tdekrbclientsocket.cpp index 7e39fcf..6ba35e5 100644 --- a/lib/libtdekrb/src/tdekrbclientsocket.cpp +++ b/lib/libtdekrb/src/tdekrbclientsocket.cpp @@ -204,6 +204,44 @@ bool TDEKerberosClientSocket::atEnd() const { return ret; } +TQ_ULONG TDEKerberosClientSocket::bytesAvailable() const { + bool ret; + + if (kerberosStatus() == KerberosInUse) { + ret = m_bufferLength; + } + else { + ret = TQSocket::bytesAvailable(); + } + + return ret; +} + +int TDEKerberosClientSocket::processPendingData() { + if (kerberosStatus() == KerberosInUse) { + int reclen; + int wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; + } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); + } + } + + return 0; +} + int TDEKerberosClientSocket::setUsingKerberos(bool krbactive) { int ret = 0; @@ -243,20 +281,22 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) { if (kerberosStatus() == KerberosInUse) { int reclen; int wrlen; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return -1; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; + } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } } + free(buf); } - free(buf); if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; @@ -304,20 +344,22 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) { if (kerberosStatus() == KerberosInUse) { int reclen; int wrlen; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return -1; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); } - free(buf); if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; @@ -354,21 +396,24 @@ TQString TDEKerberosClientSocket::readLine() { int reclen; int wrlen; int readlen; + char* buf; maxlen = m_negotiatedMaxBufferSize; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return TQString::null; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return TQString::null; } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); } - free(buf); if (maxlen > m_bufferLength) { maxlen = m_bufferLength; @@ -596,6 +641,10 @@ TDEKerberosClientSocket::KerberosStatus TDEKerberosClientSocket::kerberosStatus( return KerberosInUse; } +bool TDEKerberosClientSocket::canReadData() { + return TQSocket::canReadLine(); +} + void TDEKerberosClientSocket::setStatusMessage(TQString message) { if (message != m_prevStatusMessage) { emit(statusMessageUpdated(message)); diff --git a/lib/libtdekrb/src/tdekrbclientsocket.h b/lib/libtdekrb/src/tdekrbclientsocket.h index 8f4a287..f058220 100644 --- a/lib/libtdekrb/src/tdekrbclientsocket.h +++ b/lib/libtdekrb/src/tdekrbclientsocket.h @@ -57,6 +57,7 @@ class TDEKerberosClientSocket : public TQSocket TQ_LONG readLine(char *data, TQ_ULONG maxlen); TQString readLine(); void writeLine(TQString); + TQ_ULONG bytesAvailable() const; int setUsingKerberos(bool krbactive); void setServiceName(TQString name); @@ -65,6 +66,8 @@ class TDEKerberosClientSocket : public TQSocket void setDataTimeout(int timeoutms); KerberosStatus kerberosStatus() const; + bool canReadData(); + int processPendingData(); private: int initializeKerberosInterface(); diff --git a/lib/libtdekrb/src/tdekrbserversocket.cpp b/lib/libtdekrb/src/tdekrbserversocket.cpp index 4840c16..3134738 100644 --- a/lib/libtdekrb/src/tdekrbserversocket.cpp +++ b/lib/libtdekrb/src/tdekrbserversocket.cpp @@ -204,6 +204,44 @@ bool TDEKerberosServerSocket::atEnd() const { return ret; } +TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const { + bool ret; + + if (kerberosStatus() == KerberosInUse) { + ret = m_bufferLength; + } + else { + ret = TQSocket::bytesAvailable(); + } + + return ret; +} + +int TDEKerberosServerSocket::processPendingData() { + if (kerberosStatus() == KerberosInUse) { + int reclen; + int wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; + } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); + } + } + + return 0; +} + int TDEKerberosServerSocket::setUsingKerberos(bool krbactive) { int ret = 0; @@ -243,20 +281,22 @@ TQ_LONG TDEKerberosServerSocket::readBlock(char *data, TQ_ULONG maxlen) { if (m_kerberosRequested) { int reclen; int wrlen; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return -1; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); } - free(buf); if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; @@ -304,20 +344,22 @@ TQ_LONG TDEKerberosServerSocket::readLine(char *data, TQ_ULONG maxlen) { if (m_kerberosRequested) { int reclen; int wrlen; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return -1; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + char* buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return -1; } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); } - free(buf); if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; @@ -354,21 +396,24 @@ TQString TDEKerberosServerSocket::readLine() { int reclen; int wrlen; int readlen; + char* buf; maxlen = m_negotiatedMaxBufferSize; - char* buf = (char*)malloc(m_negotiatedMaxBufferSize); - reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); - if (reclen < 0) { - free(buf); - return TQString::null; - } - if (reclen > 0) { - m_buffer->at(m_bufferLength); - wrlen = m_buffer->writeBlock(buf, reclen); - if (wrlen > 0) { - m_bufferLength = m_bufferLength + wrlen; + if (m_bufferLength <= 0) { + buf = (char*)malloc(m_negotiatedMaxBufferSize); + reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); + if (reclen < 0) { + free(buf); + return TQString::null; } + if (reclen > 0) { + m_buffer->at(m_bufferLength); + wrlen = m_buffer->writeBlock(buf, reclen); + if (wrlen > 0) { + m_bufferLength = m_bufferLength + wrlen; + } + } + free(buf); } - free(buf); if (maxlen > m_bufferLength) { maxlen = m_bufferLength; @@ -596,6 +641,10 @@ TDEKerberosServerSocket::KerberosStatus TDEKerberosServerSocket::kerberosStatus( return KerberosInUse; } +bool TDEKerberosServerSocket::canReadData() { + return TQSocket::canReadLine(); +} + void TDEKerberosServerSocket::setStatusMessage(TQString message) { if (message != m_prevStatusMessage) { emit(statusMessageUpdated(message)); diff --git a/lib/libtdekrb/src/tdekrbserversocket.h b/lib/libtdekrb/src/tdekrbserversocket.h index 4a315ca..6276358 100644 --- a/lib/libtdekrb/src/tdekrbserversocket.h +++ b/lib/libtdekrb/src/tdekrbserversocket.h @@ -57,6 +57,7 @@ class TDEKerberosServerSocket : public TQSocket TQ_LONG readLine(char *data, TQ_ULONG maxlen); TQString readLine(); void writeLine(TQString); + TQ_ULONG bytesAvailable() const; int setUsingKerberos(bool krbactive); void setServiceName(TQString name); @@ -65,6 +66,8 @@ class TDEKerberosServerSocket : public TQSocket void setDataTimeout(int timeoutms); KerberosStatus kerberosStatus() const; + bool canReadData(); + int processPendingData(); private: int initializeKerberosInterface(); |