From 5ca224af19dac64287779d63ef4454d86bea6f0c Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 2 Apr 2011 12:23:36 +0000 Subject: [PATCH] QT does not use unsigned int for their "size()" functions, therefore we also do not use it for our sizes (it is actually not required here) --- src/protocol.cpp | 91 ++++++++++++++++++++++++------------------------ src/protocol.h | 14 ++++---- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index 19702970..b9bd38d7 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -324,7 +324,7 @@ void CProtocol::CreateAndImmSendAcknMess ( const int& iID, { CVector vecAcknMessage; CVector vecData ( 2 ); // 2 bytes of data - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // build data vector PutValOnStream ( vecData, iPos, static_cast ( iID ), 2 ); @@ -417,7 +417,7 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; if ( iRecID == PROTMESSID_ACKN ) { // extract data from stream and emit signal for received value - unsigned int iPos = 0; + int iPos = 0; const int iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); @@ -588,7 +588,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, void CProtocol::CreateJitBufMes ( const int iJitBufSize ) { CVector vecData ( 2 ); // 2 bytes of data - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // build data vector PutValOnStream ( vecData, iPos, static_cast ( iJitBufSize ), 2 ); @@ -598,7 +598,7 @@ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) bool CProtocol::EvaluateJitBufMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // check size if ( vecData.Size() != 2 ) @@ -639,7 +639,7 @@ bool CProtocol::EvaluateReqJitBufMes() void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) { CVector vecData ( 3 ); // 3 bytes of data - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // build data vector // channel ID @@ -655,7 +655,7 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) bool CProtocol::EvaluateChanGainMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // check size if ( vecData.Size() != 3 ) @@ -686,7 +686,7 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh // build data vector CVector vecData ( 0 ); - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer for ( int i = 0; i < iNumClients; i++ ) { @@ -717,8 +717,8 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh bool CProtocol::EvaluateConClientListMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer - const unsigned int iDataLen = vecData.Size(); + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); CVector vecChanInfo ( 0 ); while ( iPos < iDataLen ) @@ -778,8 +778,8 @@ bool CProtocol::EvaluateReqConnClientsList() void CProtocol::CreateChanNameMes ( const QString strName ) { - unsigned int iPos = 0; // init position pointer - const int iStrLen = strName.size(); // get string size + int iPos = 0; // init position pointer + const int iStrLen = strName.size(); // get string size // size of current list entry const int iEntrLen = 2 /* string size */ + iStrLen; @@ -795,7 +795,7 @@ void CProtocol::CreateChanNameMes ( const QString strName ) bool CProtocol::EvaluateChanNameMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // channel name QString strName; @@ -834,8 +834,8 @@ bool CProtocol::EvaluateReqChanNameMes() void CProtocol::CreateChatTextMes ( const QString strChatText ) { - unsigned int iPos = 0; // init position pointer - const int iStrLen = strChatText.size(); // get string size + int iPos = 0; // init position pointer + const int iStrLen = strChatText.size(); // get string size // size of message body const int iEntrLen = 2 /* string size */ + iStrLen; @@ -851,7 +851,7 @@ void CProtocol::CreateChatTextMes ( const QString strChatText ) bool CProtocol::EvaluateChatTextMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // chat text QString strChatText; @@ -877,7 +877,7 @@ bool CProtocol::EvaluateChatTextMes ( const CVector& vecData ) void CProtocol::CreatePingMes ( const int iMs ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // build data vector (4 bytes long) CVector vecData ( 4 ); @@ -890,7 +890,7 @@ void CProtocol::CreatePingMes ( const int iMs ) bool CProtocol::EvaluatePingMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // check size if ( vecData.Size() != 4 ) @@ -905,7 +905,7 @@ bool CProtocol::EvaluatePingMes ( const CVector& vecData ) void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // size of current message body const int iEntrLen = @@ -953,7 +953,7 @@ void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrPr bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer CNetworkTransportProps ReceivedNetwTranspProps; // size of current message body @@ -1084,7 +1084,7 @@ bool CProtocol::EvaluateDisconnectionMes() // Connection less messages ---------------------------------------------------- void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // build data vector (4 bytes long) CVector vecData ( 4 ); @@ -1100,7 +1100,7 @@ void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr, const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // check size if ( vecData.Size() != 4 ) @@ -1132,7 +1132,7 @@ bool CProtocol::EvaluateCLServerFullMes() void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr, const CServerInfo& ServerInfo ) { - unsigned int iPos = 0; // init position pointer + int iPos = 0; // init position pointer // current string sizes const int iNameLen = ServerInfo.strName.size(); @@ -1185,9 +1185,9 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr, bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, const CVector& vecData ) { - unsigned int iPos = 0; // init position pointer - const unsigned int iDataLen = vecData.Size(); - CServerInfo RecServerInfo; + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); + CServerInfo RecServerInfo; // check size (the first 5 bytes) if ( iDataLen < 5 ) @@ -1259,8 +1259,9 @@ bool CProtocol::ParseMessageFrame ( const CVector& vecIn, int& iID, CVector& vecData ) { - int iLenBy, i; - unsigned int iCurPos; + int i; + int iLenBy; + int iCurPos; // vector must be at least "MESS_LEN_WITHOUT_DATA_BYTE" bytes long if ( iNumBytesIn < MESS_LEN_WITHOUT_DATA_BYTE ) @@ -1327,18 +1328,18 @@ bool CProtocol::ParseMessageFrame ( const CVector& vecIn, } uint32_t CProtocol::GetValFromStream ( const CVector& vecIn, - unsigned int& iPos, - const unsigned int iNumOfBytes ) + int& iPos, + const int iNumOfBytes ) { /* note: iPos is automatically incremented in this function */ // 4 bytes maximum since we return uint32 Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) ); - Q_ASSERT ( static_cast ( vecIn.Size() ) >= iPos + iNumOfBytes ); + Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes ); uint32_t iRet = 0; - for ( unsigned int i = 0; i < iNumOfBytes; i++ ) + for ( int i = 0; i < iNumOfBytes; i++ ) { iRet |= vecIn[iPos] << ( i * 8 /* size of byte */ ); iPos++; @@ -1348,23 +1349,23 @@ uint32_t CProtocol::GetValFromStream ( const CVector& vecIn, } bool CProtocol::GetStringFromStream ( const CVector& vecIn, - unsigned int& iPos, - const unsigned int iMaxStringLen, + int& iPos, + const int iMaxStringLen, QString& strOut ) { /* note: iPos is automatically incremented in this function */ // check if at least two bytes are available - const unsigned int iInLen = vecIn.Size(); + const int iInLen = vecIn.Size(); if ( ( iInLen - iPos ) < 2 ) { return true; // return error code } // number of bytes for string (2 bytes) - const unsigned int iStrLen = - static_cast ( GetValFromStream ( vecIn, iPos, 2 ) ); + const int iStrLen = + static_cast ( GetValFromStream ( vecIn, iPos, 2 ) ); if ( ( ( iInLen - iPos ) < iStrLen ) || ( iStrLen > iMaxStringLen ) ) @@ -1374,7 +1375,7 @@ bool CProtocol::GetStringFromStream ( const CVector& vecIn, // string (n bytes) strOut = ""; - for ( unsigned int i = 0; i < iStrLen; i++ ) + for ( int i = 0; i < iStrLen; i++ ) { // byte-by-byte copying of the string data int iData = static_cast ( GetValFromStream ( vecIn, iPos, 1 ) ); @@ -1402,7 +1403,7 @@ void CProtocol::GenMessageFrame ( CVector& vecOut, // Encode header ----------------------------------------------------------- - unsigned int iCurPos = 0; // init position pointer + int iCurPos = 0; // init position pointer // 2 bytes TAG (all zero bits) PutValOnStream ( vecOut, iCurPos, @@ -1444,18 +1445,18 @@ void CProtocol::GenMessageFrame ( CVector& vecOut, } void CProtocol::PutValOnStream ( CVector& vecIn, - unsigned int& iPos, + int& iPos, const uint32_t iVal, - const unsigned int iNumOfBytes ) + const int iNumOfBytes ) { /* note: iPos is automatically incremented in this function */ // 4 bytes maximum since we use uint32 Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) ); - Q_ASSERT ( static_cast ( vecIn.Size() ) >= iPos + iNumOfBytes ); + Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes ); - for ( unsigned int i = 0; i < iNumOfBytes; i++ ) + for ( int i = 0; i < iNumOfBytes; i++ ) { vecIn[iPos] = ( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */; @@ -1464,9 +1465,9 @@ void CProtocol::PutValOnStream ( CVector& vecIn, } } -void CProtocol::PutStringOnStream ( CVector& vecIn, - unsigned int& iPos, - const QString& sString ) +void CProtocol::PutStringOnStream ( CVector& vecIn, + int& iPos, + const QString& sString ) { // get the string size const int iStrLen = sString.size(); diff --git a/src/protocol.h b/src/protocol.h index a2a22a09..d6b90591 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -154,21 +154,21 @@ protected: const CVector& vecData ); void PutValOnStream ( CVector& vecIn, - unsigned int& iPos, + int& iPos, const uint32_t iVal, - const unsigned int iNumOfBytes ); + const int iNumOfBytes ); void PutStringOnStream ( CVector& vecIn, - unsigned int& iPos, + int& iPos, const QString& sString ); uint32_t GetValFromStream ( const CVector& vecIn, - unsigned int& iPos, - const unsigned int iNumOfBytes ); + int& iPos, + const int iNumOfBytes ); bool GetStringFromStream ( const CVector& vecIn, - unsigned int& iPos, - const unsigned int iMaxStringLen, + int& iPos, + const int iMaxStringLen, QString& strOut ); bool IsConnectionLessMessageID ( const int iID ) const